Skip to main content

Settings

Struct Settings 

Source
pub struct Settings { /* private fields */ }
Expand description

Lossless, read-only representation of a GetData(Settings) payload.

Unknown fields remain available through Self::settings_a_raw and Self::settings_b_raw. Only fields whose meanings are corroborated by KM003C V1.9.9 firmware consumers have semantic accessors.

Implementations§

Source§

impl Settings

Source

pub fn from_bytes(bytes: &[u8]) -> Result<Self, KMError>

Parse both settings blocks and validate their independent CRC-32 values.

Source

pub fn to_bytes(&self) -> [u8; 180]

Serialize the exact captured settings payload, including unknown fields.

Source

pub fn settings_a_raw(&self) -> &[u8] ⓘ

Return the complete first persisted settings block.

Source

pub fn settings_b_raw(&self) -> &[u8] ⓘ

Return the complete second persisted settings block.

Source

pub fn settings_a_flags(&self) -> u32

Raw settings-A flags, including fields whose meanings remain unknown.

Source

pub fn settings_b_flags(&self) -> u32

Raw settings-B flags, including fields whose meanings remain unknown.

Source

pub fn language_selection(&self) -> u8

Firmware language-table selection, encoded as 0 or 1.

The mapping from these indices to a particular language is not yet independently confirmed, so this accessor deliberately returns the stored index rather than guessing an enum variant.

Examples found in repository?
examples/settings.rs (line 11)
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let mut device = KM003C::new(DeviceConfig::vendor().skip_reset()).await?;
8    let settings = device.request_settings().await?;
9
10    println!("Device name: {}", settings.device_name().unwrap_or("<invalid UTF-8>"));
11    println!("Language selection: {}", settings.language_selection());
12    println!("Uncalibrated: {}", settings.is_uncalibrated());
13    println!("Brightness: {}%", settings.brightness().get::<percent>());
14    println!(
15        "Sample interval: {} us",
16        settings.sample_interval().get::<microsecond>()
17    );
18    println!("Screen orientation: {}", settings.screen_orientation());
19    println!("Mtools device mode: {}", settings.mtools_device_mode());
20    println!("Selected main page: {}", settings.selected_main_page());
21
22    Ok(())
23}
Source

pub fn is_uncalibrated(&self) -> bool

Whether firmware marks the device as requiring calibration.

Examples found in repository?
examples/settings.rs (line 12)
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let mut device = KM003C::new(DeviceConfig::vendor().skip_reset()).await?;
8    let settings = device.request_settings().await?;
9
10    println!("Device name: {}", settings.device_name().unwrap_or("<invalid UTF-8>"));
11    println!("Language selection: {}", settings.language_selection());
12    println!("Uncalibrated: {}", settings.is_uncalibrated());
13    println!("Brightness: {}%", settings.brightness().get::<percent>());
14    println!(
15        "Sample interval: {} us",
16        settings.sample_interval().get::<microsecond>()
17    );
18    println!("Screen orientation: {}", settings.screen_orientation());
19    println!("Mtools device mode: {}", settings.mtools_device_mode());
20    println!("Selected main page: {}", settings.selected_main_page());
21
22    Ok(())
23}
Source

pub fn brightness(&self) -> Ratio

Display brightness as applied by firmware, in percent.

The stored field is seven bits wide; firmware clamps values above 100.

Examples found in repository?
examples/settings.rs (line 13)
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let mut device = KM003C::new(DeviceConfig::vendor().skip_reset()).await?;
8    let settings = device.request_settings().await?;
9
10    println!("Device name: {}", settings.device_name().unwrap_or("<invalid UTF-8>"));
11    println!("Language selection: {}", settings.language_selection());
12    println!("Uncalibrated: {}", settings.is_uncalibrated());
13    println!("Brightness: {}%", settings.brightness().get::<percent>());
14    println!(
15        "Sample interval: {} us",
16        settings.sample_interval().get::<microsecond>()
17    );
18    println!("Screen orientation: {}", settings.screen_orientation());
19    println!("Mtools device mode: {}", settings.mtools_device_mode());
20    println!("Selected main page: {}", settings.selected_main_page());
21
22    Ok(())
23}
Source

pub fn sample_interval(&self) -> Time

ADC sample interval stored in the settings block.

Examples found in repository?
examples/settings.rs (line 16)
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let mut device = KM003C::new(DeviceConfig::vendor().skip_reset()).await?;
8    let settings = device.request_settings().await?;
9
10    println!("Device name: {}", settings.device_name().unwrap_or("<invalid UTF-8>"));
11    println!("Language selection: {}", settings.language_selection());
12    println!("Uncalibrated: {}", settings.is_uncalibrated());
13    println!("Brightness: {}%", settings.brightness().get::<percent>());
14    println!(
15        "Sample interval: {} us",
16        settings.sample_interval().get::<microsecond>()
17    );
18    println!("Screen orientation: {}", settings.screen_orientation());
19    println!("Mtools device mode: {}", settings.mtools_device_mode());
20    println!("Selected main page: {}", settings.selected_main_page());
21
22    Ok(())
23}
Source

