Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken HIDPowerDevice_::sendDate method #28

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions examples/UPS/UPS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ uint16_t iAvgTimeToEmpty = 7200;
uint16_t iRemainTimeLimit = 600;
int16_t iDelayBe4Reboot = -1;
int16_t iDelayBe4ShutDown = -1;
uint16_t iManufacturerDate = 0; // initialized in setup function
byte iAudibleAlarmCtrl = 2; // 1 - Disabled, 2 - Enabled, 3 - Muted


Expand Down Expand Up @@ -92,9 +91,7 @@ void setup() {
PowerDevice.setFeature(HID_PD_CPCTYGRANULARITY1, &bCapacityGranularity1, sizeof(bCapacityGranularity1));
PowerDevice.setFeature(HID_PD_CPCTYGRANULARITY2, &bCapacityGranularity2, sizeof(bCapacityGranularity2));

uint16_t year = 2024, month = 10, day = 12;
iManufacturerDate = (year - 1980)*512 + month*32 + day; // from 4.2.6 Battery Settings in "Universal Serial Bus Usage Tables for HID Power Devices"
PowerDevice.setFeature(HID_PD_MANUFACTUREDATE, &iManufacturerDate, sizeof(iManufacturerDate));
PowerDevice.sendManufacturerDate(2024, 10, 12);
}

void loop() {
Expand Down
6 changes: 3 additions & 3 deletions src/HIDPowerDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ void HIDPowerDevice_::setSerial(const char* s) {
void HIDPowerDevice_::end(void) {
}

int HIDPowerDevice_::sendDate(uint16_t id, uint16_t year, uint8_t month, uint8_t day) {
uint16_t bval = (year - 1980)*512 + month * 32 + day;
return HID().SendReport(id, &bval, sizeof (bval));
int HIDPowerDevice_::sendManufacturerDate(uint16_t year, uint8_t month, uint8_t day) {
iManufacturerDate = (year - 1980)*512 + month * 32 + day; // from 4.2.6 Battery Settings in "Universal Serial Bus Usage Tables for HID Power Devices"
return HID().SetFeature(HID_PD_MANUFACTUREDATE, &iManufacturerDate, sizeof(iManufacturerDate));
}

int HIDPowerDevice_::sendReport(uint16_t id, const void* bval, int len) {
Expand Down
4 changes: 3 additions & 1 deletion src/HIDPowerDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,15 @@ class HIDPowerDevice_ {

void end(void);

int sendDate(uint16_t id, uint16_t year, uint8_t month, uint8_t day);
int sendManufacturerDate(uint16_t year, uint8_t month, uint8_t day);
int sendReport(uint16_t id, const void* bval, int len);

int setFeature(uint16_t id, const void* data, int len);

int setStringFeature(uint8_t id, const uint8_t* index, const char* data);

private:
uint16_t iManufacturerDate = 0;
};

extern HIDPowerDevice_ PowerDevice;
Expand Down