waveshare-ups-hat-e 0.1.0

A Rust library to monitor the status of a Waveshare UPS HAT E on a Raspberry Pi
Documentation
  • Coverage
  • 25.45%
    14 out of 55 items documented1 out of 17 items with examples
  • Size
  • Source code size: 67.03 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.61 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 19s Average build duration of successful builds.
  • all releases: 19s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • int08h

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

Method Description
get_battery_state Voltage, current, capacity, remaining runtime
get_power_state Charging state, USB-C input, power delivery mode
get_cell_voltage Individual cell voltages (4 cells)
get_usbc_vbus USB-C voltage, current, power

License

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

Copyright

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