aboutsummaryrefslogtreecommitdiffstats
path: root/sw/picardy/src/ui.rs
diff options
context:
space:
mode:
Diffstat (limited to 'sw/picardy/src/ui.rs')
-rw-r--r--sw/picardy/src/ui.rs179
1 files changed, 107 insertions, 72 deletions
diff --git a/sw/picardy/src/ui.rs b/sw/picardy/src/ui.rs
index 0170813..728e6e7 100644
--- a/sw/picardy/src/ui.rs
+++ b/sw/picardy/src/ui.rs
@@ -52,6 +52,10 @@ struct ButtonState {
pub ptt : bool,
}
+const VFO_INCR : i32 = 2;
+const RIT_INCR : i32 = 1;
+const BFO_INCR : i32 = 10;
+
impl ButtonState {
fn edge_detection(&self, old_state : &ButtonState) -> ButtonState {
ButtonState {
@@ -179,96 +183,123 @@ impl UI {
result.ptt = button_updates.ptt;
- if button_updates.a {
- state.vfo_sel = match (state.ui_sel, state.vfo_sel) {
- (UISelection::VFO, VFOSelection::A) => VFOSelection::B,
- (UISelection::VFO, VFOSelection::B) => VFOSelection::A,
- _ => state.vfo_sel.clone(),
- };
- state.ui_sel = UISelection::VFO;
- result.display_update = true;
- }
+ match state.menu_page {
+ MenuPage::One => {
+ if button_updates.a {
+ state.vfo_sel = match (state.ui_sel, state.vfo_sel) {
+ (UISelection::VFO, VFOSelection::A) => VFOSelection::B,
+ (UISelection::VFO, VFOSelection::B) => VFOSelection::A,
+ _ => state.vfo_sel.clone(),
+ };
+ state.ui_sel = UISelection::VFO;
+ result.display_update = true;
+ }
- if button_updates.b {
- state.ui_sel = UISelection::RIT;
- result.display_update = true;
- }
+ if button_updates.b {
+ state.ui_sel = UISelection::RIT;
+ result.display_update = true;
+ }
- if button_updates.c {
- let (new_ui_sel, new_filter_shift) = match (state.ui_sel, state.mode) {
- (UISelection::Mode, Mode::USB) => (UISelection::Mode, Mode::LSB),
- (UISelection::Mode, Mode::LSB) => (UISelection::Mode, Mode::CW(CWMode::StraightKey)),
- (UISelection::Mode, Mode::CW(CWMode::StraightKey)) => (UISelection::Mode, Mode::CW(CWMode::Iambic)),
- (UISelection::Mode, Mode::CW(CWMode::Iambic)) => (UISelection::Mode, Mode::USB),
- (UISelection::Mode, Mode::CustomShift(_)) => (UISelection::Mode, Mode::USB),
- (_, f) => (UISelection::Mode, f),
- };
+ if button_updates.c {
+ let (new_ui_sel, new_filter_shift) = match (state.ui_sel, state.mode) {
+ (UISelection::Mode, Mode::USB) => (UISelection::Mode, Mode::LSB),
+ (UISelection::Mode, Mode::LSB) => (UISelection::Mode, Mode::CW(CWMode::StraightKey)),
+ (UISelection::Mode, Mode::CW(CWMode::StraightKey)) => (UISelection::Mode, Mode::CW(CWMode::Iambic)),
+ (UISelection::Mode, Mode::CW(CWMode::Iambic)) => (UISelection::Mode, Mode::USB),
+ (UISelection::Mode, Mode::CustomShift(_)) => (UISelection::Mode, Mode::USB),
+ (_, f) => (UISelection::Mode, f),
+ };
- state.ui_sel = new_ui_sel;
- state.mode = new_filter_shift;
+ state.ui_sel = new_ui_sel;
+ state.mode = new_filter_shift;
- result.display_update = true;
- }
+ result.display_update = true;
+ }
- if button_updates.d {
- state.tune_speed = match state.tune_speed {
- TuneSpeed::Slow => TuneSpeed::Mid,
- TuneSpeed::Mid => TuneSpeed::Fast,
- TuneSpeed::Fast => TuneSpeed::Slow,
- };
- result.display_update = true;
- }
+ if button_updates.d {
+ state.menu_page = MenuPage::Two;
+ result.display_update = true;
+ }
- if button_updates.enc {
- match state.ui_sel {
- UISelection::VFO => {},
- UISelection::RIT => {
- state.rit = 0;
- },
- UISelection::Mode => {
- state.mode = Mode::USB;
- },
- }
+ if button_updates.enc {
+ match state.ui_sel {
+ UISelection::VFO => {},
+ UISelection::RIT => {
+ state.rit = 0;
+ },
+ UISelection::Mode => {
+ state.mode = Mode::USB;
+ },
+ }
+
+ result.display_update = true;
+ }
+ },
+ MenuPage::Two => {
+ state.ui_sel = UISelection::VFO;
+
+ if button_updates.a {
+ }
+
+ if button_updates.b {
+ }
- result.display_update = true;
+ if button_updates.c {
+ }
+
+ if button_updates.d {
+ state.menu_page = MenuPage::One;
+ result.display_update = true;
+ }
+
+ if button_updates.enc {
+ }
+ },
}
result
}
// Returns true if bfo must be reprogrammed
- pub fn update_encoder(&mut self, state: &mut State, delta : i32) -> bool {
+ pub fn update_encoder(&mut self, state: &mut State, counter_delta : i32) -> bool {
+
+ let delta = (17 * counter_delta + 3 * (counter_delta * counter_delta * counter_delta))/20;
+
match state.ui_sel {
UISelection::VFO => {
match state.vfo_sel {
VFOSelection::A => {
- state.vfo_a = (state.vfo_a as i32 + delta * state.vfo_incr()) as u32;
+ state.vfo_a = (state.vfo_a as i32 + delta * VFO_INCR) as u32;
},
VFOSelection::B => {
- state.vfo_b = (state.vfo_b as i32 + delta * state.vfo_incr()) as u32;
+ state.vfo_b = (state.vfo_b as i32 + delta * VFO_INCR) as u32;
},
}
false
},
UISelection::RIT => {
- state.rit = state.rit + delta * state.rit_incr();
+ state.rit = state.rit + delta * RIT_INCR;
false
},
UISelection::Mode => {
match state.mode {
Mode::CW(CWMode::Iambic) => {
- let mut new_wpm = state.cw_wpm as i32 + delta / 4;
+ let mut new_wpm = state.cw_wpm as i32 + counter_delta / 4;
if new_wpm < 1 {
new_wpm = 1;
}
+ if new_wpm > 40 {
+ new_wpm = 40;
+ }
+
let wpm = new_wpm as u32;
state.cw_wpm = wpm;
state.mode = Mode::CW(CWMode::Iambic);
false
},
_ => {
- let new_bfo = (state.bfo() as i32 + delta * state.bfo_incr()) as u32;
+ let new_bfo = (state.bfo() as i32 + counter_delta * BFO_INCR) as u32;
state.mode = Mode::CustomShift(new_bfo);
true
},
@@ -291,6 +322,9 @@ pub fn update_disp<T: hd44780_driver::bus::DataBus>(lcd: &mut HD44780<T>, state:
(UISelection::Mode, Mode::CW(CWMode::Iambic)) => {
write!(string, "CW{:<02}", state.cw_wpm).unwrap();
},
+ (UISelection::Mode, Mode::CustomShift(shift)) => {
+ write!(string, "{:<04}", shift/10).unwrap();
+ },
_ => {
write!(string, "{}{:<03}", if state.rit >= 0 { "+" } else { "-" }, state.rit.abs()/10).unwrap();
},
@@ -306,31 +340,32 @@ pub fn update_disp<T: hd44780_driver::bus::DataBus>(lcd: &mut HD44780<T>, state:
string.clear();
- match (bfo_tune_fail, &state.vfo_sel) {
- (true, _) => write!(string, "VFO!").unwrap(),
- (false, VFOSelection::A) => write!(string, "VFOa").unwrap(),
- (false, VFOSelection::B) => write!(string, "VFOb").unwrap(),
- }
-
- write!(string, "{}", if state.ui_sel == UISelection::RIT { ">RIT" } else { " RIT" }).unwrap();
+ match state.menu_page {
+ MenuPage::One => {
+ match (bfo_tune_fail, &state.vfo_sel) {
+ (true, _) => write!(string, "VFO!").unwrap(),
+ (false, VFOSelection::A) => write!(string, "VFOa").unwrap(),
+ (false, VFOSelection::B) => write!(string, "VFOb").unwrap(),
+ }
- write!(string, "{}", if state.ui_sel == UISelection::Mode { ">" } else { " " }).unwrap();
+ write!(string, "{}", if state.ui_sel == UISelection::RIT { ">RIT" } else { " RIT" }).unwrap();
- let mode = match state.mode {
- Mode::USB => "USB",
- Mode::LSB => "LSB",
- Mode::CustomShift(_) => "IFs",
- Mode::CW(CWMode::StraightKey) => "CWs",
- Mode::CW(CWMode::Iambic) => "CWp",
- };
+ write!(string, "{}", if state.ui_sel == UISelection::Mode { ">" } else { " " }).unwrap();
- let speed = match state.tune_speed {
- TuneSpeed::Slow => "SLO",
- TuneSpeed::Mid => "MID",
- TuneSpeed::Fast => "FST",
- };
+ let mode = match state.mode {
+ Mode::USB => "USB",
+ Mode::LSB => "LSB",
+ Mode::CustomShift(_) => "IFs",
+ Mode::CW(CWMode::StraightKey) => "CWs",
+ Mode::CW(CWMode::Iambic) => "CWp",
+ };
- write!(string, "{} {}", mode, speed).unwrap();
+ write!(string, "{} 1/2", mode).unwrap();
+ },
+ MenuPage::Two => {
+ write!(string, "---- --- --- 2/2").unwrap();
+ },
+ }
lcd.set_cursor_pos(40, delay).unwrap();
lcd.write_str(&string, delay).unwrap();