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