Public Access
refactor(ups-hid): first working cyberpower hid implementation tested with CP1500EPFCLCD
Signed-off-by: bullshit <coding@ow-software.pl>
This commit is contained in:
7 files changed
+811
-378
No files matched your search
@@ -0,0 +1,87 @@
|
||||
#pragma once
|
||||
|
||||
#include "ups_hid.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ups_hid {
|
||||
|
||||
/**
|
||||
* @brief CyberPower HID Protocol Implementation
|
||||
*
|
||||
* Based on NUT cps-hid.c driver reference implementation.
|
||||
* Supports CP1500EPFCLCD and similar CyberPower models.
|
||||
*
|
||||
* Key differences from APC:
|
||||
* - Different report IDs for core data
|
||||
* - Voltage scaling may be needed (2/3 factor)
|
||||
* - Frequency scaling (0.1 factor) for some models
|
||||
* - Uses Feature Reports for most data
|
||||
*/
|
||||
class CyberPowerProtocol : public UpsProtocolBase {
|
||||
public:
|
||||
CyberPowerProtocol(UpsHidComponent *parent) : UpsProtocolBase(parent) {}
|
||||
|
||||
bool detect() override;
|
||||
bool initialize() override;
|
||||
bool read_data(UpsData &data) override;
|
||||
UpsProtocol get_protocol_type() const override { return PROTOCOL_CYBERPOWER_HID; }
|
||||
std::string get_protocol_name() const override { return "CyberPower HID"; }
|
||||
|
||||
private:
|
||||
// Report ID constants (based on NUT debug logs)
|
||||
static const uint8_t BATTERY_RUNTIME_REPORT_ID = 0x08; // Battery % + Runtime
|
||||
static const uint8_t BATTERY_VOLTAGE_NOMINAL_REPORT_ID = 0x09; // Battery voltage nominal
|
||||
static const uint8_t BATTERY_VOLTAGE_REPORT_ID = 0x0a; // Battery voltage
|
||||
static const uint8_t PRESENT_STATUS_REPORT_ID = 0x0b; // Status bitmap
|
||||
static const uint8_t BEEPER_STATUS_REPORT_ID = 0x0c; // Beeper status
|
||||
static const uint8_t INPUT_VOLTAGE_NOMINAL_REPORT_ID = 0x0e; // Input voltage nominal
|
||||
static const uint8_t INPUT_VOLTAGE_REPORT_ID = 0x0f; // Input voltage
|
||||
static const uint8_t INPUT_TRANSFER_REPORT_ID = 0x10; // Input transfer limits
|
||||
static const uint8_t OUTPUT_VOLTAGE_REPORT_ID = 0x12; // Output voltage
|
||||
static const uint8_t LOAD_PERCENT_REPORT_ID = 0x13; // Load percentage
|
||||
static const uint8_t DELAY_SHUTDOWN_REPORT_ID = 0x15; // Delay before shutdown
|
||||
static const uint8_t DELAY_START_REPORT_ID = 0x16; // Delay before startup
|
||||
static const uint8_t REALPOWER_NOMINAL_REPORT_ID = 0x18; // Nominal real power
|
||||
static const uint8_t INPUT_SENSITIVITY_REPORT_ID = 0x1a; // Input sensitivity
|
||||
static const uint8_t FIRMWARE_VERSION_REPORT_ID = 0x1b; // Firmware version
|
||||
static const uint8_t SERIAL_NUMBER_REPORT_ID = 0x02; // Serial number
|
||||
|
||||
// HID Report structure
|
||||
struct HidReport {
|
||||
uint8_t report_id;
|
||||
std::vector<uint8_t> data;
|
||||
|
||||
HidReport() : report_id(0) {}
|
||||
};
|
||||
|
||||
// CyberPower-specific scaling factors
|
||||
float battery_voltage_scale_ = 1.0f;
|
||||
bool battery_scale_checked_ = false;
|
||||
|
||||
// HID communication methods
|
||||
bool read_hid_report(uint8_t report_id, HidReport &report);
|
||||
|
||||
// Parser methods for different reports
|
||||
void parse_battery_runtime_report(const HidReport &report, UpsData &data);
|
||||
void parse_battery_voltage_report(const HidReport &report, UpsData &data);
|
||||
void parse_battery_voltage_nominal_report(const HidReport &report, UpsData &data);
|
||||
void parse_present_status_report(const HidReport &report, UpsData &data);
|
||||
void parse_beeper_status_report(const HidReport &report, UpsData &data);
|
||||
void parse_input_voltage_nominal_report(const HidReport &report, UpsData &data);
|
||||
void parse_input_voltage_report(const HidReport &report, UpsData &data);
|
||||
void parse_input_transfer_report(const HidReport &report, UpsData &data);
|
||||
void parse_output_voltage_report(const HidReport &report, UpsData &data);
|
||||
void parse_load_percent_report(const HidReport &report, UpsData &data);
|
||||
void parse_delay_shutdown_report(const HidReport &report, UpsData &data);
|
||||
void parse_delay_start_report(const HidReport &report, UpsData &data);
|
||||
void parse_realpower_nominal_report(const HidReport &report, UpsData &data);
|
||||
void parse_input_sensitivity_report(const HidReport &report, UpsData &data);
|
||||
void parse_firmware_version_report(const HidReport &report, UpsData &data);
|
||||
void parse_serial_number_report(const HidReport &report, UpsData &data);
|
||||
|
||||
// CyberPower-specific scaling logic
|
||||
void check_battery_voltage_scaling(float battery_voltage, float nominal_voltage);
|
||||
};
|
||||
|
||||
} // namespace ups_hid
|
||||
} // namespace esphome
|
||||
Reference in new issue
Block a user