Skip to content

Commit fc58992

Browse files
authored
Merge pull request #6 from rotorman/gpio_naming
feat: improved GPIO naming
2 parents 01bc7ae + 5344229 commit fc58992

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

examples/UPS/UPS.ino

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include <HIDPowerDevice.h>
22

33
#define MINUPDATEINTERVAL 26
4+
#define CHGDCHPIN 4
5+
#define RUNSTATUSPIN 5
6+
#define COMMLOSTPIN 10
7+
#define BATTSOCPIN A7
48

59
int iIntTimer=0;
610

@@ -56,9 +60,9 @@ void setup() {
5660
// Used for debugging purposes.
5761
PowerDevice.setOutput(Serial);
5862

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.
6266

6367

6468
PowerDevice.setFeature(HID_PD_PRESENTSTATUS, &iPresentStatus, sizeof(iPresentStatus));
@@ -94,12 +98,12 @@ void loop() {
9498

9599

96100
//*********** Measurements Unit ****************************
97-
bool bCharging = digitalRead(4);
101+
bool bCharging = digitalRead(CHGDCHPIN);
98102
bool bACPresent = bCharging; // TODO - replace with sensor
99103
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
101105

102-
iRemaining = (byte)(round((float)100*iA7/1024));
106+
iRemaining = (byte)(round((float)100*iBattSoc/1024));
103107
iRunTimeToEmpty = (uint16_t)round((float)iAvgTimeToEmpty*iRemaining/100);
104108

105109
// Charging
@@ -158,10 +162,10 @@ void loop() {
158162
//************ Delay ****************************************
159163
delay(1000);
160164
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);
162166
delay(1000);
163167
iIntTimer++;
164-
digitalWrite(5, LOW); // turn the LED off;
168+
digitalWrite(RUNSTATUSPIN, LOW); // turn the LED off;
165169

166170
//************ Check if we are still online ******************
167171

@@ -176,10 +180,10 @@ void loop() {
176180
iRes = PowerDevice.sendReport(HID_PD_PRESENTSTATUS, &iPresentStatus, sizeof(iPresentStatus));
177181

178182
if(iRes <0 ) {
179-
digitalWrite(10, HIGH);
183+
digitalWrite(COMMLOSTPIN, HIGH);
180184
}
181185
else
182-
digitalWrite(10, LOW);
186+
digitalWrite(COMMLOSTPIN, LOW);
183187

184188
iIntTimer = 0;
185189
iPreviousStatus = iPresentStatus;

0 commit comments

Comments
 (0)