aboutsummaryrefslogtreecommitdiffstats
path: root/sw
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2021-05-25 22:44:21 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2021-05-25 22:44:21 +0200
commit71f560ad84328453e75c9c7112003f76ea804684 (patch)
treeccae32088b1b2dd9b20822421d2e864a321b1823 /sw
parent74f15aabba9f285b3a4188e9ed29b53dbd120b9a (diff)
downloadpicardy-71f560ad84328453e75c9c7112003f76ea804684.tar.gz
picardy-71f560ad84328453e75c9c7112003f76ea804684.tar.bz2
picardy-71f560ad84328453e75c9c7112003f76ea804684.zip
Implement encoder acceleration and create two UI menus
Diffstat (limited to 'sw')
-rw-r--r--sw/picardy/src/state.rs50
-rw-r--r--sw/picardy/src/ui.rs179
2 files changed, 120 insertions, 109 deletions
diff --git a/sw/picardy/src/state.rs b/sw/picardy/src/state.rs
index c275033..4e6af33 100644
--- a/sw/picardy/src/state.rs
+++ b/sw/picardy/src/state.rs
@@ -1,10 +1,9 @@
pub const VHF_BAND_EDGE : u32 = 144_000_000;
pub const VHF_INITIAL_VFO : u32 = 144_300_000;
-pub const VHF_LO : u32 = 114_286_400;
+pub const VHF_LO : u32 = 114_284_800;
pub const BFO_LSB : u32 = 6_000_700 + 1_100;
pub const BFO_USB : u32 = 6_000_700 - 1_100;
pub const BFO_CW : u32 = 6_000_700 - 1_100;
-pub const QRG_CORRECTION : i32 = -1_600;
// Defines which parameter is changed by the encoder
#[derive(Clone, Copy, PartialEq, Eq)]
@@ -14,19 +13,18 @@ pub enum UISelection {
Mode,
}
+#[derive(Clone, Copy, PartialEq, Eq)]
+pub enum MenuPage {
+ One,
+ Two,
+}
+
#[derive(Clone, Copy)]
pub enum VFOSelection {
A,
B,
}
-#[derive(Clone)]
-pub enum TuneSpeed {
- Slow,
- Mid,
- Fast
-}
-
#[derive(PartialEq, Eq, Clone, Copy)]
pub enum CWMode {
StraightKey,
@@ -59,13 +57,13 @@ impl SequenceState {
#[derive(Clone)]
pub struct State {
+ pub menu_page : MenuPage,
pub ui_sel : UISelection,
pub vfo_a : u32,
pub vfo_b : u32,
pub vfo_sel : VFOSelection,
pub rit : i32,
pub mode : Mode,
- pub tune_speed : TuneSpeed,
pub sequence_state : SequenceState,
pub update_disp_counter : u8,
pub cw_wpm : u32,
@@ -74,16 +72,16 @@ pub struct State {
impl State {
pub fn new() -> Self {
State {
- rit : 0,
+ menu_page : MenuPage::One,
ui_sel : UISelection::VFO,
- mode : Mode::USB,
- vfo_sel : VFOSelection::A,
vfo_a : VHF_INITIAL_VFO,
vfo_b : VHF_INITIAL_VFO,
- tune_speed : TuneSpeed::Mid,
+ vfo_sel : VFOSelection::A,
+ rit : 0,
+ mode : Mode::USB,
sequence_state : SequenceState::Rx,
update_disp_counter : 0,
- cw_wpm : 12,
+ cw_wpm : 14,
}
}
@@ -115,26 +113,4 @@ impl State {
if self.sequence_state.apply_rit() { self.rit } else { 0 };
vfo as u32
}
-
- pub fn vfo_incr(&self) -> i32 {
- match self.tune_speed {
- TuneSpeed::Slow => 10,
- TuneSpeed::Mid => 200,
- TuneSpeed::Fast => 1000,
- }
- }
-
- pub fn rit_incr(&self) -> i32 {
- // RIT is always slow because it's a fine setting
- 2
- }
-
- pub fn bfo_incr(&self) -> i32 {
- match self.tune_speed {
- TuneSpeed::Slow => 10,
- TuneSpeed::Mid => 50,
- TuneSpeed::Fast => 100,
- }
- }
-
}
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();