diff --git a/include/eom_tscode_handler.h b/include/eom_tscode_handler.h new file mode 100644 index 00000000..acb53c08 --- /dev/null +++ b/include/eom_tscode_handler.h @@ -0,0 +1,17 @@ +#ifndef __eom_tscode_handler_h +#define __eom_tscode_handler_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include "tscode.h" +#include + +tscode_command_response_t eom_tscode_handler(tscode_command_t* cmd, char* response, size_t resp_len); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/src/eom_tscode_handler.cpp b/src/eom_tscode_handler.cpp new file mode 100644 index 00000000..8f509765 --- /dev/null +++ b/src/eom_tscode_handler.cpp @@ -0,0 +1,55 @@ +#include "eom_tscode_handler.h" +#include "Hardware.h" +#include "Page.h" +#include "UserInterface.h" + +#include "tscode_capabilities.h" + +void eom_tscode_install(void) { + tscode_device_vendor_details_t dev_info = { + .vendor = "Maus-Tec Electronics", + .device = "Edge-o-Matic 3000", + .version = VERSION, + }; + + tscode_register_vendor_details(&dev_info); +} + +tscode_command_response_t eom_tscode_handler(tscode_command_t* cmd, char* response, size_t resp_len) { + switch (cmd->type) { + case TSCODE_VIBRATE_ON: { + tscode_unit_t *speed = cmd->speed; + if (speed != NULL) { + uint8_t value = speed->value; + if (speed->unit == TSCODE_UNIT_PERCENTAGE) { + value = speed->value * 255; + } + + RunGraphPage.setMode("manual"); + Hardware::setMotorSpeed(value); + } + break; + } + + + case TSCODE_CONDITIONAL_STOP: + case TSCODE_HALT_IMMEDIATE: + case TSCODE_VIBRATE_OFF: { + RunGraphPage.setMode("manual"); + Hardware::setMotorSpeed(0); + break; + } + + case TSCODE_DISPLAY_MESSAGE: { + if (cmd->str != NULL) { + UI.toastNow(cmd->str); + } + break; + } + + default: + return TSCODE_RESPONSE_FAULT; + } + + return TSCODE_RESPONSE_OK; +} \ No newline at end of file