#include #include #include #include #include "include/commands.h" cmd_t command = { .buf = {0}, .index = 0 }; void cmd_mirror_char(char c) { printf("%c", c); } void cmd_collect_char(char c) { command.buf[command.index] = c; cmd_mirror_char(c); command.index++; if (c == 0x3) { /* React on Ctl-C */ command.index = 0; printf("\r\n"); } if (c == 0xD) { /* Null-terminate the string */ command.buf[command.index-1] = '\0'; cmd_handle(&command); command.index = 0; } } void cmd_handle(cmd_t *command) { printf("\n\r"); char *tok1 = strtok(command->buf, " "); char *tok2 = strtok(NULL, " "); char *tok3 = strtok(NULL, " "); if (0 == strcmp(tok1, "set")) cmd_handle_set(tok2, tok3); if (0 == strcmp(tok1, "switch")) cmd_handle_switch(); } void cmd_handle_set(char *op1, char *op2) { long int val; char *end; if (0 == strcmp(op1, "t0_top")) { val = strtol(op2, &end, 10); if (op2 != end) { OCR0A = val; printf("Setting Timer0 TOP to %li\r\n", val); } else printf("No valid value for t0_top given\n\r"); } else if (0 == strcmp(op1, "t0_ps")) { val = strtol(op2, &end, 10); TCCR0B &= ~((1 << CS00) | (1 << CS01) | (1 << CS02)); switch (val) { case 0: TCCR0B |= (1 << CS00); break; case 8: TCCR0B |= (1 << CS01); break; case 64: TCCR0B |= (1 << CS00) | (1 << CS01); break; case 256: TCCR0B |= (1 << CS02); break; case 1024: TCCR0B |= (1 << CS02) | (1 << CS00); break; default: printf("No valid prescaler value.\n\r"); break; } } } void cmd_handle_switch(void) { int state = 0; PORTD ^= (1<