enum View {
Time,
Distance,
+ Pace,
}
struct Timer {
fn next_view(view: View) -> View {
match view {
View::Time => View::Distance,
- View::Distance => View::Time,
+ View::Distance => View::Pace,
+ View::Pace => View::Time,
}
}
fn previous_view(view: View) -> View {
match view {
- View::Time => View::Distance,
+ View::Time => View::Pace,
View::Distance => View::Time,
+ View::Pace => View::Distance,
}
}
let mut time_view = views::TimeView::new();
let mut distance_view = views::DistanceView::new();
+ let mut pace_view = views::PaceView::new();
let mut model = model::Model::new();
logger.log(&prev_tap, &tap);
model.update(model::Field::Distance(logger.total_distance_cm));
+ model.update(model::Field::Pace(logger.pace_s));
}
model.update(model::Field::UnixTime(tap.unix_time));
display.draw(&screen);
}
},
+ View::Pace => {
+ if pace_view.draw(&mut screen, &mut model) {
+ display.draw(&screen);
+ }
+ },
}
heart_icon_timer.update(|state| {
match view {
View::Time => time_view.invalidate(),
View::Distance => distance_view.invalidate(),
+ View::Pace => pace_view.invalidate(),
}
}
pub enum Field {
UnixTime(u32),
Distance(u32),
+ Pace(u32)
}
pub struct Model {
pub unix_time: u32,
pub distance_cm: u32,
+ pub pace_s: u32,
is_dirty: u32,
}
Model {
unix_time: 0,
distance_cm: 0,
+ pace_s: 0,
is_dirty: 0,
}
}
self.distance_cm = 0;
self.is_dirty |= Model::dirty_mask(Field::Distance(0));
}
+
+ if self.pace_s != 0 {
+ self.pace_s = 0;
+
+ self.is_dirty |= Model::dirty_mask(Field::Pace(0));
+ }
}
pub fn update(&mut self, data: Field) {
self.is_dirty |= Model::dirty_mask(data);
}
},
+ Field::Pace(pace_s) => {
+ if self.pace_s != pace_s {
+ self.pace_s = pace_s;
+ self.is_dirty |= Model::dirty_mask(data);
+ }
+ },
}
}
match data {
Field::UnixTime(_) => 1,
Field::Distance(_) => 2,
+ Field::Pace(_) => 4,
}
}
}
true
}
}
+
+pub struct PaceView {
+ is_valid: bool,
+}
+
+impl PaceView {
+ pub fn new() -> PaceView {
+ PaceView {
+ is_valid: false,
+ }
+ }
+
+ pub fn invalidate(&mut self) {
+ self.is_valid = false;
+ }
+
+ pub fn draw(&mut self, screen: &mut screen::Screen,
+ model: &mut model::Model) -> bool {
+ if self.is_valid &&
+ !model.check_and_reset_is_dirty(model::Field::Pace(0)) {
+ return false;
+ }
+
+ let mut min_and_s = [b':'; 6];
+
+ common::fmt::fmt_u32_pad(&mut min_and_s[0..3], model.pace_s / 60,
+ 3, b' ');
+
+ common::fmt::fmt_u32_pad(&mut min_and_s[4..6], model.pace_s % 60,
+ 2, b'0');
+
+ screen.clear();
+ screen.draw_text(&min_and_s);
+
+ self.is_valid = true;
+
+ true
+ }
+}