aboutsummaryrefslogtreecommitdiffstats
path: root/sw/dart-70/src/state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'sw/dart-70/src/state.rs')
-rw-r--r--sw/dart-70/src/state.rs129
1 files changed, 129 insertions, 0 deletions
diff --git a/sw/dart-70/src/state.rs b/sw/dart-70/src/state.rs
new file mode 100644
index 0000000..08826e7
--- /dev/null
+++ b/sw/dart-70/src/state.rs
@@ -0,0 +1,129 @@
+pub const VHF_BAND_EDGE : u32 = 144_000_000;
+pub const VHF_INITIAL_VFO : u32 = 144_300_000;
+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;
+
+// Defines which parameter is changed by the encoder
+#[derive(Clone, Copy, PartialEq, Eq)]
+pub enum UISelection {
+ VFO,
+ RIT,
+ Mode,
+}
+
+#[derive(Clone, Copy, PartialEq, Eq)]
+pub enum MenuPage {
+ One,
+ Two,
+}
+
+#[derive(Clone, Copy)]
+pub enum VFOSelection {
+ A,
+ B,
+}
+
+#[derive(PartialEq, Eq, Clone, Copy)]
+pub enum CWMode {
+ StraightKey,
+ Iambic,
+}
+
+#[derive(PartialEq, Eq, Clone, Copy)]
+pub enum Mode {
+ LSB,
+ USB,
+ CustomShift(u32),
+ CW(CWMode),
+}
+
+#[derive(Clone, PartialEq, Eq)]
+pub enum SequenceState {
+ Rx,
+ MutingSpkr,
+ SwitchingSSB,
+ TxSSB,
+ SwitchingCW,
+ TxCW,
+}
+
+impl SequenceState {
+ fn apply_rit(&self) -> bool {
+ *self == SequenceState::Rx
+ }
+}
+
+#[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 send_tone : bool,
+ pub sequence_state : SequenceState,
+ pub update_disp_counter : u8,
+ pub cw_wpm : u32,
+}
+
+impl State {
+ pub fn new() -> Self {
+ State {
+ menu_page : MenuPage::One,
+ ui_sel : UISelection::VFO,
+ vfo_a : VHF_INITIAL_VFO,
+ vfo_b : VHF_INITIAL_VFO,
+ vfo_sel : VFOSelection::A,
+ rit : 0,
+ mode : Mode::USB,
+ send_tone : false,
+ sequence_state : SequenceState::Rx,
+ update_disp_counter : 0,
+ cw_wpm : 14,
+ }
+ }
+
+ pub fn bfo(&self) -> u32 {
+ if self.send_tone {
+ 0
+ }
+ else {
+ match self.mode {
+ Mode::LSB => BFO_LSB,
+ Mode::USB => BFO_USB,
+ Mode::CustomShift(fs) => fs,
+ Mode::CW(_) => match self.sequence_state {
+ SequenceState::SwitchingCW | SequenceState::TxCW => 0,
+ _ => BFO_CW,
+ },
+ }
+ }
+ }
+
+ pub fn vhf_qrg(&self) -> u32 {
+ match self.vfo_sel {
+ VFOSelection::A => self.vfo_a,
+ VFOSelection::B => self.vfo_b,
+ }
+ }
+
+ pub fn if_qrg(&self) -> u32 {
+ self.vhf_qrg() - VHF_LO
+ }
+
+ pub fn vfo(&self) -> u32 {
+ let cw_offset = match self.sequence_state {
+ SequenceState::SwitchingCW | SequenceState::TxCW => 500,
+ _ => 0,
+ };
+
+ let vfo = (self.if_qrg() - self.bfo()) as i32 +
+ if self.sequence_state.apply_rit() { self.rit } else { 0 } +
+ cw_offset;
+ vfo as u32
+ }
+}