+42
-2
src/badge_display/mod.rs
+42
-2
src/badge_display/mod.rs
···
25
25
TextBox,
26
26
};
27
27
use gpio::Output;
28
-
use heapless::String;
28
+
use heapless::{String, Vec};
29
29
use tinybmp::Bmp;
30
30
use uc8151::LUT;
31
31
use uc8151::WIDTH;
···
34
34
35
35
use crate::{env::env_value, helpers::easy_format, Spi0Bus};
36
36
37
+
pub type RECENT_WIFI_NETWORKS_VEC = Vec<String<32>, 4>;
38
+
37
39
//Display state
38
40
pub static SCREEN_TO_SHOW: blocking_mutex::Mutex<CriticalSectionRawMutex, RefCell<Screen>> =
39
41
blocking_mutex::Mutex::new(RefCell::new(Screen::Badge));
42
+
pub static RECENT_WIFI_NETWORKS: blocking_mutex::Mutex<
43
+
CriticalSectionRawMutex,
44
+
RefCell<RECENT_WIFI_NETWORKS_VEC>,
45
+
> = blocking_mutex::Mutex::new(RefCell::new(RECENT_WIFI_NETWORKS_VEC::new()));
46
+
40
47
pub static FORCE_SCREEN_REFRESH: AtomicBool = AtomicBool::new(true);
41
48
pub static DISPLAY_CHANGED: AtomicBool = AtomicBool::new(false);
42
49
pub static CURRENT_IMAGE: AtomicU8 = AtomicU8::new(0);
···
235
242
CHANGE_IMAGE.store(false, core::sync::atomic::Ordering::Relaxed);
236
243
}
237
244
} else {
238
-
if cycles_since_last_clear % 60 == 0 || force_screen_refresh {
245
+
if force_screen_refresh {
239
246
let top_bounds = Rectangle::new(Point::new(0, 0), Size::new(WIDTH, 24));
240
247
top_bounds
241
248
.into_styled(
···
263
270
Err(_) => {
264
271
info!("Error updating display");
265
272
}
273
+
}
274
+
275
+
//write the wifi list
276
+
let mut y_offset = 24;
277
+
let wifi_list = RECENT_WIFI_NETWORKS.lock(|x| x.borrow().clone());
278
+
for wifi in wifi_list.iter() {
279
+
// let wifi_text: String<64> = easy_format::<64>(format_args!("{}", wifi));
280
+
let wifi_bounds = Rectangle::new(Point::new(0, y_offset), Size::new(WIDTH, 24));
281
+
wifi_bounds
282
+
.into_styled(
283
+
PrimitiveStyleBuilder::default()
284
+
.stroke_color(BinaryColor::Off)
285
+
.fill_color(BinaryColor::On)
286
+
.stroke_width(1)
287
+
.build(),
288
+
)
289
+
.draw(&mut display)
290
+
.unwrap();
291
+
292
+
Text::new(wifi.trim(), Point::new(8, y_offset + 16), character_style)
293
+
.draw(&mut display)
294
+
.unwrap();
295
+
296
+
let result = display
297
+
.partial_update(wifi_bounds.try_into().unwrap())
298
+
.await;
299
+
match result {
300
+
Ok(_) => {}
301
+
Err(_) => {
302
+
info!("Error updating display");
303
+
}
304
+
}
305
+
y_offset += 24;
266
306
}
267
307
}
268
308
}
+32
-2
src/main.rs
+32
-2
src/main.rs
···
7
7
use badge_display::display_image::DisplayImage;
8
8
use badge_display::{
9
9
run_the_display, Screen, CHANGE_IMAGE, CURRENT_IMAGE, DISPLAY_CHANGED, FORCE_SCREEN_REFRESH,
10
-
RTC_TIME_STRING, SCREEN_TO_SHOW, WIFI_COUNT,
10
+
RECENT_WIFI_NETWORKS, RECENT_WIFI_NETWORKS_VEC, RTC_TIME_STRING, SCREEN_TO_SHOW, WIFI_COUNT,
11
11
};
12
12
use core::fmt::Write;
13
13
use core::str::from_utf8;
···
318
318
info!("Button B pressed");
319
319
save.wifi_counted = 0;
320
320
save.bssid.clear();
321
-
WIFI_COUNT.store(0, core::sync::atomic::Ordering::Relaxed);
321
+
322
+
SCREEN_TO_SHOW.lock(|screen| {
323
+
if *screen.borrow() == Screen::Badge {
324
+
WIFI_COUNT.store(0, core::sync::atomic::Ordering::Relaxed);
325
+
}
326
+
});
327
+
328
+
let mut recent_networks = RECENT_WIFI_NETWORKS_VEC::new();
329
+
let mut scanner = control.scan(Default::default()).await;
330
+
while let Some(bss) = scanner.next().await {
331
+
process_bssid(bss.bssid, &mut save.wifi_counted, &mut save.bssid);
332
+
if recent_networks.len() < 8 {
333
+
let possible_ssid = core::str::from_utf8(&bss.ssid);
334
+
match possible_ssid {
335
+
Ok(ssid) => {
336
+
let ssid_string = easy_format::<32>(format_args!("{}", ssid.trim()));
337
+
if recent_networks.contains(&ssid_string) {
338
+
continue;
339
+
}
340
+
let _ = recent_networks.push(ssid_string);
341
+
}
342
+
Err(_) => {
343
+
continue;
344
+
}
345
+
}
346
+
}
347
+
}
348
+
RECENT_WIFI_NETWORKS.lock(|recent_networks_vec| {
349
+
recent_networks_vec.replace(recent_networks);
350
+
});
351
+
322
352
FORCE_SCREEN_REFRESH.store(true, core::sync::atomic::Ordering::Relaxed);
323
353
Timer::after(Duration::from_millis(500)).await;
324
354
current_cycle += 500;