use crate::device::bus::UsbBus;
use crate::device::class::hid::{HidDevice, HidSpec, ReportType};
use crate::device::endpoint::EndpointIn;
pub mod power_usage {
pub const I_NAME: u8 = 0x01;
pub const PRESENT_STATUS: u8 = 0x02;
pub const CHANGED_STATUS: u8 = 0x03;
pub const UPS: u8 = 0x04;
pub const POWER_SUPPLY: u8 = 0x05;
pub const BATTERY: u8 = 0x12;
pub const VOLTAGE: u8 = 0x30;
pub const CURRENT: u8 = 0x31;
pub const FREQUENCY: u8 = 0x32;
pub const PERCENT_LOAD: u8 = 0x35;
pub const TEMPERATURE: u8 = 0x36;
pub const BAD_COUNT: u8 = 0x38;
pub const CONFIG_VOLTAGE: u8 = 0x40;
pub const CONFIG_CURRENT: u8 = 0x41;
pub const CONFIG_FREQUENCY: u8 = 0x42;
pub const CONFIG_TEMPERATURE: u8 = 0x46;
pub const SWITCH_ON_CONTROL: u8 = 0x50;
pub const SWITCH_OFF_CONTROL: u8 = 0x51;
pub const TOGGLE_CONTROL: u8 = 0x52;
pub const LOW_VOLTAGE_TRANSFER: u8 = 0x53;
pub const HIGH_VOLTAGE_TRANSFER: u8 = 0x54;
pub const DELAY_BEFORE_SHUTDOWN: u8 = 0x57;
pub const AUDIBLE_ALARM_CONTROL: u8 = 0x5A;
pub const PRESENT: u8 = 0x60;
pub const GOOD: u8 = 0x61;
pub const INTERNAL_FAILURE: u8 = 0x62;
pub const VOLTAGE_OUT_OF_RANGE: u8 = 0x63;
pub const FREQUENCY_OUT_OF_RANGE: u8 = 0x64;
pub const OVERLOAD: u8 = 0x65;
pub const OVER_CHARGED: u8 = 0x66;
pub const OVER_TEMPERATURE: u8 = 0x67;
pub const SHUTDOWN_REQUESTED: u8 = 0x68;
pub const SHUTDOWN_IMMINENT: u8 = 0x69;
pub const SWITCH_ON_OFF: u8 = 0x6B;
pub const SWITCHABLE: u8 = 0x6C;
pub const USED: u8 = 0x6D;
pub const BOOST: u8 = 0x6E;
pub const BUCK: u8 = 0x6F;
pub const INITIALIZED: u8 = 0x70;
pub const TESTED: u8 = 0x71;
pub const AWAITING_POWER: u8 = 0x72;
pub const COMMUNICATION_LOST: u8 = 0x73;
pub const I_MANUFACTURER: u8 = 0xFD;
pub const I_PRODUCT: u8 = 0xFE;
pub const I_SERIAL_NUMBER: u8 = 0xFF;
}
pub mod battery_usage {
pub const BATTERY: u8 = 0x12;
pub const BELOW_REMAINING_CAPACITY_LIMIT: u8 = 0x42;
pub const CHARGING: u8 = 0x44;
pub const DISCHARGING: u8 = 0x45;
pub const FULLY_CHARGED: u8 = 0x46;
pub const NEED_REPLACEMENT: u8 = 0x4B;
pub const RELATIVE_STATE_OF_CHARGE: u8 = 0x64;
pub const REMAINING_CAPACITY: u8 = 0x66;
pub const RUN_TIME_TO_EMPTY: u8 = 0x68;
pub const AC_PRESENT: u8 = 0xD0;
pub const BATTERY_PRESENT: u8 = 0xD1;
}
pub mod report_id {
pub const STATUS: u8 = 1;
pub const MEASURES: u8 = 2;
pub const BATTERY: u8 = 3;
pub const CONFIG: u8 = 4;
pub const CONTROLS: u8 = 5;
}
const LOGICAL_MAX_16: u16 = 0x7FFF;
const IN_ENDPOINT_SIZE: u16 = 16;
const OUT_ENDPOINT_SIZE: u16 = 8;
const POLL_INTERVAL_MS: u8 = 16;
fn clamp16(value: u16) -> u16 {
if value > LOGICAL_MAX_16 {
LOGICAL_MAX_16
} else {
value
}
}
fn clamp_percent(value: u8) -> u8 {
if value > 100 { 100 } else { value }
}
fn copy_report(report: &[u8], buf: &mut [u8]) -> usize {
let len = report.len().min(buf.len());
buf[..len].copy_from_slice(&report[..len]);
len
}
macro_rules! power_report_descriptor {
($app_usage:expr) => {
&[
0x05, 0x84, 0x09, $app_usage, 0xA1, 0x01, 0x85, 0x01, 0x09, 0x02, 0xA1, 0x02, 0x19, 0x60, 0x29, 0x69, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x0A, 0x81, 0x02, 0x19, 0x6B, 0x29, 0x73, 0x95, 0x09, 0x81, 0x02, 0x75, 0x05, 0x95, 0x01, 0x81, 0x01, 0xC0, 0x09, 0x03, 0xA1, 0x02, 0x75, 0x01, 0x19, 0x60, 0x29, 0x69, 0x95, 0x0A, 0x81, 0x02, 0x19, 0x6B, 0x29, 0x73, 0x95, 0x09, 0x81, 0x02, 0x75, 0x05, 0x95, 0x01, 0x81, 0x01, 0xC0, 0x85, 0x02, 0x05, 0x84, 0x09, 0x30, 0x15, 0x00, 0x26, 0xFF, 0x7F, 0x75, 0x10, 0x95, 0x01, 0x67, 0x21, 0xD1, 0xF0, 0x00, 0x55, 0x0E, 0x81, 0x02, 0x09, 0x31, 0x67, 0x01, 0x00, 0x10, 0x00, 0x55, 0x0E, 0x81, 0x02, 0x09, 0x32, 0x25, 0x64, 0x75, 0x08, 0x67, 0x01, 0xF0, 0x00, 0x00, 0x55, 0x00, 0x81, 0x02, 0x09, 0x35, 0x65, 0x00, 0x81, 0x02, 0x09, 0x36, 0x26, 0xFF, 0x7F, 0x75, 0x10, 0x67, 0x01, 0x00, 0x01, 0x00, 0x55, 0x00, 0x81, 0x02, 0x05, 0x85, 0x09, 0x12, 0xA1, 0x00, 0x85, 0x03, 0x05, 0x84, 0x09, 0x02, 0xA1, 0x02, 0x05, 0x85, 0x09, 0x44, 0x09, 0x45, 0x09, 0x46, 0x09, 0x42, 0x09, 0xD0, 0x09, 0xD1, 0x09, 0x4B, 0x15, 0x00, 0x25, 0x01, 0x65, 0x00, 0x75, 0x01, 0x95, 0x07, 0x81, 0x02, 0x95, 0x01, 0x81, 0x01, 0xC0, 0x05, 0x84, 0x09, 0x03, 0xA1, 0x02, 0x05, 0x85, 0x09, 0x44, 0x09, 0x45, 0x09, 0x46, 0x09, 0x42, 0x09, 0xD0, 0x09, 0xD1, 0x09, 0x4B, 0x95, 0x07, 0x81, 0x02, 0x95, 0x01, 0x81, 0x01, 0xC0, 0x05, 0x85, 0x09, 0x64, 0x15, 0x00, 0x25, 0x64, 0x75, 0x08, 0x95, 0x01, 0x81, 0x02, 0x09, 0x68, 0x15, 0x00, 0x26, 0xFF, 0x7F, 0x75, 0x10, 0x95, 0x01, 0x81, 0x02, 0xC0, 0x85, 0x04, 0x05, 0x84, 0x09, 0x40, 0x15, 0x00, 0x26, 0xFF, 0x7F, 0x75, 0x10, 0x95, 0x01, 0x67, 0x21, 0xD1, 0xF0, 0x00, 0x55, 0x0E, 0xB1, 0x02, 0x09, 0x41, 0x67, 0x01, 0x00, 0x10, 0x00, 0x55, 0x0E, 0xB1, 0x02, 0x09, 0x42, 0x25, 0x64, 0x75, 0x08, 0x67, 0x01, 0xF0, 0x00, 0x00, 0x55, 0x00, 0xB1, 0x02, 0x09, 0x53, 0x26, 0xFF, 0x7F, 0x75, 0x10, 0x67, 0x21, 0xD1, 0xF0, 0x00, 0x55, 0x0E, 0xB1, 0x02, 0x09, 0x54, 0xB1, 0x02, 0x09, 0x57, 0x67, 0x01, 0x10, 0x00, 0x00, 0x55, 0x00, 0xB1, 0x02, 0x09, 0x46, 0x67, 0x01, 0x00, 0x01, 0x00, 0xB1, 0x02, 0x85, 0x05, 0x05, 0x84, 0x09, 0x50, 0x09, 0x51, 0x09, 0x52, 0x09, 0x5A, 0x15, 0x00, 0x25, 0x01, 0x65, 0x00, 0x75, 0x01, 0x95, 0x04, 0x91, 0x02, 0x75, 0x04, 0x95, 0x01, 0x91, 0x01, 0xC0, ]
};
}
pub const UPS_REPORT_DESCRIPTOR: &[u8] = power_report_descriptor!(power_usage::UPS);
pub const POWER_SUPPLY_REPORT_DESCRIPTOR: &[u8] =
power_report_descriptor!(power_usage::POWER_SUPPLY);
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum PowerDeviceType {
Ups,
PowerSupply,
}
impl PowerDeviceType {
pub const fn usage(self) -> u8 {
match self {
Self::Ups => power_usage::UPS,
Self::PowerSupply => power_usage::POWER_SUPPLY,
}
}
pub const fn descriptor(self) -> &'static [u8] {
match self {
Self::Ups => UPS_REPORT_DESCRIPTOR,
Self::PowerSupply => POWER_SUPPLY_REPORT_DESCRIPTOR,
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Default, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PowerStatus(u32);
impl PowerStatus {
pub const SIZE: usize = 3;
pub const NONE: Self = Self(0);
pub const PRESENT: Self = Self(1 << 0);
pub const GOOD: Self = Self(1 << 1);
pub const INTERNAL_FAILURE: Self = Self(1 << 2);
pub const VOLTAGE_OUT_OF_RANGE: Self = Self(1 << 3);
pub const FREQUENCY_OUT_OF_RANGE: Self = Self(1 << 4);
pub const OVERLOAD: Self = Self(1 << 5);
pub const OVER_CHARGED: Self = Self(1 << 6);
pub const OVER_TEMPERATURE: Self = Self(1 << 7);
pub const SHUTDOWN_REQUESTED: Self = Self(1 << 8);
pub const SHUTDOWN_IMMINENT: Self = Self(1 << 9);
pub const SWITCH_ON_OFF: Self = Self(1 << 10);
pub const SWITCHABLE: Self = Self(1 << 11);
pub const USED: Self = Self(1 << 12);
pub const BOOST: Self = Self(1 << 13);
pub const BUCK: Self = Self(1 << 14);
pub const INITIALIZED: Self = Self(1 << 15);
pub const TESTED: Self = Self(1 << 16);
pub const AWAITING_POWER: Self = Self(1 << 17);
pub const COMMUNICATION_LOST: Self = Self(1 << 18);
const MASK: u32 = (1 << 19) - 1;
pub const fn bits(self) -> u32 {
self.0
}
pub const fn contains(self, other: Self) -> bool {
self.0 & other.0 == other.0
}
pub const fn union(self, other: Self) -> Self {
Self(self.0 | other.0)
}
pub const fn without(self, other: Self) -> Self {
Self(self.0 & !other.0)
}
pub const fn diff(self, previous: Self) -> Self {
Self((self.0 ^ previous.0) & Self::MASK)
}
pub fn to_bytes(self) -> [u8; Self::SIZE] {
let bits = (self.0 & Self::MASK).to_le_bytes();
[bits[0], bits[1], bits[2]]
}
pub fn from_bytes(bytes: &[u8]) -> Self {
let mut bits = 0u32;
for (i, byte) in bytes.iter().take(Self::SIZE).enumerate() {
bits |= u32::from(*byte) << (8 * i);
}
Self(bits & Self::MASK)
}
}
impl core::ops::BitOr for PowerStatus {
type Output = Self;
fn bitor(self, rhs: Self) -> Self {
self.union(rhs)
}
}
#[derive(Clone, Copy, PartialEq, Eq, Default, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct BatteryStatus(u8);
impl BatteryStatus {
pub const SIZE: usize = 1;
pub const NONE: Self = Self(0);
pub const CHARGING: Self = Self(1 << 0);
pub const DISCHARGING: Self = Self(1 << 1);
pub const FULLY_CHARGED: Self = Self(1 << 2);
pub const BELOW_REMAINING_CAPACITY_LIMIT: Self = Self(1 << 3);
pub const AC_PRESENT: Self = Self(1 << 4);
pub const BATTERY_PRESENT: Self = Self(1 << 5);
pub const NEED_REPLACEMENT: Self = Self(1 << 6);
const MASK: u8 = (1 << 7) - 1;
pub const fn bits(self) -> u8 {
self.0
}
pub const fn contains(self, other: Self) -> bool {
self.0 & other.0 == other.0
}
pub const fn union(self, other: Self) -> Self {
Self(self.0 | other.0)
}
pub const fn without(self, other: Self) -> Self {
Self(self.0 & !other.0)
}
pub const fn diff(self, previous: Self) -> Self {
Self((self.0 ^ previous.0) & Self::MASK)
}
pub const fn to_byte(self) -> u8 {
self.0 & Self::MASK
}
pub const fn from_byte(byte: u8) -> Self {
Self(byte & Self::MASK)
}
}
impl core::ops::BitOr for BatteryStatus {
type Output = Self;
fn bitor(self, rhs: Self) -> Self {
self.union(rhs)
}
}
#[derive(Clone, Copy, PartialEq, Eq, Default, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PowerMeasures {
pub voltage_cv: u16,
pub current_ca: u16,
pub frequency_hz: u8,
pub percent_load: u8,
pub temperature_k: u16,
}
impl PowerMeasures {
pub const SIZE: usize = 8;
pub fn to_bytes(self) -> [u8; Self::SIZE] {
let voltage = clamp16(self.voltage_cv).to_le_bytes();
let current = clamp16(self.current_ca).to_le_bytes();
let temperature = clamp16(self.temperature_k).to_le_bytes();
[
voltage[0],
voltage[1],
current[0],
current[1],
self.frequency_hz.min(100),
clamp_percent(self.percent_load),
temperature[0],
temperature[1],
]
}
}
#[derive(Clone, Copy, PartialEq, Eq, Default, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct BatteryState {
pub status: BatteryStatus,
pub changed: BatteryStatus,
pub state_of_charge_pct: u8,
pub run_time_to_empty_min: u16,
}
impl BatteryState {
pub const SIZE: usize = 5;
pub fn to_bytes(self) -> [u8; Self::SIZE] {
let run_time = clamp16(self.run_time_to_empty_min).to_le_bytes();
[
self.status.to_byte(),
self.changed.to_byte(),
clamp_percent(self.state_of_charge_pct),
run_time[0],
run_time[1],
]
}
}
#[derive(Clone, Copy, PartialEq, Eq, Default, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PowerConfig {
pub voltage_cv: u16,
pub current_ca: u16,
pub frequency_hz: u8,
pub low_voltage_transfer_cv: u16,
pub high_voltage_transfer_cv: u16,
pub delay_before_shutdown_s: u16,
pub temperature_k: u16,
}
impl PowerConfig {
pub const SIZE: usize = 13;
pub fn to_bytes(self) -> [u8; Self::SIZE] {
let voltage = clamp16(self.voltage_cv).to_le_bytes();
let current = clamp16(self.current_ca).to_le_bytes();
let low = clamp16(self.low_voltage_transfer_cv).to_le_bytes();
let high = clamp16(self.high_voltage_transfer_cv).to_le_bytes();
let delay = clamp16(self.delay_before_shutdown_s).to_le_bytes();
let temperature = clamp16(self.temperature_k).to_le_bytes();
[
voltage[0],
voltage[1],
current[0],
current[1],
self.frequency_hz.min(100),
low[0],
low[1],
high[0],
high[1],
delay[0],
delay[1],
temperature[0],
temperature[1],
]
}
pub fn from_bytes(bytes: &[u8]) -> Option<Self> {
if bytes.len() < Self::SIZE {
return None;
}
Some(Self {
voltage_cv: u16::from_le_bytes([bytes[0], bytes[1]]),
current_ca: u16::from_le_bytes([bytes[2], bytes[3]]),
frequency_hz: bytes[4],
low_voltage_transfer_cv: u16::from_le_bytes([bytes[5], bytes[6]]),
high_voltage_transfer_cv: u16::from_le_bytes([bytes[7], bytes[8]]),
delay_before_shutdown_s: u16::from_le_bytes([bytes[9], bytes[10]]),
temperature_k: u16::from_le_bytes([bytes[11], bytes[12]]),
})
}
}
#[derive(Clone, Copy, PartialEq, Eq, Default, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct PowerControls(u8);
impl PowerControls {
pub const SIZE: usize = 1;
pub const NONE: Self = Self(0);
pub const SWITCH_ON: Self = Self(1 << 0);
pub const SWITCH_OFF: Self = Self(1 << 1);
pub const TOGGLE: Self = Self(1 << 2);
pub const AUDIBLE_ALARM: Self = Self(1 << 3);
const MASK: u8 = (1 << 4) - 1;
pub const fn bits(self) -> u8 {
self.0
}
pub const fn contains(self, other: Self) -> bool {
self.0 & other.0 == other.0
}
pub const fn union(self, other: Self) -> Self {
Self(self.0 | other.0)
}
pub const fn without(self, other: Self) -> Self {
Self(self.0 & !other.0)
}
pub const fn to_byte(self) -> u8 {
self.0 & Self::MASK
}
pub const fn from_byte(byte: u8) -> Self {
Self(byte & Self::MASK)
}
}
impl core::ops::BitOr for PowerControls {
type Output = Self;
fn bitor(self, rhs: Self) -> Self {
self.union(rhs)
}
}
const PENDING_STATUS: u8 = 1 << 0;
const PENDING_MEASURES: u8 = 1 << 1;
const PENDING_BATTERY: u8 = 1 << 2;
const PENDING_ALL: u8 = PENDING_STATUS | PENDING_MEASURES | PENDING_BATTERY;
#[derive(Debug)]
pub struct PowerDevice {
device_type: PowerDeviceType,
present: PowerStatus,
changed: PowerStatus,
measures: PowerMeasures,
battery: BatteryState,
config: PowerConfig,
pending_input: u8,
pending_controls: PowerControls,
pending_config: Option<PowerConfig>,
}
impl PowerDevice {
pub fn new(device_type: PowerDeviceType) -> Self {
Self {
device_type,
present: PowerStatus::NONE,
changed: PowerStatus::NONE,
measures: PowerMeasures::default(),
battery: BatteryState::default(),
config: PowerConfig::default(),
pending_input: 0,
pending_controls: PowerControls::NONE,
pending_config: None,
}
}
pub fn ups() -> Self {
Self::new(PowerDeviceType::Ups)
}
pub fn power_supply() -> Self {
Self::new(PowerDeviceType::PowerSupply)
}
pub fn device_type(&self) -> PowerDeviceType {
self.device_type
}
pub fn status(&self) -> PowerStatus {
self.present
}
pub fn config(&self) -> PowerConfig {
self.config
}
pub fn set_status(&mut self, present: PowerStatus, changed: PowerStatus) {
if present != self.present || changed != self.changed {
self.present = present;
self.changed = changed;
self.pending_input |= PENDING_STATUS;
}
}
pub fn set_measures(&mut self, measures: PowerMeasures) {
if measures != self.measures {
self.measures = measures;
self.pending_input |= PENDING_MEASURES;
}
}
pub fn set_battery(&mut self, battery: BatteryState) {
if battery != self.battery {
self.battery = battery;
self.pending_input |= PENDING_BATTERY;
}
}
pub fn set_config(&mut self, config: PowerConfig) {
self.config = config;
}
pub fn request_refresh(&mut self) {
self.pending_input |= PENDING_ALL;
}
pub fn take_controls(&mut self) -> Option<PowerControls> {
if self.pending_controls == PowerControls::NONE {
None
} else {
Some(core::mem::replace(
&mut self.pending_controls,
PowerControls::NONE,
))
}
}
pub fn take_config_write(&mut self) -> Option<PowerConfig> {
self.pending_config.take()
}
fn status_report(&self) -> [u8; 1 + 2 * PowerStatus::SIZE] {
let mut report = [0u8; 1 + 2 * PowerStatus::SIZE];
report[0] = report_id::STATUS;
report[1..1 + PowerStatus::SIZE].copy_from_slice(&self.present.to_bytes());
report[1 + PowerStatus::SIZE..].copy_from_slice(&self.changed.to_bytes());
report
}
fn measures_report(&self) -> [u8; 1 + PowerMeasures::SIZE] {
let mut report = [0u8; 1 + PowerMeasures::SIZE];
report[0] = report_id::MEASURES;
report[1..].copy_from_slice(&self.measures.to_bytes());
report
}
fn battery_report(&self) -> [u8; 1 + BatteryState::SIZE] {
let mut report = [0u8; 1 + BatteryState::SIZE];
report[0] = report_id::BATTERY;
report[1..].copy_from_slice(&self.battery.to_bytes());
report
}
fn config_report(&self) -> [u8; 1 + PowerConfig::SIZE] {
let mut report = [0u8; 1 + PowerConfig::SIZE];
report[0] = report_id::CONFIG;
report[1..].copy_from_slice(&self.config.to_bytes());
report
}
fn apply_controls(&mut self, data: &[u8]) -> bool {
match data.first() {
Some(&byte) => {
self.pending_controls = self.pending_controls.union(PowerControls::from_byte(byte));
true
}
None => false,
}
}
fn clear_host_requests(&mut self) {
self.pending_controls = PowerControls::NONE;
self.pending_config = None;
}
}
impl<B: UsbBus> HidDevice<B> for PowerDevice {
fn spec(&self) -> HidSpec {
HidSpec::new(self.device_type.descriptor(), IN_ENDPOINT_SIZE)
.out_report_size(OUT_ENDPOINT_SIZE)
.poll_interval_ms(POLL_INTERVAL_MS)
.report_ids(true)
}
fn get_report(
&mut self,
report_type: ReportType,
report_id: u8,
buf: &mut [u8],
) -> Option<usize> {
match (report_type, report_id) {
(ReportType::Input, report_id::STATUS) => Some(copy_report(&self.status_report(), buf)),
(ReportType::Input, report_id::MEASURES) => {
Some(copy_report(&self.measures_report(), buf))
}
(ReportType::Input, report_id::BATTERY) => {
Some(copy_report(&self.battery_report(), buf))
}
(ReportType::Feature, report_id::CONFIG) => {
Some(copy_report(&self.config_report(), buf))
}
_ => None,
}
}
fn set_report(&mut self, report_type: ReportType, report_id: u8, data: &[u8]) -> bool {
match (report_type, report_id) {
(ReportType::Feature, report_id::CONFIG) => match PowerConfig::from_bytes(data) {
Some(config) => {
self.pending_config = Some(config);
true
}
None => false,
},
(ReportType::Output, report_id::CONTROLS) => self.apply_controls(data),
_ => false,
}
}
fn output_report(&mut self, report_id: u8, data: &[u8]) {
if report_id == report_id::CONTROLS {
self.apply_controls(data);
}
}
fn reset(&mut self) {
self.pending_input = 0;
self.clear_host_requests();
}
fn configure(&mut self) {
self.request_refresh();
self.clear_host_requests();
}
fn deconfigure(&mut self) {
self.pending_input = 0;
self.clear_host_requests();
}
fn poll(&mut self, input: &EndpointIn<'_, B>) {
if self.pending_input & PENDING_STATUS != 0 {
if input.write(&self.status_report()).is_err() {
return;
}
self.pending_input &= !PENDING_STATUS;
}
if self.pending_input & PENDING_MEASURES != 0 {
if input.write(&self.measures_report()).is_err() {
return;
}
self.pending_input &= !PENDING_MEASURES;
}
if self.pending_input & PENDING_BATTERY != 0 {
if input.write(&self.battery_report()).is_err() {
return;
}
self.pending_input &= !PENDING_BATTERY;
}
}
}