M source/src/calendar.rs => source/src/calendar.rs +4 -1
@@ 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,
M source/src/clock_app.rs => source/src/clock_app.rs +22 -6
@@ 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<dyn ClockButton + Send>; 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::<DisplayView>()).try_into().unwrap();
+ let new_view = ((current_view + 1) % core::mem::variant_count::<DisplayView>())
+ .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
M source/src/clock_display.rs => source/src/clock_display.rs +1 -1
@@ 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);
M source/src/clock_display_viewer.rs => source/src/clock_display_viewer.rs +57 -18
@@ 52,14 52,14 @@ impl TryFrom<usize> for ClockPart {
pub struct ClockDisplayViewer {
clock_display: ClockDisplay,
- parts: [bool; core::mem::variant_count::<ClockPart>()]
+ parts: [bool; core::mem::variant_count::<ClockPart>()],
}
impl ClockDisplayViewer {
pub fn new(clock_display: ClockDisplay) -> Self {
Self {
clock_display,
- parts: [false; core::mem::variant_count::<ClockPart>()]
+ parts: [false; core::mem::variant_count::<ClockPart>()],
}
}
@@ 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);
}