Skip to content

Commit

Permalink
Merge pull request #37 from dbrgn/update-dev-dependencies
Browse files Browse the repository at this point in the history
Update dev dependencies, general maintenance
  • Loading branch information
dbrgn authored May 10, 2024
2 parents a883900 + 406c769 commit 3cdb49f
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 53 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ embedded-hal = "1.0"
[dev-dependencies]
embedded-hal-mock = { version = "0.10.0", features = ["eh1"], default-features = false }
linux-embedded-hal = "0.4"
termion = "1.5"
tui = "0.8"
termion = "4.0"
tui = "0.19"

[profile.release]
lto = true
16 changes: 11 additions & 5 deletions examples/linux-shtc1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@ fn main() {
println!();

println!("Soft reset...");
sht.reset(&mut delay).unwrap();
sht.reset(&mut delay).expect("Soft reset failed");
println!();

println!(
"Device identifier: 0x{:02x}",
sht.device_identifier().unwrap()
sht.device_identifier()
.expect("Failed to get device identifier")
);
println!(
"Raw ID register: 0b{:016b}",
sht.raw_id_register().unwrap()
sht.raw_id_register()
.expect("Failed to get raw ID register")
);

println!("\nNormal mode measurements:");
for _ in 0..3 {
let measurement = sht.measure(PowerMode::NormalMode, &mut delay).unwrap();
let measurement = sht
.measure(PowerMode::NormalMode, &mut delay)
.expect("Normal mode measurement failed");
println!(
" {:.2} °C | {:.2} %RH",
measurement.temperature.as_degrees_celsius(),
Expand All @@ -36,7 +40,9 @@ fn main() {

println!("\nLow power mode measurements:");
for _ in 0..3 {
let measurement = sht.measure(PowerMode::LowPower, &mut delay).unwrap();
let measurement = sht
.measure(PowerMode::LowPower, &mut delay)
.expect("Low power mode measurement failed");
println!(
" {:.2} °C | {:.2} %RH",
measurement.temperature.as_degrees_celsius(),
Expand Down
22 changes: 14 additions & 8 deletions examples/linux-shtc3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,24 @@ fn main() {
println!("Starting SHTC3 tests.");
println!("Waking up sensor.");
println!();
sht.wakeup(&mut delay).unwrap();
sht.wakeup(&mut delay).expect("Wakeup failed");

println!(
"Device identifier: 0x{:02x}",
sht.device_identifier().unwrap()
sht.device_identifier()
.expect("Failed to get device identifier")
);
println!(
"Raw ID register: 0b{:016b}",
sht.raw_id_register().unwrap()
sht.raw_id_register()
.expect("Failed to get raw ID register")
);

println!("\nNormal mode measurements:");
for _ in 0..3 {
let measurement = sht.measure(PowerMode::NormalMode, &mut delay).unwrap();
let measurement = sht
.measure(PowerMode::NormalMode, &mut delay)
.expect("Normal mode measurement failed");
println!(
" {:.2} °C | {:.2} %RH",
measurement.temperature.as_degrees_celsius(),
Expand All @@ -34,7 +38,9 @@ fn main() {

println!("\nLow power mode measurements:");
for _ in 0..3 {
let measurement = sht.measure(PowerMode::LowPower, &mut delay).unwrap();
let measurement = sht
.measure(PowerMode::LowPower, &mut delay)
.expect("Low power mode measurement failed");
println!(
" {:.2} °C | {:.2} %RH",
measurement.temperature.as_degrees_celsius(),
Expand All @@ -49,21 +55,21 @@ fn main() {
.unwrap();
println!("Success: {:.2} °C", temperature.as_degrees_celsius());
println!("-> Sleep");
sht.sleep().unwrap();
sht.sleep().expect("Sleep command failed");
print!("-> Measure: ");
let error = sht
.measure_temperature(PowerMode::NormalMode, &mut delay)
.unwrap_err();
println!("Error: {:?}", error);
println!("-> Wakeup");
sht.wakeup(&mut delay).unwrap();
sht.wakeup(&mut delay).expect("Wakeup command failed");
print!("-> Measure: ");
let temperature = sht
.measure_temperature(PowerMode::NormalMode, &mut delay)
.unwrap();
println!("Success: {:.2} °C", temperature.as_degrees_celsius());
println!("-> Soft reset");
sht.reset(&mut delay).unwrap();
sht.reset(&mut delay).expect("Reset command failed");
print!("-> Measure: ");
let temperature = sht
.measure_temperature(PowerMode::NormalMode, &mut delay)
Expand Down
86 changes: 48 additions & 38 deletions examples/monitor-shtc3.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
//! Monitor an SHTC3 sensor on Linux in the terminal.
use std::collections::VecDeque;
use std::io::{self, Stdout};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{mpsc::channel, Arc};
use std::thread;
use std::time::Duration;
use std::{
collections::VecDeque,
io::{self, Stdout},
sync::{
atomic::{AtomicBool, Ordering},
mpsc::channel,
Arc,
},
thread,
time::Duration,
};

use linux_embedded_hal::{Delay, I2cdev};
use shtcx::{self, PowerMode};
use termion::event::Key;
use termion::input::TermRead;
use termion::raw::{IntoRawMode, RawTerminal};
use tui::backend::{Backend, TermionBackend};
use tui::layout::{Constraint, Direction, Layout, Rect};
use tui::style::{Color, Style};
use tui::widgets::{Axis, Block, Borders, Chart, Dataset, Marker, Widget};
use tui::{Frame, Terminal};
use termion::{
event::Key,
input::TermRead,
raw::{IntoRawMode, RawTerminal},
};
use tui::{
backend::{Backend, CrosstermBackend},
layout::{Constraint, Direction, Layout, Rect},
style::{Color, Style},
symbols::Marker,
text::Span,
widgets::{Axis, Block, Borders, Chart, Dataset},
Frame, Terminal,
};

const SENSOR_REFRESH_DELAY: Duration = Duration::from_millis(50);
const UI_REFRESH_DELAY: Duration = Duration::from_millis(25);
Expand Down Expand Up @@ -61,7 +72,7 @@ fn main() -> Result<(), io::Error> {

// Initialize terminal app
let stdout = io::stdout().into_raw_mode()?;
let backend = TermionBackend::new(stdout);
let backend = CrosstermBackend::new(stdout);
let mut terminal = Terminal::new(backend)?;

// Prepare terminal
Expand Down Expand Up @@ -131,39 +142,38 @@ fn show_chart<B: Backend>(
frame: &mut Frame<B>,
area: Rect,
) {
Chart::default()
let dataset = vec![
Dataset::default()
.name("Low power mode")
.marker(Marker::Braille)
.style(Style::default().fg(color_lowpwr))
.data(&data_lowpwr),
Dataset::default()
.name("Normal mode")
.marker(Marker::Dot)
.style(Style::default().fg(color_normal))
.data(data_normal),
];
let axis_style = Style::default().fg(Color::Red);
let chart = Chart::new(dataset)
.block(Block::default().title(title).borders(Borders::ALL))
.x_axis(
Axis::<&str>::default()
.title("X Axis")
.title_style(Style::default().fg(Color::Red))
Axis::default()
.title(Span::styled("X Axis", axis_style))
.style(Style::default().fg(Color::White))
.bounds([0.0, DATA_CAPACITY as f64]),
)
.y_axis(
Axis::<&str>::default()
.title("Y Axis")
.title_style(Style::default().fg(Color::Red))
Axis::default()
.title(Span::styled("Y Axis", axis_style))
.style(Style::default().fg(Color::White))
.bounds([0.0, max.0])
.labels(&["0", max.1]),
)
.datasets(&[
Dataset::default()
.name("Low power mode")
.marker(Marker::Braille)
.style(Style::default().fg(color_lowpwr))
.data(&data_lowpwr),
Dataset::default()
.name("Normal mode")
.marker(Marker::Dot)
.style(Style::default().fg(color_normal))
.data(data_normal),
])
.render(frame, area);
.labels(vec![Span::from("0"), Span::from(max.1)]),
);
frame.render_widget(chart, area);
}

fn render(terminal: &mut Terminal<TermionBackend<RawTerminal<Stdout>>>, data: &Data) {
fn render(terminal: &mut Terminal<CrosstermBackend<RawTerminal<Stdout>>>, data: &Data) {
terminal
.draw(|mut f| {
let chunks = Layout::default()
Expand Down

0 comments on commit 3cdb49f

Please sign in to comment.