Merge branch 'master' into feature/livestream

This commit is contained in:
Ryan Summers 2021-05-26 16:43:21 +02:00
commit 24dd749da9
3 changed files with 24 additions and 9 deletions

View File

@ -14,7 +14,7 @@ use hardware::{
};
use net::{
BlockGenerator, NetworkUsers, Telemetry, TelemetryBuffer, UpdateState,
BlockGenerator, NetworkUsers, Telemetry, TelemetryBuffer, NetworkState,
};
const SCALE: f32 = i16::MAX as _;
@ -192,8 +192,11 @@ const APP: () = {
fn idle(mut c: idle::Context) -> ! {
loop {
match c.resources.network.lock(|net| net.update()) {
UpdateState::Updated => c.spawn.settings_update().unwrap(),
UpdateState::NoChange => cortex_m::asm::wfi(),
NetworkState::SettingsChanged => {
c.spawn.settings_update().unwrap()
}
NetworkState::Updated => {}
NetworkState::NoChange => cortex_m::asm::wfi(),
}
}
}

View File

@ -17,7 +17,7 @@ use stabilizer::hardware::{
};
use miniconf::Miniconf;
use net::{NetworkUsers, Telemetry, TelemetryBuffer, UpdateState};
use net::{NetworkState, NetworkUsers, Telemetry, TelemetryBuffer};
// A constant sinusoid to send on the DAC output.
// Full-scale gives a +/- 10.24V amplitude waveform. Scale it down to give +/- 1V.
@ -248,8 +248,11 @@ const APP: () = {
fn idle(mut c: idle::Context) -> ! {
loop {
match c.resources.network.lock(|net| net.update()) {
UpdateState::Updated => c.spawn.settings_update().unwrap(),
UpdateState::NoChange => cortex_m::asm::wfi(),
NetworkState::SettingsChanged => {
c.spawn.settings_update().unwrap()
}
NetworkState::Updated => {}
NetworkState::NoChange => cortex_m::asm::wfi(),
}
}
}

View File

@ -38,6 +38,12 @@ pub enum UpdateState {
Updated,
}
#[derive(Copy, Clone, PartialEq)]
pub enum NetworkState {
SettingsChanged,
Updated,
NoChange,
}
/// A structure of Stabilizer's default network users.
pub struct NetworkUsers<S: Default + Clone + Miniconf, T: Serialize> {
pub miniconf: MiniconfClient<S>,
@ -136,9 +142,12 @@ where
///
/// # Returns
/// An indication if any of the network users indicated a state change.
pub fn update(&mut self) -> UpdateState {
pub fn update(&mut self) -> NetworkState {
// Poll for incoming data.
let poll_result = self.processor.update();
let poll_result = match self.processor.update() {
UpdateState::NoChange => NetworkState::NoChange,
UpdateState::Updated => NetworkState::Updated,
};
// Update the MQTT clients.
self.telemetry.update();
@ -147,7 +156,7 @@ where
self.update_stream();
match self.miniconf.update() {
UpdateState::Updated => UpdateState::Updated,
UpdateState::Updated => NetworkState::SettingsChanged,
UpdateState::NoChange => poll_result,
}
}