Skip to content

Commit 051042b

Browse files
committed
Initial commit
1 parent 77fbf71 commit 051042b

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

examples/UPS/UPS.ino

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include <HIDPowerDevice.h>
2+
3+
void setup() {
4+
// put your setup code here, to run once:
5+
PowerDevice.begin();
6+
pinMode(4, INPUT_PULLUP);
7+
8+
Serial.begin(9600);
9+
10+
}
11+
12+
void loop() {
13+
//put your main code here, to run repeatedly:
14+
15+
delay(2000);
16+
17+
uint8_t raw[USB_EP_SIZE]={0};
18+
// Serial.println(USB_Available(HID_RX));
19+
if(Serial.available()) {
20+
21+
int incomingByte = Serial.read();
22+
Serial.println(incomingByte, DEC);
23+
}
24+
25+
if(USB_Available(HID_RX)) {
26+
Serial.print("USB_Available\t"); Serial.println(USB_Available(HID_RX));
27+
}
28+
29+
// return;
30+
31+
PowerDevice.sendByte(HID_PD_IPRODUCT, IPRODUCT);
32+
PowerDevice.sendByte(HID_PD_MANUFACTURER, IMANUFACTURER);
33+
PowerDevice.sendByte(HID_PD_SERIAL, ISERIAL);
34+
35+
PowerDevice.sendByte(HID_PD_RECHARGEABLE, 1); // should be 1 (Rechargable). Equivalent to "Battery Technology" in ACPI.
36+
PowerDevice.sendByte(HID_PD_CAPACITYMODE, 0);
37+
PowerDevice.sendInt32(HID_PD_FULLCHRGECAPACITY, 43200); //12 Ah (in Asec)
38+
PowerDevice.sendInt32(HID_PD_DESIGNCAPACITY, 43200); //12 Ah (in Asec)
39+
PowerDevice.sendInt16(HID_PD_CONFIGVOLTAGE, 13800); //13.8V
40+
PowerDevice.sendInt32(HID_PD_REMNCAPACITYLIMIT, 2160); //5% is set to threshold
41+
PowerDevice.sendByte(HID_PD_CPCTYGRANULARITY1, 100);
42+
PowerDevice.sendByte(HID_PD_CPCTYGRANULARITY2, 50);
43+
44+
byte bRemaining = 75;
45+
46+
PowerDevice.sendByte(HID_PD_REMAININGCAPACITY, bRemaining);
47+
48+
int iPresentStatus = 0;
49+
50+
// Charging
51+
bool bCharging = digitalRead(4);
52+
if(bCharging) {
53+
bitSet(iPresentStatus,0);
54+
// Fully Charged
55+
if(bRemaining == 100) bitSet(iPresentStatus, 12);
56+
57+
}
58+
// Dischargig
59+
else {
60+
bitSet(iPresentStatus,1);
61+
// Fully Discharged
62+
if(bRemaining = 1) bitSet(iPresentStatus, 13);
63+
}
64+
65+
// Need Replacement
66+
bitSet(iPresentStatus, 9);
67+
// Overload
68+
bitSet(iPresentStatus, 10);
69+
70+
71+
PowerDevice.sendInt16(HID_PD_PRESENTSTATUS, iPresentStatus);
72+
if(bCharging) {
73+
PowerDevice.sendInt16(HID_PD_CURRENT, 500);
74+
}
75+
else {
76+
PowerDevice.sendInt16(HID_PD_CURRENT, -500);
77+
PowerDevice.sendInt16(HID_PD_RUNTIMETOEMPTY, 3600);
78+
}
79+
80+
PowerDevice.sendInt16(HID_PD_VOLTAGE, 12000);
81+
82+
}

0 commit comments

Comments
 (0)