-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.c
More file actions
94 lines (72 loc) · 2.1 KB
/
Copy pathmain.c
File metadata and controls
94 lines (72 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/multicore.h"
#include "hardware/buzzer.h"
#include "hardware/keypad.h"
#include "hardware/latch.h"
#include "hardware/light.h"
#include "hardware/led.h"
#include "network/wifi.h"
#include "network/ntp.h"
#include "serial/commands.h"
#include "serial/console.h"
#include "storage/storage.h"
static void main1(void) {
// allow pausing core 1 while writing to flash
multicore_lockout_victim_init();
multicore_fifo_push_blocking(1); // signal core 0: ready
keypad_init();
while (true) {
char key = keypad_get_key();
if (key) {
// TODO: accumulate digits, verify TOTP, drive latch
printf("[keypad] key pressed: %c\r\n", key);
buzzer_beep_short();
}
sleep_ms(5);
}
}
static void boot_network(void) {
wifi_config_t cfg;
if (!storage_wifi_get(&cfg)) {
printf("[main] no wifi config - skipping NTP\r\n");
printf("[main] use set-wifi to configure\r\n");
buzzer_beep_long();
return;
}
if (!wifi_connect(cfg.ssid, cfg.password)) {
printf("[main] wifi connect failed - skipping NTP\r\n");
buzzer_beep_long();
return;
}
ntp_init();
// Block until first NTP sync succeeds - beep + retry on failure
printf("[main] waiting for NTP sync...\r\n");
while (!ntp_sync()) {
printf("[main] NTP sync failed, retrying in %ds...\r\n", NTP_RETRY_INTERVAL_S);
buzzer_beep_short();
sleep_ms(NTP_RETRY_INTERVAL_S * 1000);
}
printf("[main] NTP sync ok\r\n");
}
int main(void) {
stdio_init_all();
buzzer_init();
latch_init();
light_init();
led_init();
buzzer_beep_short();
// Core 1 must be running and ready before any flash writes
multicore_launch_core1(main1);
multicore_fifo_pop_blocking(); // wait for core 1 ready signal
storage_init();
boot_network();
// Startup beep - signals boot completed
buzzer_play_boot();
console_init();
while (true) {
console_task();
ntp_task();
sleep_ms(10);
}
}