1
1
#include < HIDPowerDevice.h>
2
2
3
3
#define MINUPDATEINTERVAL 26
4
+ #define CHGDCHPIN 4
5
+ #define RUNSTATUSPIN 5
6
+ #define COMMLOSTPIN 10
7
+ #define BATTSOCPIN A7
4
8
5
9
int iIntTimer=0 ;
6
10
@@ -56,9 +60,9 @@ void setup() {
56
60
// Used for debugging purposes.
57
61
PowerDevice.setOutput (Serial);
58
62
59
- pinMode (4 , INPUT_PULLUP); // ground this pin to simulate power failure.
60
- pinMode (5 , OUTPUT); // output flushing 1 sec indicating that the arduino cycle is running.
61
- pinMode (10 , OUTPUT); // output is on once commuication is lost with the host, otherwise off.
63
+ pinMode (CHGDCHPIN , INPUT_PULLUP); // ground this pin to simulate power failure.
64
+ pinMode (RUNSTATUSPIN , OUTPUT); // output flushing 1 sec indicating that the arduino cycle is running.
65
+ pinMode (COMMLOSTPIN , OUTPUT); // output is on once communication is lost with the host, otherwise off.
62
66
63
67
64
68
PowerDevice.setFeature (HID_PD_PRESENTSTATUS, &iPresentStatus, sizeof (iPresentStatus));
@@ -94,12 +98,12 @@ void loop() {
94
98
95
99
96
100
// *********** Measurements Unit ****************************
97
- bool bCharging = digitalRead (4 );
101
+ bool bCharging = digitalRead (CHGDCHPIN );
98
102
bool bACPresent = bCharging; // TODO - replace with sensor
99
103
bool bDischarging = !bCharging; // TODO - replace with sensor
100
- int iA7 = analogRead (A7 ); // TODO - this is for debug only. Replace with charge estimation
104
+ int iBattSoc = analogRead (BATTSOCPIN ); // TODO - this is for debug only. Replace with charge estimation
101
105
102
- iRemaining = (byte)(round ((float )100 *iA7 /1024 ));
106
+ iRemaining = (byte)(round ((float )100 *iBattSoc /1024 ));
103
107
iRunTimeToEmpty = (uint16_t )round ((float )iAvgTimeToEmpty*iRemaining/100 );
104
108
105
109
// Charging
@@ -158,10 +162,10 @@ void loop() {
158
162
// ************ Delay ****************************************
159
163
delay (1000 );
160
164
iIntTimer++;
161
- digitalWrite (5 , HIGH); // turn the LED on (HIGH is the voltage level);
165
+ digitalWrite (RUNSTATUSPIN , HIGH); // turn the LED on (HIGH is the voltage level);
162
166
delay (1000 );
163
167
iIntTimer++;
164
- digitalWrite (5 , LOW); // turn the LED off;
168
+ digitalWrite (RUNSTATUSPIN , LOW); // turn the LED off;
165
169
166
170
// ************ Check if we are still online ******************
167
171
@@ -176,10 +180,10 @@ void loop() {
176
180
iRes = PowerDevice.sendReport (HID_PD_PRESENTSTATUS, &iPresentStatus, sizeof (iPresentStatus));
177
181
178
182
if (iRes <0 ) {
179
- digitalWrite (10 , HIGH);
183
+ digitalWrite (COMMLOSTPIN , HIGH);
180
184
}
181
185
else
182
- digitalWrite (10 , LOW);
186
+ digitalWrite (COMMLOSTPIN , LOW);
183
187
184
188
iIntTimer = 0 ;
185
189
iPreviousStatus = iPresentStatus;
0 commit comments