fw-rust: Make Si5351 useable
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
In order to make the Si5351 configurable add some needed assets, create the ability to print the frequency with selected digits and add a channel screen.
This commit is contained in:
parent
7f14974146
commit
c36581e703
5 changed files with 430 additions and 119 deletions
|
@ -1,10 +1,5 @@
|
|||
use super::{Event, Screens, Setup, Splash};
|
||||
use crate::{
|
||||
assets::{OFF, ON, PLL_A, PLL_B},
|
||||
lcd::Lcd,
|
||||
Input,
|
||||
};
|
||||
use si5351::PLL;
|
||||
use super::{Channel, Event, Screens, Setup};
|
||||
use crate::{lcd::Lcd, screen::ClockChannel, Input};
|
||||
|
||||
enum Selection {
|
||||
Ch1,
|
||||
|
@ -13,74 +8,35 @@ enum Selection {
|
|||
Setup,
|
||||
}
|
||||
|
||||
struct Channel {
|
||||
freq: u32,
|
||||
enabled: bool,
|
||||
pll: PLL,
|
||||
}
|
||||
|
||||
impl Channel {
|
||||
fn print(&self, lcd: &mut Lcd, page: u8) {
|
||||
lcd.print_freq(25, page, self.freq);
|
||||
lcd.print_icon(91, page, if self.enabled { &ON } else { &OFF });
|
||||
lcd.print_icon(
|
||||
94,
|
||||
page + 1,
|
||||
match self.pll {
|
||||
PLL::A => &PLL_A,
|
||||
PLL::B => &PLL_B,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Home {
|
||||
active: Selection,
|
||||
channels: [Channel; 3],
|
||||
}
|
||||
|
||||
impl Home {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
active: Selection::Ch1,
|
||||
channels: [
|
||||
Channel {
|
||||
freq: 0,
|
||||
enabled: false,
|
||||
pll: PLL::A,
|
||||
},
|
||||
Channel {
|
||||
freq: 0,
|
||||
enabled: false,
|
||||
pll: PLL::A,
|
||||
},
|
||||
Channel {
|
||||
freq: 0,
|
||||
enabled: false,
|
||||
pll: PLL::A,
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn input(&mut self, input: &Input) -> Event {
|
||||
pub fn input(&mut self, input: &Input, channels: [ClockChannel; 3]) -> Event {
|
||||
self.active = match self.active {
|
||||
Selection::Ch1 => match input {
|
||||
Input::Next => Selection::Ch2,
|
||||
Input::Previous => Selection::Setup,
|
||||
Input::Select => return Event::Screen(Screens::Splash(Splash)),
|
||||
Input::Select => return Event::Screen(Screens::Channel(Channel::new(channels[0]))),
|
||||
Input::Back => Selection::Ch1,
|
||||
},
|
||||
Selection::Ch2 => match input {
|
||||
Input::Next => Selection::Ch3,
|
||||
Input::Previous => Selection::Ch1,
|
||||
Input::Select => return Event::Screen(Screens::Splash(Splash)),
|
||||
Input::Select => return Event::Screen(Screens::Channel(Channel::new(channels[1]))),
|
||||
Input::Back => Selection::Ch2,
|
||||
},
|
||||
Selection::Ch3 => match input {
|
||||
Input::Next => Selection::Setup,
|
||||
Input::Previous => Selection::Ch2,
|
||||
Input::Select => return Event::Screen(Screens::Splash(Splash)),
|
||||
Input::Select => return Event::Screen(Screens::Channel(Channel::new(channels[2]))),
|
||||
Input::Back => Selection::Ch3,
|
||||
},
|
||||
Selection::Setup => match input {
|
||||
|
@ -94,42 +50,42 @@ impl Home {
|
|||
Event::None
|
||||
}
|
||||
|
||||
pub fn draw(&self, lcd: &mut Lcd) {
|
||||
pub fn draw(&self, lcd: &mut Lcd, channels: [ClockChannel; 3]) {
|
||||
match &self.active {
|
||||
Selection::Ch1 => {
|
||||
lcd.print_inverted(0, 0, "CH1");
|
||||
self.channels[0].print(lcd, 0);
|
||||
channels[0].print(lcd, 0);
|
||||
lcd.print(0, 2, "CH2");
|
||||
self.channels[1].print(lcd, 2);
|
||||
channels[1].print(lcd, 2);
|
||||
lcd.print(0, 4, "CH3");
|
||||
self.channels[2].print(lcd, 4);
|
||||
channels[2].print(lcd, 4);
|
||||
lcd.print(33, 6, "SETUP");
|
||||
}
|
||||
Selection::Ch2 => {
|
||||
lcd.print(0, 0, "CH1");
|
||||
self.channels[0].print(lcd, 0);
|
||||
channels[0].print(lcd, 0);
|
||||
lcd.print_inverted(0, 2, "CH2");
|
||||
self.channels[1].print(lcd, 2);
|
||||
channels[1].print(lcd, 2);
|
||||
lcd.print(0, 4, "CH3");
|
||||
self.channels[2].print(lcd, 4);
|
||||
channels[2].print(lcd, 4);
|
||||
lcd.print(33, 6, "SETUP");
|
||||
}
|
||||
Selection::Ch3 => {
|
||||
lcd.print(0, 0, "CH1");
|
||||
self.channels[0].print(lcd, 0);
|
||||
channels[0].print(lcd, 0);
|
||||
lcd.print(0, 2, "CH2");
|
||||
self.channels[1].print(lcd, 2);
|
||||
channels[1].print(lcd, 2);
|
||||
lcd.print_inverted(0, 4, "CH3");
|
||||
self.channels[2].print(lcd, 4);
|
||||
channels[2].print(lcd, 4);
|
||||
lcd.print(33, 6, "SETUP");
|
||||
}
|
||||
Selection::Setup => {
|
||||
lcd.print(0, 0, "CH1");
|
||||
self.channels[0].print(lcd, 0);
|
||||
channels[0].print(lcd, 0);
|
||||
lcd.print(0, 2, "CH2");
|
||||
self.channels[1].print(lcd, 2);
|
||||
channels[1].print(lcd, 2);
|
||||
lcd.print(0, 4, "CH3");
|
||||
self.channels[2].print(lcd, 4);
|
||||
channels[2].print(lcd, 4);
|
||||
lcd.print_inverted(33, 6, "SETUP");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue