pub struct PowerDevice { /* private fields */ }Expand description
HID Power Device: a UPS or power supply.
Wrap it in a HidClass to talk to the host, and update it
from the main loop through
device_mut.
Implementations§
Source§impl PowerDevice
impl PowerDevice
Sourcepub fn new(device_type: PowerDeviceType) -> Self
pub fn new(device_type: PowerDeviceType) -> Self
Create a power device of the given type.
Sourcepub fn ups() -> Self
pub fn ups() -> Self
Create a UPS (PowerDeviceType::Ups).
Sourcepub fn power_supply() -> Self
pub fn power_supply() -> Self
Create a power supply without a battery (PowerDeviceType::PowerSupply).
Sourcepub fn device_type(&self) -> PowerDeviceType
pub fn device_type(&self) -> PowerDeviceType
Device type this instance was created with.
Sourcepub fn status(&self) -> PowerStatus
pub fn status(&self) -> PowerStatus
Present status last reported to the host.
Sourcepub fn config(&self) -> PowerConfig
pub fn config(&self) -> PowerConfig
Configuration last applied by the application.
Sourcepub fn set_status(&mut self, present: PowerStatus, changed: PowerStatus)
pub fn set_status(&mut self, present: PowerStatus, changed: PowerStatus)
Update the status flags and queue input report 1 if anything changed.
Pass changed flags (see PowerStatus::diff) to tell the host which
flags just changed; pass PowerStatus::NONE for a plain refresh.
Sourcepub fn set_measures(&mut self, measures: PowerMeasures)
pub fn set_measures(&mut self, measures: PowerMeasures)
Update the measurements and queue input report 2 if anything changed.
Sourcepub fn set_battery(&mut self, battery: BatteryState)
pub fn set_battery(&mut self, battery: BatteryState)
Update the battery state and queue input report 3 if anything changed.
Sourcepub fn set_config(&mut self, config: PowerConfig)
pub fn set_config(&mut self, config: PowerConfig)
Store the configuration the device is actually running with.
This is what Get Report returns, so call it after applying a
configuration written by the host, and whenever the configuration
changes for another reason.
Sourcepub fn request_refresh(&mut self)
pub fn request_refresh(&mut self)
Queue all three input reports, even if nothing changed.
Sourcepub fn take_controls(&mut self) -> Option<PowerControls>
pub fn take_controls(&mut self) -> Option<PowerControls>
Take the switch commands received since the last call.
Commands are accumulated until taken, so several reports may be coalesced into one value.
Sourcepub fn take_config_write(&mut self) -> Option<PowerConfig>
pub fn take_config_write(&mut self) -> Option<PowerConfig>
Take the configuration written by the host since the last call.
The application is expected to apply the values and then publish them
with set_config; until it does, Get Report keeps
returning the previous configuration.
Trait Implementations§
Source§impl Debug for PowerDevice
impl Debug for PowerDevice
Source§impl<B: UsbBus> HidDevice<B> for PowerDevice
impl<B: UsbBus> HidDevice<B> for PowerDevice
Source§fn get_report(
&mut self,
report_type: ReportType,
report_id: u8,
buf: &mut [u8],
) -> Option<usize>
fn get_report( &mut self, report_type: ReportType, report_id: u8, buf: &mut [u8], ) -> Option<usize>
Serve the reports the host reads on demand: the three input reports and the configuration feature report.
Source§fn set_report(
&mut self,
report_type: ReportType,
report_id: u8,
data: &[u8],
) -> bool
fn set_report( &mut self, report_type: ReportType, report_id: u8, data: &[u8], ) -> bool
Accept a configuration write or a switch command.
Source§fn output_report(&mut self, report_id: u8, data: &[u8])
fn output_report(&mut self, report_id: u8, data: &[u8])
Same switch commands, this time written straight to the interrupt OUT endpoint.
Source§fn poll(&mut self, input: &EndpointIn<'_, B>)
fn poll(&mut self, input: &EndpointIn<'_, B>)
Send the queued input reports, status first.
A report the endpoint cannot take yet
(WouldBlock) stays queued and is
retried on the next poll.