Skip to content

Commit

Permalink
Add buzzer to GCS implementation, speed up init
Browse files Browse the repository at this point in the history
  • Loading branch information
KoffeinFlummi committed Mar 17, 2024
1 parent d442f64 commit 51e5486
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/gcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use embassy_time::{Ticker, Duration};

use defmt::*;

//use crate::buzzer::*;
use crate::buzzer::Buzzer as BuzzerDriver;
use crate::lora::*;
use crate::settings::*;
use crate::telemetry::*;
Expand All @@ -24,6 +24,8 @@ use crate::usb::*;
type RadioHandle = Radio<SpiDevice<'static, CriticalSectionRawMutex, Spi<'static, SPI1, DMA2_CH3, DMA2_CH2>, Output<'static, PA1>>, Input<'static, PC0>,Input<'static, PC1>>;

type LEDs = (Output<'static, PC13>, Output<'static, PC14>, Output<'static, PC15>);
// TODO
type Buzzer = BuzzerDriver<TIM3>;

const MAIN_LOOP_FREQUENCY: Hertz = Hertz::hz(1000);

Expand All @@ -32,6 +34,7 @@ pub struct GroundControlStation {
usb: UsbHandle,
radio: RadioHandle,
leds: LEDs,
buzzer: Buzzer,
}

// TODO: move to main?
Expand All @@ -50,12 +53,14 @@ impl GroundControlStation {
usb: UsbHandle,
radio: RadioHandle,
leds: LEDs,
buzzer: Buzzer,
) -> Self {
Self {
time: core::num::Wrapping(0),
usb,
radio,
leds,
buzzer,
}
}

Expand All @@ -81,7 +86,7 @@ impl GroundControlStation {
self.leds.0.set_level((!(self.radio.transmit_power >= TransmitPower::P20dBm)).into());
self.leds.1.set_level((!rssi_led).into());
self.leds.2.set_level((!true).into());
//self.buzzer.tick(self.time);
self.buzzer.tick(self.time.0);

if let Some(msg) = uplink_msg {
self.radio.queue_uplink_message(msg);
Expand Down
6 changes: 3 additions & 3 deletions src/lora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ impl<SPI: SpiDevice<u8>, IRQ: InputPin, BUSY: InputPin> Radio<SPI, IRQ, BUSY> {

#[cfg(feature = "gcs")]
pub async fn tick(&mut self, time: u32) -> Option<DownlinkMessage> {
if self.sequence.is_none() || time < 3000 {
if self.sequence.is_none() {
return None;
}

Expand All @@ -331,8 +331,8 @@ impl<SPI: SpiDevice<u8>, IRQ: InputPin, BUSY: InputPin> Radio<SPI, IRQ, BUSY> {
let fc_time = (self.time as i64).wrapping_add(self.fc_time_offset as i64) as u32;

// When not in contact with the FC we do a slow sweep across channels.
if !in_contact && self.time % 5000 == 0 {
let i = (self.time as usize / 5000) % CHANNELS.len();
if !in_contact && self.time % 1000 == 0 {
let i = (self.time as usize / 1000) % CHANNELS.len();
info!("Sweeping, switching to {}MHz.", (CHANNELS[i] as f32) / 1_000_000.0);
if let Err(e) = self.trx.set_frequency(CHANNELS[i]).await {
error!("Failed to switch frequencies: {:?}", Debug2Format(&e));
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ async fn main(_low_priority_spawner: Spawner) {
);

#[cfg(feature="gcs")]
let gcs = GroundControlStation::init(usb, radio, leds);
let gcs = GroundControlStation::init(usb, radio, leds, buzzer);

// Start high priority executor
interrupt::I2C3_EV.set_priority(Priority::P6);
Expand Down

0 comments on commit 51e5486

Please sign in to comment.