summaryrefslogtreecommitdiff
path: root/project/Core/Src/Project/remote_control.c
diff options
context:
space:
mode:
Diffstat (limited to 'project/Core/Src/Project/remote_control.c')
-rw-r--r--project/Core/Src/Project/remote_control.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/project/Core/Src/Project/remote_control.c b/project/Core/Src/Project/remote_control.c
index c8c1f73..c549eb1 100644
--- a/project/Core/Src/Project/remote_control.c
+++ b/project/Core/Src/Project/remote_control.c
@@ -1,5 +1,6 @@
/*
* remote_control.c
+ * Code related to the local control mode
*
* Created on: Nov 4, 2025
* Author: sowgro
@@ -17,6 +18,9 @@
static char buffer[80];
static char* cur = buffer;
+/**
+ * Initialize remote control mode (does not enable it)
+ */
void remote_control_init() {
NVIC_EnableIRQ (USART2_IRQn);
USART2->CR1 |= USART_CR1_RXNEIE; // 1 << 5
@@ -24,11 +28,18 @@ void remote_control_init() {
player_help();
}
+/**
+ * Logic that should be called constantly from the main loop.
+ */
void remote_control_loop() {
-
+ if (*cur == '\r') {
+ *cur = 0;
+ parse_input(buffer);
+ cur = buffer;
+ }
}
-static void parse_input(char buffer[]) {
+void parse_input(char buffer[]) {
if (!strcmp(buffer, "HELP")) {
player_help();
}
@@ -49,6 +60,9 @@ static void parse_input(char buffer[]) {
}
}
+/**
+ * Handles user input
+ */
void USART2_IRQHandler() {
int ch = USART_Read(USART2);
@@ -63,9 +77,7 @@ void USART2_IRQHandler() {
if (ch == '\r') {
putchar('\n');
- *cur = 0;
- parse_input(buffer);
- cur = buffer;
+ *cur = ch;
return;
}