pub fn screen_orientation(&self) -> u8

Display orientation index stored by firmware, in the range 0..=3.

Examples found in repository?
examples/settings.rs (line 18)
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let mut device = KM003C::new(DeviceConfig::vendor().skip_reset()).await?;
8    let settings = device.request_settings().await?;
9
10    println!("Device name: {}", settings.device_name().unwrap_or("<invalid UTF-8>"));
11    println!("Language selection: {}", settings.language_selection());
12    println!("Uncalibrated: {}", settings.is_uncalibrated());
13    println!("Brightness: {}%", settings.brightness().get::<percent>());
14    println!(
15        "Sample interval: {} us",
16        settings.sample_interval().get::<microsecond>()
17    );
18    println!("Screen orientation: {}", settings.screen_orientation());
19    println!("Mtools device mode: {}", settings.mtools_device_mode());
20    println!("Selected main page: {}", settings.selected_main_page());
21
22    Ok(())
23}
Source

pub fn mtools_device_mode(&self) -> u8

Mtools device-mode index stored by firmware, in the range 0..=3.

Examples found in repository?
examples/settings.rs (line 19)
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let mut device = KM003C::new(DeviceConfig::vendor().skip_reset()).await?;
8    let settings = device.request_settings().await?;
9
10    println!("Device name: {}", settings.device_name().unwrap_or("<invalid UTF-8>"));
11    println!("Language selection: {}", settings.language_selection());
12    println!("Uncalibrated: {}", settings.is_uncalibrated());
13    println!("Brightness: {}%", settings.brightness().get::<percent>());
14    println!(
15        "Sample interval: {} us",
16        settings.sample_interval().get::<microsecond>()
17    );
18    println!("Screen orientation: {}", settings.screen_orientation());
19    println!("Mtools device mode: {}", settings.mtools_device_mode());
20    println!("Selected main page: {}", settings.selected_main_page());
21
22    Ok(())
23}
Source

pub fn selected_main_page(&self) -> u8

Persisted main-page index, in the range 0..=15.

Examples found in repository?
examples/settings.rs (line 20)
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let mut device = KM003C::new(DeviceConfig::vendor().skip_reset()).await?;
8    let settings = device.request_settings().await?;
9
10    println!("Device name: {}", settings.device_name().unwrap_or("<invalid UTF-8>"));
11    println!("Language selection: {}", settings.language_selection());
12    println!("Uncalibrated: {}", settings.is_uncalibrated());
13    println!("Brightness: {}%", settings.brightness().get::<percent>());
14    println!(
15        "Sample interval: {} us",
16        settings.sample_interval().get::<microsecond>()
17    );
18    println!("Screen orientation: {}", settings.screen_orientation());
19    println!("Mtools device mode: {}", settings.mtools_device_mode());
20    println!("Selected main page: {}", settings.selected_main_page());
21
22    Ok(())
23}
Source

pub fn device_name_raw(&self) -> &[u8] ⓘ

Raw 64-byte device-name field, including trailing zero padding.

Source

pub fn device_name(&self) -> Option<&str>

UTF-8 device name when the stored bytes are valid UTF-8.

Examples found in repository?
examples/settings.rs (line 10)
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let mut device = KM003C::new(DeviceConfig::vendor().skip_reset()).await?;
8    let settings = device.request_settings().await?;
9
10    println!("Device name: {}", settings.device_name().unwrap_or("<invalid UTF-8>"));
11    println!("Language selection: {}", settings.language_selection());
12    println!("Uncalibrated: {}", settings.is_uncalibrated());
13    println!("Brightness: {}%", settings.brightness().get::<percent>());
14    println!(
15        "Sample interval: {} us",
16        settings.sample_interval().get::<microsecond>()
17    );
18    println!("Screen orientation: {}", settings.screen_orientation());
19    println!("Mtools device mode: {}", settings.mtools_device_mode());
20    println!("Selected main page: {}", settings.selected_main_page());
21
22    Ok(())
23}
Source

pub fn settings_a_checksum(&self) -> u32

Stored CRC-32 for the first settings block.

Source

pub fn settings_b_checksum(&self) -> u32

Stored CRC-32 for the second settings block.

Trait Implementations§

Source§

impl Clone for Settings

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Settings

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Settings

Source§

impl PartialEq for Settings

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Settings

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more