Skip to content
Snippets Groups Projects
Commit 2738a981 authored by Stephen D's avatar Stephen D
Browse files

propagate changed settings to radio

parent 6bfece3e
No related branches found
No related tags found
No related merge requests found
Pipeline #6663 passed
......@@ -32,7 +32,7 @@ use crate::{
Element,
},
keyboard::KeyCode,
spi_devices::{RxPacket, TxCommand},
spi_devices::{NewSettings, RxPacket, TxCommand},
storage::{
ContactIter, MessageDirection, Storage, UnsavedMessage, MAX_CONTACTS,
MAX_CONTACT_NAME_LENGTH,
......@@ -270,6 +270,7 @@ pub struct Controller {
ping: bool,
// If true, unhandled new unread message (i.e. we need to vibrate and stuff)
new_unread: bool,
settings_changed: bool,
// radio status
pub radio_error: bool,
......@@ -302,6 +303,7 @@ impl Controller {
beacon: Beacon::new(),
ping: false,
new_unread: false,
settings_changed: false,
radio_error: false,
radio_restarts: 0,
......@@ -460,6 +462,25 @@ impl Controller {
self.gps_data = data;
}
pub fn new_settings(&mut self) -> Option<NewSettings> {
let ret = if self.settings_changed {
let settings = self.storage.settings();
Some(NewSettings {
callsign: settings.callsign().clone(),
ssid: settings.ssid(),
icon: settings.icon(),
beacon_message: settings.beacon_message.clone(),
})
} else {
None
};
self.settings_changed = false;
ret
}
fn refresh_rx_led(&mut self) {
self.green_led =
Some(monotonics::now() + Duration::<u64, 1, 1000000>::millis(RX_LIGHT_TIME_MS));
......@@ -758,6 +779,8 @@ impl Controller {
if let Some(id) = self.cur_view.to_main_menu_id() {
self.cur_view = View::new_main_menu(id);
}
self.settings_changed = true;
}
}
......
......@@ -2,12 +2,13 @@ use core::mem;
use crate::{buffered_display::BufferedDisplay, controller::Controller};
use super::{RxPacket, SharedDisplay, SharedSpiDeviceData, TxCommand};
use super::{NewSettings, RxPacket, SharedDisplay, SharedSpiDeviceData, TxCommand};
pub struct SpiDeviceCommunicator {
display: Option<BufferedDisplay>,
tx_command: Option<TxCommand>,
packet: Option<RxPacket>,
new_settings: Option<NewSettings>,
radio_error: bool,
radio_restarts: u32,
......@@ -20,6 +21,7 @@ impl SpiDeviceCommunicator {
display: None,
tx_command: None,
packet: None,
new_settings: None,
radio_error: false,
radio_restarts: 0,
......@@ -60,6 +62,10 @@ impl SpiDeviceCommunicator {
controller.handle_packet(pkt);
}
if let Some(ns) = controller.new_settings() {
self.new_settings = Some(ns);
}
if self.tx_command.is_none() {
self.tx_command = controller.next_tx_command();
}
......@@ -73,5 +79,7 @@ impl SpiDeviceCommunicator {
if data.tx_command.is_none() {
data.tx_command = self.tx_command.take();
}
data.new_settings = self.new_settings.clone();
}
}
......@@ -150,7 +150,6 @@ impl SpiDeviceController {
ack: None,
rx_packets,
// FIXME need a mechanism to update these
callsign: settings.callsign().clone(),
ssid: settings.ssid(),
icon: settings.icon(),
......@@ -173,6 +172,13 @@ impl SpiDeviceController {
if self.tx_command.is_none() {
self.tx_command = data.tx_command.take();
}
if let Some(ns) = data.new_settings.take() {
self.callsign = ns.callsign;
self.ssid = ns.ssid;
self.icon = ns.icon;
self.beacon_message = ns.beacon_message;
}
}
pub fn tick(&mut self) {
......
......@@ -8,7 +8,9 @@ use crate::{
buffered_display::BufferedDisplay,
gps::GpsPos,
radio::MAX_SEMI_ENCODED_PACKET_LEN,
storage::{Message, MAX_CONTACT_CALLSIGN_LENGTH, MAX_MESSAGE_BODY_LENGTH},
storage::{
Message, MAX_BEACON_MESSAGE_LEN, MAX_CONTACT_CALLSIGN_LENGTH, MAX_MESSAGE_BODY_LENGTH,
},
};
pub mod communicator;
......@@ -110,10 +112,19 @@ impl RxPacket {
}
}
#[derive(Clone)]
pub struct NewSettings {
pub callsign: String<MAX_CONTACT_CALLSIGN_LENGTH>,
pub ssid: u8,
pub icon: u16,
pub beacon_message: String<MAX_BEACON_MESSAGE_LEN>,
}
pub struct SharedSpiDeviceData {
display: SharedDisplay,
tx_command: Option<TxCommand>,
packet: Option<RxPacket>,
new_settings: Option<NewSettings>,
// radio status
radio_error: bool,
......@@ -130,6 +141,8 @@ impl Default for SharedSpiDeviceData {
radio_error: false,
radio_restarts: 0,
dropped_packets: 0,
new_settings: None,
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment