Skip to content

Commit

Permalink
Update README.md picture
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsided committed Jul 5, 2024
1 parent 87d3753 commit 94eca47
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
Binary file modified readme/picture.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion src/components/sensors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,18 @@ impl Component for Sensors {
"".into()
};

let name = self.receiver.get_sensor_name(&id);
let name = if !name.is_empty() {
Span::styled(name, Style::default().white().underlined())
} else {
"unknown".into()
};

let mut lines = vec![
Span::styled(format!("{no}"), Style::default()),
": ".into(),
Span::styled(id.tag().to_string(), Style::default().yellow()),
name,
Span::styled(format!(" {}", id.tag()), Style::default().yellow()),
":".into(),
Span::styled(frame.sensor_sequence.to_string(), Style::default().dim()),
skipped,
Expand Down
56 changes: 39 additions & 17 deletions src/data_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::time::Duration;

use serial_sensors_proto::types::LinearRangeInfo;
use serial_sensors_proto::versions::Version1DataFrame;
use serial_sensors_proto::{DataFrame, SensorData, SensorId};
use serial_sensors_proto::{DataFrame, IdentifierCode, SensorData, SensorId};

use crate::fps_counter::FpsCounter;

Expand All @@ -26,6 +26,8 @@ struct InnerSensorDataBuffer {
sequence: AtomicU32,
num_skipped: AtomicU32,
calibration: Option<LinearRangeInfo>,
maker: String,
product: String,
}

impl Default for SensorDataBuffer {
Expand All @@ -46,22 +48,6 @@ impl InnerSensorDataBuffer {
}
}

impl Default for InnerSensorDataBuffer {
fn default() -> Self {
let capacity = 100;
Self {
sensor_specific: true,
capacity,
data: VecDeque::with_capacity(capacity),
len: AtomicUsize::new(0),
fps: FpsCounter::default(),
sequence: AtomicU32::new(0),
num_skipped: AtomicU32::new(0),
calibration: None,
}
}
}

impl SensorDataBuffer {
#[allow(dead_code)]
pub fn len(&self) -> usize {
Expand Down Expand Up @@ -136,6 +122,13 @@ impl SensorDataBuffer {
map.get(id).map(|entry| entry.skipped()).unwrap_or(0)
}

pub fn get_sensor_name(&self, id: &SensorId) -> String {
let map = self.by_sensor.read().expect("failed to lock");
map.get(id)
.map(|entry| entry.product.clone())
.unwrap_or_default()
}

pub fn transform_values(&self, id: &SensorId, values: &mut [f32]) -> bool {
let map = self.by_sensor.read().expect("failed to lock");
map.get(id)
Expand All @@ -150,6 +143,24 @@ impl SensorDataBuffer {
}
}

impl Default for InnerSensorDataBuffer {
fn default() -> Self {
let capacity = 100;
Self {
sensor_specific: true,
maker: String::new(),
product: String::new(),
capacity,
data: VecDeque::with_capacity(capacity),
len: AtomicUsize::new(0),
fps: FpsCounter::default(),
sequence: AtomicU32::new(0),
num_skipped: AtomicU32::new(0),
calibration: None,
}
}
}

impl InnerSensorDataBuffer {
#[allow(dead_code)]
pub fn len(&self) -> usize {
Expand All @@ -166,6 +177,17 @@ impl InnerSensorDataBuffer {
if self.sensor_specific && frame.is_meta() {
if let SensorData::LinearRanges(calibration) = frame.value {
self.calibration = Some(calibration);
} else if let SensorData::Identification(ident) = frame.value {
match ident.code {
IdentifierCode::Generic => {}
IdentifierCode::Maker => {
self.maker = String::from(ident.as_str().unwrap_or("").trim())
}
IdentifierCode::Product => {
self.product = String::from(ident.as_str().unwrap_or("").trim())
}
IdentifierCode::Revision => {}
}
}

return;
Expand Down

0 comments on commit 94eca47

Please sign in to comment.