From 994a92fe69cfc8bbe5ebd05303695c8cf877eb7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Sun, 6 Aug 2023 22:59:35 +0200 Subject: [PATCH] chore(src): format with cargo-fmt --- source/src/calendar.rs | 5 +- source/src/clock_app.rs | 28 ++++++++--- source/src/clock_display.rs | 2 +- source/src/clock_display_viewer.rs | 75 +++++++++++++++++++++++------- 4 files changed, 84 insertions(+), 26 deletions(-) diff --git a/source/src/calendar.rs b/source/src/calendar.rs index d2b9adba219461bd6e49af9dba2ef2652c8192f5..8fe4e23c843265568437a070677e650aa2e6253e 100644 --- a/source/src/calendar.rs +++ b/source/src/calendar.rs @@ -211,7 +211,10 @@ impl Calendar { /// Sets the current day of the month, /// gets clamped to 1 - days in the month. pub fn set_day(&mut self, day: u8) { - self.day = day.clamp(1, Self::days_in_month(self.month, Self::is_leap_year(self.year))); + self.day = day.clamp( + 1, + Self::days_in_month(self.month, Self::is_leap_year(self.year)), + ); } /// Sets the current day of the month, diff --git a/source/src/clock_app.rs b/source/src/clock_app.rs index 410dd2f606be49b6feded4f7d33321f37c9dc302..7b50dd2d771178674837df01687377bdac4d701e 100644 --- a/source/src/clock_app.rs +++ b/source/src/clock_app.rs @@ -4,8 +4,10 @@ use alloc::boxed::Box; use stm32f1xx_hal::rtc::Rtc; use crate::{ - brightness_manager::BrightnessManager, button::ButtonState, - clock_display_viewer::{ClockDisplayViewer, DisplayView}, clock_state::ClockState, + brightness_manager::BrightnessManager, + button::ButtonState, + clock_display_viewer::{ClockDisplayViewer, DisplayView}, + clock_state::ClockState, }; pub struct ClockApp { @@ -14,7 +16,7 @@ pub struct ClockApp { state: ClockState, buttons: [Box; 4], brightness: BrightnessManager, - current_view: DisplayView + current_view: DisplayView, } struct AppState<'a> { @@ -22,7 +24,7 @@ struct AppState<'a> { display: &'a mut ClockDisplayViewer, state: &'a mut ClockState, brightness: &'a mut BrightnessManager, - current_view: &'a mut DisplayView + current_view: &'a mut DisplayView, } trait ClockButton { @@ -86,7 +88,7 @@ impl ClockApp { display: &mut self.display, state: &mut self.state, brightness: &mut self.brightness, - current_view: &mut self.current_view + current_view: &mut self.current_view, }, ); } @@ -102,7 +104,9 @@ impl ClockButton for ButtonSwitchView { ButtonState::JustPressed => { let display = app.display; let current_view = *app.current_view as usize; - let new_view = ((current_view + 1) % core::mem::variant_count::()).try_into().unwrap(); + let new_view = ((current_view + 1) % core::mem::variant_count::()) + .try_into() + .unwrap(); display.set_current_view(new_view); *app.current_view = new_view; } @@ -145,3 +149,15 @@ impl ClockButton for ButtonChangeTime { } } } + +// to edit date, second button can be used +// to enter edit mode +// DateEditMode +// editing_field +// 1. Hours, 2. Minutes, 3. Seconds, +// 4. Year, 5. Month, 6. Day +// button functions: +// 1. next field +// 2. current_field++ +// 3. current_field-- +// 4. set diff --git a/source/src/clock_display.rs b/source/src/clock_display.rs index 4a6e26c9ea68f5d0590f21930d2d3c35f9ec6de4..daf5edd0cb070625a8eae73dca39425077e4c3bd 100644 --- a/source/src/clock_display.rs +++ b/source/src/clock_display.rs @@ -64,7 +64,7 @@ impl ClockDisplay { &mut self, part: DisplayPart, number: u32, - pad: bool + pad: bool, ) -> Result<(), DisplayError> { let offset = Self::get_part_offset(part); let size = Self::get_part_size(part); diff --git a/source/src/clock_display_viewer.rs b/source/src/clock_display_viewer.rs index ba8160b16615a845a9316bff3a1c6db17254ecaf..68a8cc76762af3344ea137d7be6ef98139002afd 100644 --- a/source/src/clock_display_viewer.rs +++ b/source/src/clock_display_viewer.rs @@ -52,14 +52,14 @@ impl TryFrom for ClockPart { pub struct ClockDisplayViewer { clock_display: ClockDisplay, - parts: [bool; core::mem::variant_count::()] + parts: [bool; core::mem::variant_count::()], } impl ClockDisplayViewer { pub fn new(clock_display: ClockDisplay) -> Self { Self { clock_display, - parts: [false; core::mem::variant_count::()] + parts: [false; core::mem::variant_count::()], } } @@ -91,18 +91,18 @@ impl ClockDisplayViewer { DisplayView::ClockView => { self.show(ClockPart::Hours); self.show(ClockPart::Minutes); - }, + } DisplayView::ClockSecondsView => { self.show(ClockPart::Hours); self.show(ClockPart::Minutes); self.show(ClockPart::Seconds); - }, + } DisplayView::ClockDateView => { self.show(ClockPart::Hours); self.show(ClockPart::Minutes); self.show(ClockPart::Day); self.show(ClockPart::Month); - }, + } DisplayView::DateView => { self.show(ClockPart::Day); self.show(ClockPart::Month); @@ -122,28 +122,67 @@ impl ClockDisplayViewer { let part: ClockPart = ClockPart::try_from(i).unwrap(); match part { ClockPart::Day => { - self.clock_display.show_ordinal(DisplayPart::SideDisplay1, state.calendar().day() as u32, true).unwrap(); - }, + self.clock_display + .show_ordinal( + DisplayPart::SideDisplay1, + state.calendar().day() as u32, + true, + ) + .unwrap(); + } ClockPart::Month => { - self.clock_display.show_ordinal(DisplayPart::SideDisplay2, state.calendar().month() as u32, true).unwrap(); - }, + self.clock_display + .show_ordinal( + DisplayPart::SideDisplay2, + state.calendar().month() as u32, + true, + ) + .unwrap(); + } ClockPart::Year => { - self.clock_display.show_number(DisplayPart::MainDisplay, state.calendar().year() as u32, true).unwrap(); - }, + self.clock_display + .show_number( + DisplayPart::MainDisplay, + state.calendar().year() as u32, + true, + ) + .unwrap(); + } ClockPart::Hours => { - self.clock_display.show_number_at(ClockDisplay::get_part_offset(DisplayPart::MainDisplay), 2, state.calendar().hours() as u32, true).unwrap(); - }, + self.clock_display + .show_number_at( + ClockDisplay::get_part_offset(DisplayPart::MainDisplay), + 2, + state.calendar().hours() as u32, + true, + ) + .unwrap(); + } ClockPart::Minutes => { - self.clock_display.show_number_at(ClockDisplay::get_part_offset(DisplayPart::MainDisplay) + 2, 2, state.calendar().minutes() as u32, true).unwrap(); - }, + self.clock_display + .show_number_at( + ClockDisplay::get_part_offset(DisplayPart::MainDisplay) + 2, + 2, + state.calendar().minutes() as u32, + true, + ) + .unwrap(); + } ClockPart::Seconds => { - self.clock_display.show_number(DisplayPart::SideDisplay2, state.calendar().seconds() as u32, true).unwrap(); - }, + self.clock_display + .show_number( + DisplayPart::SideDisplay2, + state.calendar().seconds() as u32, + true, + ) + .unwrap(); + } } } if self.parts[ClockPart::Hours as usize] && self.parts[ClockPart::Minutes as usize] { - self.clock_display.set_colon(state.calendar().seconds() % 2 == 0); + self.clock_display + .set_colon(state.calendar().seconds() % 2 == 0); } else { self.clock_display.set_colon(false); }