aboutsummaryrefslogtreecommitdiffstats
path: root/sw/eval-clock-cw-tx/src/state.rs
blob: 44c64d2b66610d0f290f451eb4e9afc483b90e30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const INITIAL_VFO : u32 = 10_100_000;

// Defines which parameter is changed by the encoder
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum UISelection {
    VFO,
    Mode,
}

#[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 {
    CW(CWMode),
    FeldHell,
}

#[derive(PartialEq, Eq, Clone, Copy)]
pub enum SequenceMode {
    CW,
    FeldHell,
}

#[derive(Clone, PartialEq, Eq)]
pub enum SequenceState {
    Rx,
    Switching(SequenceMode),
    Tx(SequenceMode),
}

#[derive(Clone)]
pub struct State {
    pub ui_sel : UISelection,
    pub vfo_a : u32,
    pub vfo_b : u32,
    pub vfo_sel : VFOSelection,
    pub mode : Mode,
    pub sequence_state : SequenceState,
    pub update_disp_counter : u8,
    pub cw_wpm : u32,
}

impl State {
    pub fn new() -> Self {
        State {
            ui_sel : UISelection::VFO,
            mode : Mode::CW(CWMode::StraightKey),
            vfo_sel : VFOSelection::A,
            vfo_a : INITIAL_VFO,
            vfo_b : INITIAL_VFO,
            sequence_state : SequenceState::Rx,
            update_disp_counter : 0,
            cw_wpm : 14,
        }
    }

    pub fn set_vfo(&mut self, freq : u32) {
        match self.vfo_sel {
            VFOSelection::A => self.vfo_a = freq,
            VFOSelection::B => self.vfo_b = freq,
        }
    }

    pub fn vfo_display(&self) -> u32 {
        match self.vfo_sel {
            VFOSelection::A => self.vfo_a,
            VFOSelection::B => self.vfo_b,
        }
    }

    pub fn vfo_siclock(&self) -> u32 {
        match self.sequence_state {
            SequenceState::Rx => 0,
            _ => match self.vfo_sel {
                VFOSelection::A => self.vfo_a,
                VFOSelection::B => self.vfo_b,
            }
        }
    }

    pub fn allow_feldhell_keying(&self) -> bool {
        self.sequence_state == SequenceState::Tx(SequenceMode::FeldHell)
    }
}