summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2025-08-03 16:01:05 +0200
committerJan200101 <sentrycraft123@gmail.com>2025-08-03 16:01:05 +0200
commit7eac4b5eb6b863d2ecb3f8a2bef2e38bac8a16ab (patch)
tree624e2545e3ce246e38d0f6cf04ec8817c6009f49 /src
parent74f9ff4e7fa0d30ead7ddf8bc87f3be7c62f1e78 (diff)
downloadpico-relay-7eac4b5eb6b863d2ecb3f8a2bef2e38bac8a16ab.tar.gz
pico-relay-7eac4b5eb6b863d2ecb3f8a2bef2e38bac8a16ab.zip
read stdio via callback instead of manually
Diffstat (limited to 'src')
-rw-r--r--src/main.c53
1 files changed, 29 insertions, 24 deletions
diff --git a/src/main.c b/src/main.c
index afcdb30..fa53c3e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -29,6 +29,32 @@ absolute_time_t wifi_connected_time;
#define LEVEL_START 95.0
#define LEVEL_END 85.0
+static void key_pressed_func(void *param)
+{
+ int input = stdio_getchar_timeout_us(0);
+ if (input != PICO_ERROR_TIMEOUT)
+ {
+ LogDebug("input => %i", input);
+
+ switch(input)
+ {
+ case 'd':
+ LogInfo("disconnecting");
+ modbus_close_connection();
+ break;
+
+ case 'p':
+ LogInfo("rebooting into programming mode");
+ modbus_close_connection();
+ rom_reset_usb_boot_extra(-1, 0, false);
+ break;
+
+ default:
+ break;
+ }
+ }
+}
+
int main()
{
stdio_init_all();
@@ -37,6 +63,9 @@ int main()
busy_wait_ms(5000);
#endif
+ LogInfo("initializing stdio callback");
+ stdio_set_chars_available_callback(key_pressed_func, NULL);
+
LogInfo("initializing relay");
init_relay();
@@ -127,30 +156,6 @@ int main()
}
}
- LogDebug("checking for inputs");
- int input = stdio_getchar_timeout_us(0);
- if (input != PICO_ERROR_TIMEOUT)
- {
- LogDebug("input => %i", input);
-
- switch(input)
- {
- case 'd':
- LogInfo("disconnecting");
- modbus_close_connection();
- break;
-
- case 'p':
- LogInfo("rebooting into programming mode");
- modbus_close_connection();
- rom_reset_usb_boot_extra(-1, 0, false);
- break;
-
- default:
- break;
- }
- }
-
if (state != last_state)
{
LogInfo("state change %i => %i", last_state, state);