summaryrefslogtreecommitdiff
path: root/project/Core/Src/Project
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
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 '')
-rw-r--r--project/Core/Src/Project/local_control.c55
-rw-r--r--project/Core/Src/Project/player_actions.c25
-rw-r--r--project/Core/Src/Project/project.c9
-rw-r--r--project/Core/Src/Project/remote_control.c22
4 files changed, 97 insertions, 14 deletions
diff --git a/project/Core/Src/Project/local_control.c b/project/Core/Src/Project/local_control.c
index ce40c22..8b12bc3 100644
--- a/project/Core/Src/Project/local_control.c
+++ b/project/Core/Src/Project/local_control.c
@@ -1,5 +1,6 @@
/*
* local_control.c
+ * Code related to the local control mode
*
* Created on: Nov 4, 2025
* Author: sowgro
@@ -11,15 +12,43 @@
#include "GPIO.h"
#include "project.h"
+int click_count = 0;
+uint32_t last_press = 0;
+uint32_t time_down = 0;
+int hold_pending = 0;
+
+/**
+ * Initialize local control mode (does not enable it)
+ */
void local_control_init() {
GPIO_Init();
NVIC_EnableIRQ(EXTI9_5_IRQn);
}
+/**
+ * Logic that should be called constantly from the main loop.
+ */
void local_control_loop() {
-
+ uint32_t now = systick_get_count();
+ if (hold_pending) {
+ hold_pending = 0;
+ printf("Hold click action\r\n");
+ }
+ if (now - last_press > 10000) {
+ last_press = 0;
+ switch(click_count) {
+ case 1:
+ printf("Single click action\r\n"); break;
+ case 2:
+ printf("Double click action\r\n"); break;
+ }
+ click_count = 0;
+ }
}
+/**
+ * Handles external button press
+ */
void EXTI9_5_IRQHandler() {
static int prevStatus = -1;
if (~EXTI->PR1 & EXTI_PR1_PIF9)
@@ -32,25 +61,33 @@ void EXTI9_5_IRQHandler() {
int status = !!(GPIOA->IDR & GPIO_PIN_9);
if (prevStatus == status)
return;
+ prevStatus = status;
handle_press(status);
}
-uint32_t time_down = 0;
+/**
+ * Logs button information
+ */
void handle_press(int pressed) {
uint32_t now = systick_get_count();
if (pressed) {
time_down = now;
} else {
- printf("now: %i, time_down: %i diff: %i\r\n", now, time_down, now - time_down);
- if (now - time_down < 10) {
- //ignore
- } else if (now - time_down < 10000) {
- printf("SHORT PRESS\r\n");
+// printf("now: %i, time_down: %i diff: %i\r\n", now, time_down, now - time_down);
+ if (/*(now - time_down) < 10 ||*/ !time_down) {
+ printf("ignored\r\n");
+// printf("now: %i, time_down: %i diff: %i\r\n", now, time_down, now - time_down);
+ } else if ((now - time_down) < 10000) {
+// printf("SHORT PRESS\r\n");
+ time_down = 0;
+ last_press = now;
+ click_count++;
} else {
- printf("LONG_PRESS\r\n");
+// printf("LONG PRESS\r\n");
+ hold_pending = 1;
+ time_down = 0;
}
- time_down = 0;
}
}
diff --git a/project/Core/Src/Project/player_actions.c b/project/Core/Src/Project/player_actions.c
index 4fc29a1..8318e08 100644
--- a/project/Core/Src/Project/player_actions.c
+++ b/project/Core/Src/Project/player_actions.c
@@ -1,5 +1,6 @@
/*
* player_actions.c
+ * Code related to the player states and actions
*
* Created on: Oct 17, 2025
* Author: sowgro
@@ -15,14 +16,23 @@
static uint8_t state = STOPPED_STATE;
+/**
+ * Returns the current player state to other files
+ */
uint8_t player_get_state() {
return state;
}
+/**
+ * Sets the current player state from other files
+ */
void player_set_state(uint8_t newState) {
state = newState;
}
+/**
+ * Prints the help message
+ */
void player_help() {
printf("\r***REMOTE LED CONTROL MENU***\r\n");
printf("Available User Commands:\r\n");
@@ -32,6 +42,9 @@ void player_help() {
printf("STOP - Stop the song (LED off)\r\n");
}
+/**
+ * Advances the player to the next song.
+ */
void player_next() {
static int current_song = -1;
current_song++;
@@ -50,21 +63,33 @@ void player_next() {
printf("Tempo: %i\r\n", song_info.tempo);
}
+/**
+ * Switches to the play state
+ */
void player_play() {
state = PLAYING_STATE;
LED_On();
}
+/**
+ * Switches to the pause state
+ */
void player_pause() {
state = PAUSED_STATE;
init_systick();
}
+/**
+ * Switches to the stop state
+ */
void player_stop() {
state = STOPPED_STATE;
LED_Off();
}
+/**
+ * Toggles the LED every second if in pause mode
+ */
void SysTick_Handler2(int count) {
if (state != PAUSED_STATE)
return;
diff --git a/project/Core/Src/Project/project.c b/project/Core/Src/Project/project.c
index d4517d7..1bb685b 100644
--- a/project/Core/Src/Project/project.c
+++ b/project/Core/Src/Project/project.c
@@ -19,10 +19,16 @@
static uint8_t mode = REMOTE_MODE;
+/**
+ * Returns the mode to other files
+ */
uint8_t project_get_mode() {
return mode;
}
+/**
+ * Runs the project
+ */
void project_run() {
HAL_Init();
local_control_init();
@@ -41,6 +47,9 @@ void project_run() {
}
}
+/**
+ * Listen for blue button presses
+ */
void EXTI15_10_IRQHandler() {
if (~EXTI->PR1 & EXTI_PR1_PIF13)
return;
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;
}