summaryrefslogtreecommitdiff
path: root/project/Core/Src/Project/remote_control.c
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2025-11-04 18:12:00 -0500
committersowgro <tpoke.ferrari@gmail.com>2025-11-04 18:12:00 -0500
commita98361e6babc866bd7b4ed6b22f197e98e2dc28a (patch)
tree22b836ec4f03e6bee9c7b719e78917ba2f464be6 /project/Core/Src/Project/remote_control.c
parentfd7dd988b8a5e5838ba4db7fb59faf3c11c33a17 (diff)
download340-repo-Sowgro-a98361e6babc866bd7b4ed6b22f197e98e2dc28a.tar.gz
340-repo-Sowgro-a98361e6babc866bd7b4ed6b22f197e98e2dc28a.tar.bz2
340-repo-Sowgro-a98361e6babc866bd7b4ed6b22f197e98e2dc28a.zip
[incomplete] work on part 2 architecture
Diffstat (limited to 'project/Core/Src/Project/remote_control.c')
-rw-r--r--project/Core/Src/Project/remote_control.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/project/Core/Src/Project/remote_control.c b/project/Core/Src/Project/remote_control.c
new file mode 100644
index 0000000..905f966
--- /dev/null
+++ b/project/Core/Src/Project/remote_control.c
@@ -0,0 +1,72 @@
+/*
+ * remote_control.c
+ *
+ * Created on: Nov 4, 2025
+ * Author: sowgro
+ */
+
+static char buffer[80];
+static char* cur = buffer;
+static uint8_t state = STOPPED_STATE;
+
+void remote_control_start() {
+ NVIC_EnableIRQ (USART2_IRQn);
+ USART2->CR1 |= USART_CR1_RXNEIE; // 1 << 5
+
+ help();
+}
+
+void remote_control_loop() {
+
+}
+
+void remote_control_stop() {
+
+}
+
+static void parse_input(char buffer[], uint8_t *state) {
+ if (!strcmp(buffer, "HELP")) {
+ help();
+ }
+ else if (!strcmp(buffer, "NEXT")) {
+ next();
+ }
+ else if (!strcmp(buffer, "PLAY")) {
+ play();
+ *state = PLAYING_STATE;
+ }
+ else if (!strcmp(buffer, "PAUSE")) {
+ pause();
+ *state = PAUSED_STATE;
+ }
+ else if (!strcmp(buffer, "STOP")) {
+ stop();
+ *state = STOPPED_STATE;
+ }
+ else {
+ printf("Unknown command \"%s\"\n\r", buffer);
+ }
+}
+
+void USART2_IRQHandler() {
+ int ch = USART_Read(USART2);
+ remote_control_parse_input(ch);
+ if (!ch)
+ continue;
+ if (ch == '\r') {
+ *cur = 0;
+ handle_input(buffer, &state);
+ cur = buffer;
+ continue;
+ }
+ if (ch == 0x08 || ch == 0x7F) {
+ if (cur <= buffer)
+ continue;
+ cur--;
+ printf("\b \b");
+ continue;
+ }
+ *cur++ = ch;
+}
+
+