tangled
alpha
login
or
join now
baileytownsend.dev
/
rusty-badger
0
fork
atom
A personal rust firmware for the Badger 2040 W
0
fork
atom
overview
issues
pulls
pipelines
big wip but working
baileytownsend.dev
1 year ago
a6bf4f4f
22b7cd8b
+73
-2
1 changed file
expand all
collapse all
unified
split
src
badge_display
mod.rs
+73
-2
src/badge_display/mod.rs
···
34
34
pub static CURRENT_IMAGE: AtomicU8 = AtomicU8::new(0);
35
35
pub static CHANGE_IMAGE: AtomicBool = AtomicBool::new(true);
36
36
pub static WIFI_COUNT: AtomicU32 = AtomicU32::new(0);
37
37
+
pub static HOUR: AtomicU8 = AtomicU8::new(10);
38
38
+
pub static MINUTE: AtomicU8 = AtomicU8::new(57);
39
39
+
pub static SECOND: AtomicU8 = AtomicU8::new(0);
40
40
+
pub static WRITE_NEW_TIME: AtomicBool = AtomicBool::new(true);
37
41
38
42
#[embassy_executor::task]
39
43
pub async fn run_the_display(
···
85
89
let cycles_to_skip = 30;
86
90
let mut cycles_since_last_clear = 0;
87
91
92
92
+
let mut time_text: String<16> = String::<16>::new();
93
93
+
88
94
loop {
89
89
-
//TODO do the clock here need to
90
90
-
//1. Find the right time for counting
95
95
+
//if cycles are even, update the time values
96
96
+
if cycles_since_last_clear % 2 == 0 {
97
97
+
update_time_values_from_cycles();
98
98
+
}
99
99
+
100
100
+
if WRITE_NEW_TIME.load(core::sync::atomic::Ordering::Relaxed) {
101
101
+
let hour = HOUR.load(core::sync::atomic::Ordering::Relaxed);
102
102
+
let minute = MINUTE.load(core::sync::atomic::Ordering::Relaxed);
103
103
+
let second = SECOND.load(core::sync::atomic::Ordering::Relaxed);
104
104
+
105
105
+
let _ = core::fmt::write(
106
106
+
&mut time_text,
107
107
+
format_args!("{:02}:{:02}:{:02}", hour, minute, second),
108
108
+
);
109
109
+
110
110
+
let time_bounds = Rectangle::new(Point::new(0, 24), Size::new(WIDTH, 16));
111
111
+
time_bounds
112
112
+
.into_styled(
113
113
+
PrimitiveStyleBuilder::default()
114
114
+
.stroke_color(BinaryColor::Off)
115
115
+
.fill_color(BinaryColor::On)
116
116
+
.stroke_width(1)
117
117
+
.build(),
118
118
+
)
119
119
+
.draw(&mut display)
120
120
+
.unwrap();
121
121
+
122
122
+
Text::new(time_text.as_str(), Point::new(8, 32), character_style)
123
123
+
.draw(&mut display)
124
124
+
.unwrap();
125
125
+
126
126
+
let result = display
127
127
+
.partial_update(time_bounds.try_into().unwrap())
128
128
+
.await;
129
129
+
match result {
130
130
+
Ok(_) => {}
131
131
+
Err(_) => {
132
132
+
info!("Error updating display");
133
133
+
}
134
134
+
}
135
135
+
WRITE_NEW_TIME.store(false, core::sync::atomic::Ordering::Relaxed);
136
136
+
}
137
137
+
91
138
if cycles_since_last_clear >= cycles_to_skip || first_run {
92
139
let count = WIFI_COUNT.load(core::sync::atomic::Ordering::Relaxed);
93
140
let _ = core::fmt::write(&mut text, format_args!("Count: {}", count));
···
152
199
Timer::after(cycle).await;
153
200
}
154
201
}
202
202
+
203
203
+
fn update_time_values_from_cycles() {
204
204
+
let current_second = SECOND.load(core::sync::atomic::Ordering::Relaxed);
205
205
+
let current_minute = MINUTE.load(core::sync::atomic::Ordering::Relaxed);
206
206
+
let current_hour = HOUR.load(core::sync::atomic::Ordering::Relaxed);
207
207
+
208
208
+
let new_second = (current_second + 1) % 60;
209
209
+
let new_minute = if new_second == 0 {
210
210
+
WRITE_NEW_TIME.store(true, core::sync::atomic::Ordering::Relaxed);
211
211
+
(current_minute + 1) % 60
212
212
+
} else {
213
213
+
current_minute
214
214
+
};
215
215
+
let new_hour = if new_minute == 0 && new_second == 0 {
216
216
+
WRITE_NEW_TIME.store(true, core::sync::atomic::Ordering::Relaxed);
217
217
+
(current_hour + 1) % 24
218
218
+
} else {
219
219
+
current_hour
220
220
+
};
221
221
+
222
222
+
SECOND.store(new_second, core::sync::atomic::Ordering::Relaxed);
223
223
+
MINUTE.store(new_minute, core::sync::atomic::Ordering::Relaxed);
224
224
+
HOUR.store(new_hour, core::sync::atomic::Ordering::Relaxed);
225
225
+
}