Skip to content

Commit

Permalink
Add more variables
Browse files Browse the repository at this point in the history
Signed-off-by: Valerian Saliou <[email protected]>
  • Loading branch information
valeriansaliou committed Nov 3, 2020
1 parent b972a42 commit 3bec332
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 19 deletions.
18 changes: 18 additions & 0 deletions src/config/context.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// MakAir Control UI
//
// Copyright: 2020, Makers For Life
// License: Public Domain License

use std::time::Instant;

pub struct ConfigContext {
pub start_time: Instant,
}

impl ConfigContext {
pub fn make() -> Self {
ConfigContext {
start_time: Instant::now(),
}
}
}
1 change: 1 addition & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
// License: Public Domain License

pub mod arguments;
pub mod context;
pub mod environment;
pub mod logger;
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use crate::chip::Chip;
use crate::lora::controller::LoraController;

use config::arguments::ConfigArguments;
use config::context::ConfigContext;
use config::logger::ConfigLogger;
use display::window::DisplayWindowBuilder;
use locale::accessor::LocaleAccessor;
Expand All @@ -56,13 +57,18 @@ pub struct EmbeddedLocales;

lazy_static! {
static ref APP_ARGS: ConfigArguments = make_app_args();
static ref APP_CONTEXT: ConfigContext = make_app_context();
static ref APP_I18N: LocaleAccessor = make_app_i18n();
}

fn make_app_args() -> ConfigArguments {
ConfigArguments::read()
}

fn make_app_context() -> ConfigContext {
ConfigContext::make()
}

fn make_app_i18n() -> LocaleAccessor {
LocaleLoader::new(&APP_ARGS.translation).into_accessor()
}
Expand Down
8 changes: 8 additions & 0 deletions src/utilities/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ pub fn parse_version_number(version: &str) -> &str {
// Fallback on the identity function (return version as-is)
version
}

pub fn parse_non_empty_number_to_string(value: usize) -> String {
if value == 0 {
"".to_string()
} else {
value.to_string()
}
}
38 changes: 19 additions & 19 deletions src/widget/advanced_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ use telemetry::structures::MachineStateSnapshot;

use crate::config::environment::*;
use crate::display::widget::ControlWidget;
use crate::utilities::parse::parse_non_empty_number_to_string;
use crate::APP_CONTEXT;

const CONTROL_UI_VERSION: &'static str = env!("CARGO_PKG_VERSION");
const CONTROL_UI_VERSION: &str = env!("CARGO_PKG_VERSION");

pub struct Config<'a> {
pub width: f64,
Expand Down Expand Up @@ -50,31 +52,29 @@ pub fn render<'a>(master: &mut ControlWidget<'a>, config: Config) -> f64 {
let line_data: [(&str, &str); ADVANCED_SETTINGS_LINES_COUNT] = [
(
"telemetry-version",
&(if config.snapshot.telemetry_version == 0 {
"".to_string()
} else {
config.snapshot.telemetry_version.to_string()
}),
&parse_non_empty_number_to_string(config.snapshot.telemetry_version as usize),
),
("control-ui-version", CONTROL_UI_VERSION),
("control-ui-uptime-seconds", ""), // TODO
(
"control-ui-uptime-seconds",
&parse_non_empty_number_to_string(APP_CONTEXT.start_time.elapsed().as_secs() as usize),
),
("firmware-version", &config.snapshot.version),
("firmware-target", ""), // TODO
("firmware-target", ""), // TODO: BootMessage::mode
("runtime-device-id", &config.snapshot.device_id.to_string()),
(
"runtime-uptime-seconds",
&(if config.snapshot.systick == 0 {
"".to_string()
} else {
(config.snapshot.systick / 1000000).to_string()
}),
&parse_non_empty_number_to_string(config.snapshot.systick as usize / 1000000),
),
(
"runtime-cycles",
&parse_non_empty_number_to_string(config.snapshot.cycle as usize),
),
("runtime-cycles", &config.snapshot.cycle.to_string()),
("runtime-phase", ""), // TODO
("pinch-angle-inhale", ""), // TODO
("pinch-angle-exhale", ""), // TODO
("blower-rpm", ""), // TODO
("battery-voltage", ""), // TODO
("runtime-phase", ""), // TODO: DataSnapshot::subphase
("pinch-angle-inhale", ""), // TODO: DataSnapshot::blower_valve_position
("pinch-angle-exhale", ""), // TODO: DataSnapshot::patient_valve_position
("blower-rpm", ""), // TODO: DataSnapshot::blower_rpm
("battery-voltage", ""), // TODO: DataSnapshot::battery_level
];

// Append lines
Expand Down

0 comments on commit 3bec332

Please sign in to comment.