Skip to content

Commit

Permalink
Log sensor self-identification
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsided committed Jul 4, 2024
1 parent ea82aea commit 2eaa744
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 36 additions & 1 deletion src/components/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::ops::Neg;
use num_traits::ConstZero;
use ratatui::prelude::*;
use serial_sensors_proto::versions::Version1DataFrame;
use serial_sensors_proto::SensorData;
use serial_sensors_proto::{IdentifierCode, SensorData, SensorId};

pub fn axis_to_span<'a, V>(value: V, highlight: bool) -> Span<'a>
where
Expand Down Expand Up @@ -49,6 +49,19 @@ where
}
}

fn sensor_id<'a>(id: &SensorId) -> Vec<Span<'a>> {
vec![
Span::styled(id.tag().to_string(), Style::default().yellow()),
" ".into(),
Span::styled(format!("{:02X}", id.id()), Style::default().dim()),
":".into(),
Span::styled(
format!("{:02X}", id.value_type() as u8),
Style::default().dim(),
),
]
}

pub fn frame_data_to_line(frame: &Version1DataFrame, line: &mut Vec<Span>) {
match frame.value {
SensorData::AccelerometerI16(vec) => {
Expand Down Expand Up @@ -93,6 +106,28 @@ pub fn frame_data_to_line(frame: &Version1DataFrame, line: &mut Vec<Span>) {

pub fn frame_data_to_line_raw(frame: &Version1DataFrame, line: &mut Vec<Span>) {
match frame.value {
SensorData::Identification(ref ident) => {
line.extend(vec![
Span::styled("ident:", Style::default().cyan()),
match ident.code {
IdentifierCode::Generic => "generic".into(),
IdentifierCode::Maker => "maker".into(),
IdentifierCode::Product => "prod".into(),
IdentifierCode::Revision => "rev".into(),
},
" ".into(),
]);

line.extend(sensor_id(&ident.target));

line.extend(vec![
" ".into(),
Span::styled(
String::from(ident.as_str().unwrap_or("(invalid)").trim_end()),
Style::default().dim(),
),
])
}
SensorData::AccelerometerI16(vec) => {
let (highlight_x, highlight_y, highlight_z) = highlight_axis_3(vec.x, vec.y, vec.z);

Expand Down
3 changes: 2 additions & 1 deletion src/data_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ impl InnerSensorDataBuffer {
let mut data = self.data.write().expect("lock failed");

let previous = self.sequence.swap(frame.sensor_sequence, Ordering::SeqCst);
if frame.sensor_sequence != previous + 1 {
// If the value didn't increase by one (sensor case) or remain identical (metadata case), count it as a strike.
if frame.sensor_sequence != previous + 1 && frame.sensor_sequence != previous {
self.num_skipped.fetch_add(1, Ordering::SeqCst);
}

Expand Down

0 comments on commit 2eaa744

Please sign in to comment.