summaryrefslogtreecommitdiff
path: root/project/Core/Src/Project/local_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/local_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/local_control.c')
-rw-r--r--project/Core/Src/Project/local_control.c55
1 files changed, 46 insertions, 9 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;
}
}