Skip to content

Commit 40bb279

Browse files
authored
Heavy patches (#152)
* Remove Launch test 2 Production doesn't use it anymore. Test 3 has been renamed test 2. * Arrange Testing panel into 2 x 2 grid. A vertical list was just a lot to scroll through. Request of production. * Remove num_runs_spin_3 Forgot to remove in 95700a6 * Only read keys in layout during nelson test Other Launch keyboards used every key in the keymap, so it was fine to read any key in the matrix. Though, on launch heavy there are several unmapped keys, these ones obviously don't get pressed by nelson, because they don't physically exist. This ignores those extra keys by only checking for pressed keys that are in both the matrix and the layout.
1 parent 6157a5a commit 40bb279

File tree

3 files changed

+39
-50
lines changed

3 files changed

+39
-50
lines changed

backend/src/layout/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ impl Layout {
178178
None
179179
})
180180
}
181+
182+
pub fn layout(&self) -> &HashMap<String, (u8, u8)> {
183+
&self.layout
184+
}
181185
}
182186

183187
fn parse_keymap_json(keymap_json: &str) -> (HashMap<String, u16>, HashMap<u16, String>) {

backend/src/nelson.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use serde::{Deserialize, Serialize};
22
use std::cmp;
3+
use std::collections::HashMap;
34

45
use crate::Matrix;
56

@@ -31,13 +32,12 @@ impl Nelson {
3132
)
3233
}
3334

