HUGE FIX for frequency setting
This commit is contained in:
23
src/main.rs
23
src/main.rs
@@ -128,8 +128,7 @@ fn main() -> ! {
|
||||
const MAX_TUNE: u16 = 350u16;
|
||||
const MIN_TUNE: u16 = 4u16;
|
||||
|
||||
pwm0.set_top(current_tune);
|
||||
pwm0.channel_a.set_duty(current_tune / 2);
|
||||
set_tune(current_tune, pwm0);
|
||||
|
||||
// Create the I²C drive
|
||||
let mut i2c = hal::I2C::i2c0(
|
||||
@@ -156,7 +155,7 @@ fn main() -> ! {
|
||||
gfx_buf.clear();
|
||||
gfx_buf.draw_string(20, 14, "Hello Radio!");
|
||||
|
||||
let tuned_freq = 272_000u32 / (current_tune as u32);
|
||||
let tuned_freq = 300_000 / (current_tune as u32);
|
||||
let mut tune_str_buf = [0u8; 5];
|
||||
let len = u32_into_str(tuned_freq, &mut tune_str_buf);
|
||||
let tune_str = str::from_utf8(&tune_str_buf[tune_str_buf.len() - len..]).unwrap();
|
||||
@@ -201,24 +200,30 @@ fn main() -> ! {
|
||||
}
|
||||
|
||||
if tune_up_input.is_low().unwrap() {
|
||||
info!("Tune UP");
|
||||
info!("Tune DOWN");
|
||||
last_input = tick;
|
||||
current_tune = MAX_TUNE.min(current_tune + 2);
|
||||
pwm0.set_top(current_tune);
|
||||
pwm0.channel_a.set_duty(current_tune / 2);
|
||||
set_tune(current_tune, pwm0);
|
||||
continue;
|
||||
}
|
||||
|
||||
if tune_dn_input.is_low().unwrap() {
|
||||
info!("Tune DOWN");
|
||||
info!("Tune UP");
|
||||
last_input = tick;
|
||||
current_tune = MIN_TUNE.max(current_tune - 2);
|
||||
pwm0.set_top(current_tune);
|
||||
pwm0.channel_a.set_duty(current_tune / 2);
|
||||
set_tune(current_tune, pwm0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn set_tune(
|
||||
tune: u16,
|
||||
pwm: &mut rp2040_hal::pwm::Slice<rp2040_hal::pwm::Pwm0, rp2040_hal::pwm::FreeRunning>,
|
||||
) {
|
||||
pwm.set_top(tune - 1);
|
||||
pwm.channel_a.set_duty(tune / 2);
|
||||
}
|
||||
|
||||
// returns the length of the final str removing leading zeroes
|
||||
fn u32_into_str(mut value: u32, str_buf: &mut [u8]) -> usize {
|
||||
let mut len = str_buf.len();
|
||||
|
||||
Reference in New Issue
Block a user