Skip to main content

PowerDevice

Struct PowerDevice 

Source
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

Source

pub fn new(device_type: PowerDeviceType) -> Self

Create a power device of the given type.

Source

pub fn ups() -> Self

Create a UPS (PowerDeviceType::Ups).

Source

pub fn power_supply() -> Self

Create a power supply without a battery (PowerDeviceType::PowerSupply).

Source

pub fn device_type(&self) -> PowerDeviceType

Device type this instance was created with.

Source

pub fn status(&self) -> PowerStatus

Present status last reported to the host.

Source

pub fn config(&self) -> PowerConfig

Configuration last applied by the application.

Source

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.

Source

pub fn set_measures(&mut self, measures: PowerMeasures)

Update the measurements and queue input report 2 if anything changed.

Source

pub fn set_battery(&mut self, battery: BatteryState)

Update the battery state and queue input report 3 if anything changed.

Source

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.

Source

pub fn request_refresh(&mut self)

Queue all three input reports, even if nothing changed.

Source

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.

Source

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

Source§

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

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

impl<B: UsbBus> HidDevice<B> for PowerDevice

Source§

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

Accept a configuration write or a switch command.

Source§

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>)

Send the queued input reports, status first.

A report the endpoint cannot take yet (WouldBlock) stays queued and is retried on the next poll.

Source§

fn spec(&self) -> HidSpec

Report descriptor, endpoint sizes and interface class/protocol.
Source§

fn reset(&mut self)

Called after a USB bus reset.
Source§

fn configure(&mut self)

Called when the host configures the device. Read more
Source§

fn deconfigure(&mut self)

Called when the host de-configures the device.

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.