34-
pub fn success(&self) -> bool {
35+
pub fn success(&self, layout: &HashMap<std::string::String, (u8, u8)>) -> bool {
36+
let mut values: Vec<&(u8, u8)> = layout.values().collect();
3537
for matrix in &[&self.missing, &self.bouncing, &self.sticking] {
36-
for row in 0..matrix.rows() {
37-
for col in 0..matrix.cols() {
38-
if matrix.get(row, col).unwrap_or(false) {
39-
return false;
40-
}
38+
for (row, col) in values.iter() {
39+
if matrix.get(*row as usize, *col as usize).unwrap_or(false) {
40+
return false;
4141
}
4242
}
4343
}

src/testing.rs

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ pub struct TestingInner {
5858
bench_button: DerefCell<gtk::ToggleButton>,
5959
bench_labels: DerefCell<HashMap<&'static str, gtk::Label>>,
6060
num_runs_spin_2: DerefCell<gtk::SpinButton>,
61-
num_runs_spin_3: DerefCell<gtk::SpinButton>,
62-
test_buttons: DerefCell<[gtk::Button; 3]>,
61+
test_buttons: DerefCell<[gtk::Button; 2]>,
6362
test_labels: DerefCell<[gtk::Label; 3]>,
6463
selma_start_button: DerefCell<gtk::Button>,
6564
selma_stop_button: DerefCell<gtk::Button>,
@@ -140,7 +139,7 @@ impl ObjectImpl for TestingInner {
140139

141140
let bench_button = gtk::ToggleButton::with_label("Run USB test");
142141

143-
obj.add(&cascade! {
142+
let usb_test = &cascade! {
144143
gtk::Box::new(gtk::Orientation::Vertical, 12);
145144
..add(&gtk::Label::new(Some("USB Port Test")));
146145
..add(&cascade! {
@@ -150,24 +149,22 @@ impl ObjectImpl for TestingInner {
150149
..add(&row(&bench_button));
151150
..set_header_func(Some(Box::new(header_func)));
152151
});
153-
});
152+
};
154153

155154
let num_runs_spin_2 = gtk::SpinButton::with_range(1.0, 1000.0, 1.0);
156-
let num_runs_spin_3 = gtk::SpinButton::with_range(1.0, 1000.0, 1.0);
157-
num_runs_spin_3.set_value(100.0);
155+
num_runs_spin_2.set_value(100.0);
158156

159157
let test_buttons = [
160158
gtk::Button::with_label(&fl!("button-test")),
161159
gtk::Button::with_label(&fl!("button-test")),
162-
gtk::Button::with_label(&fl!("button-test")),
163160
];
164161
let test_labels = [
165162
gtk::Label::new(None),
166163
gtk::Label::new(None),
167164
gtk::Label::new(None),
168165
];
169166

170-
obj.add(&cascade! {
167+
let nelson_test_1 = &cascade! {
171168
gtk::Box::new(gtk::Orientation::Vertical, 12);
172169
..add(&gtk::Label::new(Some("Nelson Test 1")));
173170
..add(&cascade! {
@@ -180,46 +177,31 @@ impl ObjectImpl for TestingInner {
180177
..add(&label_row("Check key (sticking)", &color_box(0., 1., 0.)));
181178
..set_header_func(Some(Box::new(header_func)));
182179
});
183-
});
180+
};
184181

185-
obj.add(&cascade! {
182+
let nelson_test_2 = &cascade! {
186183
gtk::Box::new(gtk::Orientation::Vertical, 12);
187184
..add(&gtk::Label::new(Some("Nelson Test 2")));
188185
..add(&cascade! {
189186
gtk::ListBox::new();
190187
..set_valign(gtk::Align::Start);
191188
..style_context().add_class("frame");
192-
..add(&label_row("Number of runs", &num_runs_spin_2));
189+
..add(&label_row(&fl!("test-number-of-runs"), &num_runs_spin_2));
193190
..add(&row(&test_buttons[1]));
194-
..add(&row(&test_labels[1]));
195-
..add(&label_row("Replace switch (bouncing)", &color_box(0., 0., 1.)));
196-
..set_header_func(Some(Box::new(header_func)));
197-
});
198-
});
199-
200-
obj.add(&cascade! {
201-
gtk::Box::new(gtk::Orientation::Vertical, 12);
202-
..add(&gtk::Label::new(Some("Nelson Test 3")));
203-
..add(&cascade! {
204-
gtk::ListBox::new();
205-
..set_valign(gtk::Align::Start);
206-
..style_context().add_class("frame");
207-
..add(&label_row(&fl!("test-number-of-runs"), &num_runs_spin_3));
208-
..add(&row(&test_buttons[2]));
209191
..add(&row(&test_labels[2]));
210192
..add(&label_row(&fl!("test-check-pins"), &color_box(1., 0., 0.)));
211193
..add(&label_row(&fl!("test-check-key"), &color_box(0., 1., 0.)));
212194
..set_header_func(Some(Box::new(header_func)));
213195
});
214-
});
196+
};
215197

216198
let selma_start_button = gtk::Button::with_label(&fl!("button-start"));
217199
let selma_stop_button = cascade! {
218200
gtk::Button::with_label(&fl!("button-stop"));
219201
..set_sensitive(false);
220202
};
221203

222-
obj.add(&cascade! {
204+
let selma_test = &cascade! {
223205
gtk::Box::new(gtk::Orientation::Vertical, 12);
224206
..add(&gtk::Label::new(Some("Selma Test")));
225207
..add(&cascade! {
@@ -235,13 +217,29 @@ impl ObjectImpl for TestingInner {
235217
..add(&label_row(&fl!("test-spurious-keypress"), &color_box(1., 0., 0.)));
236218
..set_header_func(Some(Box::new(header_func)));
237219
});
220+
};
221+
222+
obj.add(&cascade! {
223+
gtk::Box::new(gtk::Orientation::Horizontal, 18);
224+
..set_valign(gtk::Align::Start);
225+
..add(&cascade! {
226+
gtk::Box::new(gtk::Orientation::Vertical, 18);
227+
..set_valign(gtk::Align::Start);
228+
..add(&row(usb_test));
229+
..add(&row(selma_test));
230+
});
231+
..add(&cascade! {
232+
gtk::Box::new(gtk::Orientation::Vertical, 18);
233+
..set_valign(gtk::Align::Start);
234+
..add(&row(nelson_test_1));
235+
..add(&row(nelson_test_2));
236+
});
238237
});
239238

240239
self.reset_button.set(reset_button);
241240
self.bench_button.set(bench_button);
242241
self.bench_labels.set(bench_labels);
243242
self.num_runs_spin_2.set(num_runs_spin_2);
244-
self.num_runs_spin_3.set(num_runs_spin_3);
245243
self.test_buttons.set(test_buttons);
246244
self.test_labels.set(test_labels);
247245
self.selma_start_button.set(selma_start_button);
@@ -372,7 +370,7 @@ impl Testing {
372370
}
373371

374372
fn test_buttons_sensitive(&self, sensitive: bool) {
375-
for i in 0..3 {
373+
for i in 0..2 {
376374
self.inner().test_buttons[i].set_sensitive(sensitive);
377375
}
378376
self.inner().selma_start_button.set_sensitive(sensitive);
@@ -435,7 +433,7 @@ impl Testing {
435433

436434
self.notify("colors");
437435

438-
if nelson.success() {
436+
if nelson.success(testing.board.layout().layout()) {
439437
let message = format!("Test {}/{} successful", test_run, test_runs);
440438
info!("{}", message);
441439
test_label.set_text(&message);
@@ -467,18 +465,6 @@ impl Testing {
467465
glib::MainContext::default().spawn_local(clone!(@strong self_ => async move {
468466
self_.nelson(
469467
self_.inner().num_runs_spin_2.value_as_int(),
470-
1,
471-
NelsonKind::Bouncing,
472-
).await;
473-
}));
474-
}));
475-
}
476-
477-
fn connect_test_button_3(&self) {
478-
self.inner().test_buttons[2].connect_clicked(clone!(@strong self as self_ => move |_| {
479-
glib::MainContext::default().spawn_local(clone!(@strong self_ => async move {
480-
self_.nelson(
481-
self_.inner().num_runs_spin_3.value_as_int(),
482468
2,
483469
NelsonKind::Normal,
484470
).await;
@@ -569,7 +555,6 @@ impl Testing {
569555
obj.connect_bench_button();
570556
obj.connect_test_button_1();
571557
obj.connect_test_button_2();
572-
obj.connect_test_button_3();
573558
obj.connect_selma_buttons();
574559
obj.connect_reset_button();
575560
obj.update_benchmarks();

0 commit comments

Comments
 (0)