Skip to content

Commit

Permalink
Disable color change for title and apply fmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
tkornack committed Feb 17, 2025
1 parent e2131eb commit 2316be6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 deletions.
44 changes: 24 additions & 20 deletions twinleaf-tools/src/bin/tio-monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use twinleaf::{
};

use getopts::Options;
use std::collections::HashMap;
use std::{env, io::stdout, time::Duration, io::Read, fs};
use serde::{ser::StdError, Deserialize};
use std::collections::HashMap;
use std::{env, fs, io::stdout, io::Read, time::Duration};

use futures::{future::FutureExt, select, StreamExt};
use futures_timer::Delay;
Expand All @@ -16,8 +16,8 @@ use crossterm::ExecutableCommand;
use crossterm::{
cursor::*,
event::{Event, EventStream, KeyCode, KeyModifiers},
style::*,
terminal::*,
style::*
};

fn tio_opts() -> Options {
Expand Down Expand Up @@ -73,7 +73,7 @@ impl Threshold {
}
}

fn read_file(file_path: String) -> std::result::Result<String, Box<dyn StdError >>{
fn read_file(file_path: String) -> std::result::Result<String, Box<dyn StdError>> {
//read file contents to string
let mut file = fs::File::open(&file_path)?;
let mut file_content = String::new();
Expand All @@ -88,19 +88,18 @@ fn test_range(column: String, value: f32, file_path: Option<String>) -> u32 {

match read_file(path) {
Ok(result) => {
let read_yaml: HashMap<String, Threshold> = serde_yaml::from_str(&result).expect("FAILED TO READ YAML");
let read_yaml: HashMap<String, Threshold> =
serde_yaml::from_str(&result).expect("FAILED TO READ YAML");

if let Some(range) = read_yaml.get(&clean_name) {
if range.no_value(){
return 1;

if range.no_value() {
return 1;
} else if range.within_range(value) {
return 2;

} else{
} else {
return 3;
}
}
}
}
Err(_err) => {
return 1;
Expand All @@ -109,13 +108,19 @@ fn test_range(column: String, value: f32, file_path: Option<String>) -> u32 {
1
}

fn set_text_color(match_color: u32){
fn set_text_color(match_color: u32) {
let mut stdout = stdout();

match match_color {
1 => {_ = stdout.execute(SetForegroundColor(Color::Reset));}
2 => {_ = stdout.execute(SetForegroundColor(Color::Green));}
3 => {_ = stdout.execute(SetForegroundColor(Color::Red));}
1 => {
_ = stdout.execute(SetForegroundColor(Color::Reset));
}
2 => {
_ = stdout.execute(SetForegroundColor(Color::Green));
}
3 => {
_ = stdout.execute(SetForegroundColor(Color::Red));
}
_ => {}
};
}
Expand Down Expand Up @@ -151,14 +156,13 @@ async fn run_monitor() {
"{} Serial: {}",
sample.device.name, sample.device.serial_number
);
_ = stdout.execute(SetForegroundColor(Color::White));
_ = stdout.execute(MoveToRow(0));
println!("\r{}", name);

select! {
_= delay => {
for col in &sample.columns{
let color_pair = test_range(col.desc.name.clone(),
let color_pair = test_range(col.desc.name.clone(),
match col.value {
ColumnData::Int(x) => x as f32,
ColumnData::UInt(x) => x as f32,
Expand Down Expand Up @@ -226,9 +230,9 @@ async fn run_monitor() {

fn main() -> std::io::Result<()> {
let mut args: Vec<String> = std::env::args().collect();
if args.len() < 2{
if args.len() < 2 {
args.push("run".to_string())
}
}
match args[1].as_str() {
"run" => {
let mut stdout = stdout();
Expand All @@ -247,7 +251,7 @@ fn main() -> std::io::Result<()> {
_ => {
println!("Usage:");
println!(" tio-monitor help");
println!(" tio-monitor run [yaml_file_path]");
println!(" tio-monitor run [yaml_file_path]");
}
}

Expand Down
23 changes: 14 additions & 9 deletions twinleaf-tools/src/bin/tio-tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,33 +583,38 @@ fn log_csv(args: &[String]) -> std::io::Result<()> {
Ok(())
}

fn read_capture(args: &[String]){
fn read_capture(args: &[String]) {
let prefix = &args[0];
let data_type = &args[1];
let trigger = format!("{}.trigger", prefix.clone());
let block = format!("{}.block", prefix.clone());
let size = format!{"{}.size", prefix.clone()};
let blocksize = format!{"{}.blocksize", prefix.clone()};
let size = format! {"{}.size", prefix.clone()};
let blocksize = format! {"{}.blocksize", prefix.clone()};

let _ = rpc(&[trigger]);

let mut num_blocks: f32 = 0.0;
if let Ok(sizenum) = rpc(&[size]) {
let size32: f32 = sizenum.parse().expect("err");
if let Ok(blocknum) = rpc(&[blocksize]){
if let Ok(blocknum) = rpc(&[blocksize]) {
let blocksize32: f32 = blocknum.parse().expect("err");
let block_len = (size32/blocksize32).floor();
num_blocks = block_len;
let block_len = (size32 / blocksize32).floor();
num_blocks = block_len;
}
}
for i in 0..(num_blocks as i32 - 1){
let mut command = vec!["rpc".to_string(), "-t".to_string(), "-T".to_string(), "string".to_string()];
for i in 0..(num_blocks as i32 - 1) {
let mut command = vec![
"rpc".to_string(),
"-t".to_string(),
"-T".to_string(),
"string".to_string(),
];
command.insert(1, block.clone());
command.insert(2, i.to_string());
command.insert(4, data_type.clone());

_ = rpc(&command[1..]);
}
}
}

fn firmware_upgrade(args: &[String]) {
Expand Down

0 comments on commit 2316be6

Please sign in to comment.