+17
-3
src/main.rs
+17
-3
src/main.rs
···
28
28
use embassy_rp::rtc::{DateTime, DayOfWeek};
29
29
use embassy_rp::spi::Spi;
30
30
use embassy_rp::spi::{self};
31
+
use embassy_rp::watchdog::Watchdog;
31
32
use embassy_rp::{bind_interrupts, gpio, i2c};
32
33
use embassy_sync::blocking_mutex::NoopMutex;
33
34
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
···
123
124
let btn_b = Input::new(p.PIN_13, Pull::Down);
124
125
let btn_c = Input::new(p.PIN_14, Pull::Down);
125
126
let rtc_alarm = Input::new(p.PIN_8, Pull::Down);
127
+
let mut watchdog = Watchdog::new(p.WATCHDOG);
126
128
127
129
//Setup i2c bus
128
130
let config = embassy_rp::i2c::Config::default();
···
171
173
RESOURCES.init(StackResources::new()),
172
174
seed,
173
175
);
176
+
177
+
//If the watch dog isn't fed in 60 seconds reboot to help with hang up
178
+
watchdog.start(Duration::from_secs(8));
174
179
175
180
spawner.must_spawn(net_task(runner));
176
181
//Attempt to connect to wifi to get RTC time loop for 2 minutes
···
180
185
let wifi_ssid = env_value("WIFI_SSID");
181
186
let wifi_password = env_value("WIFI_PASSWORD");
182
187
while wifi_connection_attempts < 30 {
188
+
watchdog.feed();
183
189
match control
184
190
.join(wifi_ssid, JoinOptions::new(wifi_password.as_bytes()))
185
191
.await
···
198
204
}
199
205
200
206
if connected_to_wifi {
207
+
//Feed the dog if it makes it this far
208
+
watchdog.feed();
201
209
info!("waiting for DHCP...");
202
210
while !stack.is_config_up() {
203
211
Timer::after_millis(100).await;
···
235
243
let url = env_value("TIME_API");
236
244
info!("connecting to {}", &url);
237
245
246
+
// Feeds the dog again for one last time
247
+
watchdog.feed();
248
+
238
249
//If the call goes through set the rtc
239
250
match http_client.request(Method::GET, &url).await {
240
251
Ok(mut request) => {
···
334
345
let reset_cycle = 3_000;
335
346
336
347
//Turn off led to signify that the badge is ready
337
-
user_led.set_low();
348
+
// user_led.set_low();
338
349
339
350
//RTC alarm stuff
340
351
let mut go_to_sleep = false;
···
353
364
}
354
365
355
366
loop {
367
+
//Keep feeding the dog
368
+
watchdog.feed();
369
+
356
370
//Change Image Button
357
371
if btn_c.is_high() {
358
372
info!("Button C pressed");
···
486
500
//goes to sleep for 15 mins
487
501
_ = rtc_device.disable_all_alarms();
488
502
_ = rtc_device.clear_alarm_flag();
489
-
_ = rtc_device.set_alarm_seconds(5);
490
-
_ = rtc_device.control_alarm_seconds(Control::On);
503
+
_ = rtc_device.set_alarm_minutes(15);
504
+
_ = rtc_device.control_alarm_minutes(Control::On);
491
505
_ = rtc_device.control_alarm_interrupt(Control::On);
492
506
power.set_low();
493
507
}