summaryrefslogtreecommitdiff
path: root/project/Core/Src/Project/remote_control.c
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2025-11-06 22:09:21 -0500
committersowgro <tpoke.ferrari@gmail.com>2025-11-06 22:09:21 -0500
commitff93296322bcff19d9983c3d800bffbd08a35941 (patch)
tree6eac8d5080bafbe101b5103ee95f3a8445b21bd7 /project/Core/Src/Project/remote_control.c
parent843e263ac896fae11b8c176810bab4866eb8b2a8 (diff)
download340-repo-Sowgro-ff93296322bcff19d9983c3d800bffbd08a35941.tar.gz
340-repo-Sowgro-ff93296322bcff19d9983c3d800bffbd08a35941.tar.bz2
340-repo-Sowgro-ff93296322bcff19d9983c3d800bffbd08a35941.zip
add comments, fix remote control, work on local control
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;
}