Crate waveshare_ups_hat_e

Crate waveshare_ups_hat_e 

Source
Expand description

§waveshare-ups-hat-e

A Rust library for monitoring the Waveshare UPS HAT (E) on Raspberry Pi via I2C.

§Example Output

Output from the ups_monitor example demonstrating the type of information available:

Screenshot of ups_monitor example

§Usage

use waveshare_ups_hat_e::UpsHatE;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut ups = UpsHatE::new();

    let battery = ups.get_battery_state()?;
    println!("Battery: {}% ({} mV, {} mA)",
        battery.remaining_percent,
        battery.millivolts,
        battery.milliamps);
    println!("Remaining: {} mAh, {} min",
        battery.remaining_capacity_milliamphours,
        battery.remaining_runtime_minutes);

    let power = ups.get_power_state()?;
    println!("Charging: {:?}, Activity: {:?}",
        power.charging_state,
        power.charger_activity);
    println!("USB-C: {:?}, PD: {:?}",
        power.usbc_input_state,
        power.usbc_power_delivery);

    let vbus = ups.get_usbc_vbus()?;
    println!("VBUS: {} mV, {} mA, {} mW",
        vbus.millivolts,
        vbus.milliamps,
        vbus.milliwatts);

    let cells = ups.get_cell_voltage()?;
    println!("Cells: {:?}", cells);

    Ok(())
}

§API

MethodDescription
get_battery_stateVoltage, current, capacity, remaining runtime
get_power_stateCharging state, USB-C input, power delivery mode
get_cell_voltageIndividual cell voltages (4 cells)
get_usbc_vbusUSB-C voltage, current, power

§License

Licensed under either of Apache License, Version 2.0 or MIT License at your option.

Copyright (c) 2025 Stuart Stock, all rights reserved.

Modules§

error
registers

Structs§

BatteryState
Aggregate battery state of the UPS Hat E.
CellVoltage
Voltage readings for each of the four battery cells.
PowerState
Represent the composite power state of the UPS Hat E.
UpsHatE
Monitor a Waveshare UPS HAT E (Uninterruptible Power Supply model E) for a Raspberry Pi.
UsbCVBus
Voltage and current readings from the USB-C port.

Constants§

DEFAULT_I2C_ADDRESS
Default I2C address of the Waveshare UPS Hat E
DEFAULT_I2C_DEV_PATH
The default I2C bus device path to interface with the UPS Hat E