Skip to content

Commit 8499e53

Browse files
committed
fix: v4 inspection time display on finished scene
1 parent a56fd5f commit 8499e53

3 files changed

Lines changed: 76 additions & 23 deletions

File tree

src/buttons.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ async fn inspection_start(
326326
}
327327

328328
if unsafe { CURRENT_TIME } != 0 {
329+
log::warn!("Skipping inspection start because current timer time is not 0");
329330
return Ok(false);
330331
}
331332

src/lcd_v4.rs

Lines changed: 65 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ pub const SMALL_FONT: MonoTextStyle<'_, BinaryColor> = MonoTextStyle::new(
7676
);
7777
pub const TIMER_FONT: MonoTextStyle<'_, BinaryColor> =
7878
MonoTextStyle::new(&profont::PROFONT_14_POINT, BinaryColor::On);
79+
pub const SMALL_TIMER_FONT: MonoTextStyle<'_, BinaryColor> =
80+
MonoTextStyle::new(&profont::PROFONT_7_POINT, BinaryColor::On);
7981

8082
pub const TEXT_CENTER: TextStyle = TextStyleBuilder::new()
8183
.alignment(Alignment::Center)
@@ -675,7 +677,6 @@ async fn process_main(
675677
Scene::Finished => {
676678
let solve_time = current_state.solve_time.unwrap_or(0);
677679
let time_str = ms_to_time_str(solve_time);
678-
679680
let inspection_time =
680681
match (current_state.inspection_start, current_state.inspection_end) {
681682
(Some(start), Some(end)) => {
@@ -684,15 +685,12 @@ async fn process_main(
684685
_ => None,
685686
};
686687

687-
let time_display = if current_state.use_inspection()
688-
&& inspection_time.unwrap_or(0) > INSPECTION_TIME_PLUS2
689-
{
690-
let inspection_seconds = inspection_time.unwrap_or(0) / 1000;
691-
alloc::format!("{time_str}+{inspection_seconds}s")
692-
} else {
693-
alloc::format!("{time_str}")
694-
};
688+
let show_inspection = current_state.use_inspection()
689+
&& inspection_time.unwrap_or(0) > INSPECTION_TIME_PLUS2;
690+
let inspection_display =
691+
show_inspection.then(|| ms_to_time_str(inspection_time.unwrap_or(0)));
695692

693+
let time_display = alloc::format!("{time_str}");
696694
let penalty = current_state.penalty.unwrap_or(0);
697695
let penalty_str: alloc::string::String = match penalty {
698696
-2 => "DNS".into(),
@@ -701,9 +699,64 @@ async fn process_main(
701699
_ => alloc::string::String::new(),
702700
};
703701

704-
if penalty_str.is_empty() {
705-
let time_text =
706-
Text::with_text_style(&time_display, Point::zero(), TIMER_FONT, TEXT_CENTER);
702+
let time_text =
703+
Text::with_text_style(&time_display, Point::zero(), TIMER_FONT, TEXT_CENTER);
704+
705+
if let Some(insp_str) = inspection_display {
706+
let insp_text =
707+
Text::with_text_style(&insp_str, Point::zero(), SMALL_TIMER_FONT, TEXT_CENTER);
708+
709+
if penalty_str.is_empty() {
710+
LinearLayout::vertical(
711+
Chain::new(
712+
LinearLayout::horizontal(Chain::new(time_text))
713+
.with_alignment(embedded_layout::align::vertical::Center)
714+
.arrange(),
715+
)
716+
.append(
717+
LinearLayout::horizontal(Chain::new(insp_text))
718+
.with_alignment(embedded_layout::align::vertical::Center)
719+
.arrange(),
720+
),
721+
)
722+
.with_alignment(embedded_layout::align::horizontal::Center)
723+
.arrange()
724+
.align_to(
725+
&MAIN_RECT,
726+
embedded_layout::align::horizontal::Center,
727+
embedded_layout::align::vertical::Top,
728+
)
729+
.translate(Point::new(0, 2))
730+
.draw(&mut oled.fbuf)?;
731+
} else {
732+
let penalty_text =
733+
Text::with_text_style(&penalty_str, Point::zero(), TIMER_FONT, TEXT_CENTER);
734+
LinearLayout::vertical(
735+
Chain::new(
736+
LinearLayout::horizontal(Chain::new(time_text).append(penalty_text))
737+
.with_alignment(embedded_layout::align::vertical::Center)
738+
.with_spacing(
739+
embedded_layout::layout::linear::spacing::FixedMargin(4),
740+
)
741+
.arrange(),
742+
)
743+
.append(
744+
LinearLayout::horizontal(Chain::new(insp_text))
745+
.with_alignment(embedded_layout::align::vertical::Center)
746+
.arrange(),
747+
),
748+
)
749+
.with_alignment(embedded_layout::align::horizontal::Center)
750+
.arrange()
751+
.align_to(
752+
&MAIN_RECT,
753+
embedded_layout::align::horizontal::Center,
754+
embedded_layout::align::vertical::Top,
755+
)
756+
.translate(Point::new(0, 2))
757+
.draw(&mut oled.fbuf)?;
758+
}
759+
} else if penalty_str.is_empty() {
707760
LinearLayout::horizontal(Chain::new(time_text))
708761
.with_alignment(embedded_layout::align::vertical::Center)
709762
.arrange()
@@ -715,8 +768,6 @@ async fn process_main(
715768
.translate(Point::new(0, 10))
716769
.draw(&mut oled.fbuf)?;
717770
} else {
718-
let time_text =
719-
Text::with_text_style(&time_display, Point::zero(), TIMER_FONT, TEXT_CENTER);
720771
let penalty_text =
721772
Text::with_text_style(&penalty_str, Point::zero(), TIMER_FONT, TEXT_CENTER);
722773
LinearLayout::horizontal(Chain::new(time_text).append(penalty_text))
@@ -743,13 +794,11 @@ async fn process_main(
743794
} else {
744795
None
745796
};
746-
747797
if let Some(status_str) = status {
748798
let textbox_style = TextBoxStyleBuilder::new()
749799
.alignment(HorizontalAlignment::Center)
750800
.vertical_alignment(VerticalAlignment::Bottom)
751801
.build();
752-
753802
TextBox::with_textbox_style(&status_str, MAIN_RECT, NORMAL_FONT, textbox_style)
754803
.draw(&mut oled.fbuf)?;
755804
}

src/stackmat.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,18 @@ pub async fn stackmat_task(
156156
state.scene = Scene::Timer;
157157
}
158158
} else if parsed.0 == StackmatTimerState::Stopped {
159-
log::info!("Timer stopped: {}ms", parsed.1);
160159
let mut state = global_state.state.lock().await;
160+
let inspection_time = state
161+
.inspection_end
162+
.zip(state.inspection_start)
163+
.map(|(end, start)| (end - start).as_millis())
164+
.unwrap_or(0);
165+
166+
log::info!(
167+
"Timer stopped: {}ms (inspection: {inspection_time}ms)",
168+
parsed.1
169+
);
161170
if state.solve_time.is_none() {
162-
let inspection_time = state
163-
.inspection_end
164-
.zip(state.inspection_start)
165-
.map(|(end, start)| (end - start).as_millis())
166-
.unwrap_or(0);
167-
168171
state.delegate_used = false;
169172
state.solve_time = Some(parsed.1);
170173
state.penalty = if inspection_time >= INSPECTION_TIME_DNF {

0 commit comments

Comments
 (0)