Skip to content

Commit

Permalink
Add basic TScode handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
MauAbata committed Sep 1, 2021
1 parent 364e683 commit 10bd25f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
17 changes: 17 additions & 0 deletions include/eom_tscode_handler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef __eom_tscode_handler_h
#define __eom_tscode_handler_h

#ifdef __cplusplus
extern "C" {
#endif

#include "tscode.h"
#include <stddef.h>

tscode_command_response_t eom_tscode_handler(tscode_command_t* cmd, char* response, size_t resp_len);

#ifdef __cplusplus
}
#endif

#endif
55 changes: 55 additions & 0 deletions src/eom_tscode_handler.cpp
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 10bd25f

Please sign in to comment.