diff --git a/emb/command.c b/emb/command.c index 27bfbad79586fe24c1d1e674d3ba68eecb8300b2..24546851efb0aeef3593e5d087ca89e65959a259 100644 --- a/emb/command.c +++ b/emb/command.c @@ -8,6 +8,9 @@ struct command command_buf[NUM_COMMANDS]; uint16_t comm_start = 0, comm_end = 0; +char comm_str[33]; +uint8_t comm_str_ind = 0; + /* Add y to x, wrapping around limit */ static inline void add_wrap(uint16_t *x, uint16_t y, uint16_t limit) { @@ -17,7 +20,7 @@ static inline void add_wrap(uint16_t *x, uint16_t y, uint16_t limit) } enum state { - STATE_COMM, STATE_COMM_SPACE, STATE_ARG + STATE_COMM, STATE_COMM_SPACE, STATE_ARG, STATE_STRING }; /* Return 1 if new command ready */ @@ -36,8 +39,16 @@ uint8_t uart_add_ch(char c) break; case STATE_COMM_SPACE: if (c == ' ') { - state = STATE_ARG; - } else { + if (curr->comm_ch == 't') + { + comm_str_ind = 0; + state = STATE_STRING; + } + else + { + state = STATE_ARG; + } + } else { state = STATE_COMM; add_wrap(&comm_end, 1, NUM_COMMANDS); } @@ -58,6 +69,18 @@ uint8_t uart_add_ch(char c) if (argbuf_ind < 19) argbuf[argbuf_ind++] = c; } break; + case STATE_STRING: + if (comm_str_ind == sizeof(comm_str) - 1 || c == '\n') + { + comm_str[comm_str_ind] = '\0'; + state = STATE_COMM; + add_wrap(&comm_end, 1, NUM_COMMANDS); + } + else + { + comm_str[comm_str_ind++] = c; + } + break; } return state == STATE_COMM; } diff --git a/emb/command.h b/emb/command.h index f8aa9cbfc3d5ebfa9f7345b8d562d8f01d2c10a0..cb657c57ecc23df66b8611f9e6aec7c56e96928d 100644 --- a/emb/command.h +++ b/emb/command.h @@ -14,6 +14,8 @@ extern "C" { int16_t arg[NUM_ARGS]; }; + extern char comm_str[33]; + uint8_t uart_add_ch(char c); struct command *get_command(void); diff --git a/emb/state-controller.cpp b/emb/state-controller.cpp index 428094bd61d6b092b36c6a3bde5f407f60bc1e1a..77bb5eb8874eabdc5f18e78bb40a83786f3e8f63 100644 --- a/emb/state-controller.cpp +++ b/emb/state-controller.cpp @@ -1,8 +1,10 @@ #include "servos.hpp" #include "command.h" #include "time.hpp" +#include "display.hpp" #include <avr/interrupt.h> +#include <string.h> enum State { @@ -17,13 +19,15 @@ static uint32_t velocitiesEndMillis[NUM_SERVOS]; static int16_t startAngles[NUM_SERVOS]; static uint32_t startMillis[NUM_SERVOS]; +static char displayString[33]; + void parseCommand(command *comm) { uint32_t currentMillis = getCurrentMillis(); switch (comm->comm_ch) { - case 's': + case 's': // set if (0 <= comm->arg[0] - 1 && comm->arg[0] - 1 < NUM_SERVOS) { setServoAngle(comm->arg[0] - 1, comm->arg[1] * 60); @@ -31,7 +35,7 @@ void parseCommand(command *comm) servoVelocities[comm->arg[0] - 1] = 0; } break; - case 'v': + case 'v': // velocity if (0 <= comm->arg[0] - 1 && comm->arg[0] - 1 < NUM_SERVOS) { servoVelocities[comm->arg[0] - 1] = comm->arg[1]; @@ -40,10 +44,23 @@ void parseCommand(command *comm) startMillis[comm->arg[0] - 1] = currentMillis; } break; - case 'd': + case 'd': // delay delayEnd = getCurrentMillis() + comm->arg[0]; state = STATE_DELAY; break; + case 't': // text + clearDisplay(); + setDisplayCursor(0, 0); + uint8_t i = 0; + + while (char c = displayString[i++]) + { + writeDisplay(c); + + if (i == 16) + setDisplayCursor(0, 1); + } + break; } } @@ -58,6 +75,7 @@ void updateState() cli(); command *tmp = get_command(); command comm = *tmp; + memcpy(displayString, comm_str, sizeof(displayString)); sei(); if (tmp != nullptr)