Skip to content

Commit 36c2e87

Browse files
committed
wip: selection handling minor improvements
1 parent 6296861 commit 36c2e87

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

mqtt_example/src/controls.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ impl<'controls, SELECT: InputPin, ENTER: InputPin> Controls<'controls, SELECT, E
8383
data: self.selection,
8484
})
8585
.unwrap();
86-
self.selection = 0;
8786
// GPIO35 has no pull up resistor, this helps not to send multiple events
8887
thread::sleep(Duration::from_millis(500))
8988
}

mqtt_example/src/main.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ fn main() -> anyhow::Result<()> {
9292
let mut question_id = Default::default();
9393
let mut question_text = Default::default();
9494
let mut options: Vec<String> = Default::default();
95+
let mut selection: u8 = 0;
9596

9697
let header_text_bounds = Rectangle::new(
9798
Point::zero(),
@@ -129,7 +130,7 @@ fn main() -> anyhow::Result<()> {
129130
);
130131
text_box.draw(&mut display).unwrap();
131132
for (idx, option) in options.iter().enumerate() {
132-
let selected = idx == 0;
133+
let selected = idx as u8 == selection;
133134
Text::new(
134135
format!("{} {}", if selected { ">" } else { " " }, option).as_str(),
135136
Point::new(0, 20 * idx as i32 + DISPLAY_SIZE.1 as i32 / 2),
@@ -144,6 +145,10 @@ fn main() -> anyhow::Result<()> {
144145
}
145146
}
146147
DeviceEvent::Select { data } => {
148+
selection = data;
149+
if question_id.is_empty() {
150+
continue;
151+
}
147152
// TODO: duplicate, move to display module
148153
Rectangle::new(
149154
Point::new(0, (DISPLAY_SIZE.1 / 2 - 12).into()),
@@ -152,7 +157,7 @@ fn main() -> anyhow::Result<()> {
152157
.draw_styled(&PrimitiveStyle::with_fill(Rgb565::BLACK), &mut display)
153158
.unwrap();
154159
for (idx, option) in options.iter().enumerate() {
155-
let selected = idx as u8 == data;
160+
let selected = idx as u8 == selection;
156161
Text::new(
157162
format!("{} {}", if selected { ">" } else { " " }, option).as_str(),
158163
Point::new(0, 20 * idx as i32 + DISPLAY_SIZE.1 as i32 / 2),
@@ -167,7 +172,7 @@ fn main() -> anyhow::Result<()> {
167172
}
168173
}
169174
DeviceEvent::Enter { data } => {
170-
if question_id.len() == 0 {
175+
if question_id.is_empty() {
171176
continue;
172177
}
173178
// TODO: add device id (from MAC?)

0 commit comments

Comments
 (0)