fleascope_rs/
lib.rs

1//! # FleaScope RS
2//!
3//! A Rust library for configuring triggers and communicating with FleaScope oscilloscope devices.
4//!
5//! This library provides types and builders for creating digital and analog triggers
6//! that can be used to control data capture timing in FleaScope oscilloscope devices,
7//! as well as a serial terminal interface for communication and complete device control.
8//!
9//! ## Features
10//!
11//! - **Cross-platform device discovery**: Uses `serialport` for finding FleaScope devices
12//! - **Trigger configuration**: Digital and analog triggers with builder patterns
13//! - **Data acquisition**: Raw oscilloscope data reading with automatic time indexing
14//! - **Calibration management**: Read/write probe calibrations from/to device flash
15//! - **DataFrame output**: Uses `polars` for efficient data handling instead of pandas
16//! - **Type safety**: Strong typing and error handling throughout
17//!
18//! ## Examples
19//!
20//! ### Device Connection and Basic Usage
21//!
22//! ```rust,no_run
23//! use fleascope_rs::{FleaScope, ProbeType, Waveform};
24//! use std::time::Duration;
25//!
26//! // Connect to any available FleaScope device
27//! let mut scope = FleaScope::connect(None, None, true)?;
28//!
29//! // Set up signal generator
30//! scope.set_waveform(Waveform::Sine, 1000)?; // 1kHz sine wave
31//!
32//! // Read data using the 1x probe with default auto trigger
33//! let data = scope.read(ProbeType::X1, Duration::from_millis(10), None, None)?;
34//! println!("Captured {} samples", data.height());
35//! # Ok::<(), Box<dyn std::error::Error>>(())
36//! ```
37//!
38//! ### Digital Trigger
39//!
40//! ```rust
41//! use fleascope_rs::trigger_config::{DigitalTrigger, BitState};
42//!
43//! let trigger = DigitalTrigger::start_capturing_when()
44//!     .bit0(BitState::High)
45//!     .bit1(BitState::Low)
46//!     .starts_matching();
47//!
48//! let trigger_fields = trigger.into_trigger_fields();
49//! println!("Digital trigger: {}", trigger_fields);
50//! ```
51//!
52//! ### Analog Trigger
53//!
54//! ```rust
55//! use fleascope_rs::trigger_config::AnalogTrigger;
56//!
57//! let trigger = AnalogTrigger::start_capturing_when()
58//!     .rising_edge(1.5);
59//!
60//! let voltage_to_raw = |v: f64| v * 100.0;
61//! let trigger_fields = trigger.into_trigger_fields(voltage_to_raw).unwrap();
62//! println!("Analog trigger: {}", trigger_fields);
63//! ```
64//!
65//! ### Data Acquisition with Triggers
66//!
67//! ```rust,no_run
68//! use fleascope_rs::{FleaScope, ProbeType, DigitalTrigger, AnalogTrigger, Trigger, BitState};
69//! use std::time::Duration;
70//!
71//! let mut scope = FleaScope::connect(None, None, true)?;
72//!
73//! // Read with unified trigger API - digital trigger using 1x probe
74//! let digital_trigger = DigitalTrigger::start_capturing_when()
75//!     .bit0(BitState::High)
76//!     .starts_matching();
77//! let data = scope.read(ProbeType::X1, Duration::from_millis(5), Some(digital_trigger.into()), None)?;
78//!
79//! // Read with unified trigger API - analog trigger using 10x probe  
80//! let analog_trigger = AnalogTrigger::start_capturing_when()
81//!     .rising_edge(2.0);
82//! let data = scope.read(ProbeType::X10, Duration::from_millis(10), Some(analog_trigger.into()), Some(Duration::from_micros(500)))?;
83//!
84//! // You can also read without triggers (auto trigger)
85//! let data = scope.read(ProbeType::X1, Duration::from_millis(5), None, None)?;
86//! # Ok::<(), Box<dyn std::error::Error>>(())
87//! ```
88//!
89//! ### Device Discovery
90//!
91//! ```rust,no_run
92//! use fleascope_rs::FleaConnector;
93//!
94//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
95//! // Connect to any available FleaScope device
96//! let terminal = FleaConnector::connect(None, None, true)?;
97//!
98//! // Or connect to a specific port
99//! let terminal = FleaConnector::connect(None, Some("/dev/ttyUSB0"), true)?;
100//!
101//! // List available devices (iterator - memory efficient)
102//! let devices = FleaConnector::get_available_devices(None)?;
103//! for device in devices.take(3) { // Only process first 3 devices
104//!     println!("Found device: {} at {}", device.name, device.port);
105//! }
106//!
107//! // Or get all devices as a Vec (if you need to access multiple times)
108//! let devices_vec = FleaConnector::get_available_devices_vec(None)?;
109//! println!("Total devices: {}", devices_vec.len());
110//! # Ok(())
111//! # }
112//! ```
113//! ```
114
115pub mod flea_connector;
116pub mod flea_scope;
117pub mod serial_terminal;
118pub mod trigger_config;
119
120// Re-export the main types for convenience
121pub use trigger_config::{
122    AnalogTrigger, AnalogTriggerBehavior, AnalogTriggerBuilder, BitState, BitTriggerBuilder,
123    DigitalTrigger, DigitalTriggerBehavior, Trigger,
124};
125
126pub use serial_terminal::{FleaTerminalError, IdleFleaTerminal, StatelessFleaTerminal};
127
128pub use flea_connector::{FleaConnector, FleaConnectorError, FleaDevice};
129
130pub use flea_scope::{FleaProbe, IdleFleaScope, ProbeType, Waveform};