Skip to content

Commit d780f33

Browse files
committed
Use new OpenEVSE API
1 parent 7085be6 commit d780f33

File tree

2 files changed

+77
-85
lines changed

2 files changed

+77
-85
lines changed

src/input.cpp

Lines changed: 49 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if defined(ENABLE_DEBUG) && !defined(ENABLE_DEBUG_RAPI)
1+
#if defined(ENABLE_DEBUG) && !defined(ENABLE_DEBUG_INPUT)
22
#undef ENABLE_DEBUG
33
#endif
44

@@ -131,65 +131,56 @@ update_rapi_values() {
131131
});
132132
break;
133133
case 2:
134-
rapiSender.sendCmd("$GS", [](int ret)
134+
OpenEVSE.getStatus([](int ret, uint8_t evse_state, uint32_t session_time, uint8_t pilot_state, uint32_t vflags)
135135
{
136136
if(RAPI_RESPONSE_OK == ret)
137137
{
138-
if(rapiSender.getTokenCnt() >= 3)
139-
{
140-
const char *val = rapiSender.getToken(1);
141-
DBUGVAR(val);
142-
state = strtol(val, NULL, 10);
143-
DBUGVAR(state);
144-
val = rapiSender.getToken(2);
145-
DBUGVAR(val);
146-
elapsed = strtol(val, NULL, 10);
147-
DBUGVAR(elapsed);
148-
149-
#ifdef ENABLE_LEGACY_API
150-
switch (state) {
151-
case 1:
152-
estate = "Not Connected";
153-
break;
154-
case 2:
155-
estate = "EV Connected";
156-
break;
157-
case 3:
158-
estate = "Charging";
159-
break;
160-
case 4:
161-
estate = "Vent Required";
162-
break;
163-
case 5:
164-
estate = "Diode Check Failed";
165-
break;
166-
case 6:
167-
estate = "GFCI Fault";
168-
break;
169-
case 7:
170-
estate = "No Earth Ground";
171-
break;
172-
case 8:
173-
estate = "Stuck Relay";
174-
break;
175-
case 9:
176-
estate = "GFCI Self Test Failed";
177-
break;
178-
case 10:
179-
estate = "Over Temperature";
180-
break;
181-
case 254:
182-
estate = "Sleeping";
183-
break;
184-
case 255:
185-
estate = "Disabled";
186-
break;
187-
default:
188-
estate = "Invalid";
189-
break;
190-
}
191-
#endif
138+
state = evse_state;
139+
elapsed = session_time;
140+
141+
#ifdef ENABLE_LEGACY_API
142+
switch (state) {
143+
case 1:
144+
estate = "Not Connected";
145+
break;
146+
case 2:
147+
estate = "EV Connected";
148+
break;
149+
case 3:
150+
estate = "Charging";
151+
break;
152+
case 4:
153+
estate = "Vent Required";
154+
break;
155+
case 5:
156+
estate = "Diode Check Failed";
157+
break;
158+
case 6:
159+
estate = "GFCI Fault";
160+
break;
161+
case 7:
162+
estate = "No Earth Ground";
163+
break;
164+
case 8:
165+
estate = "Stuck Relay";
166+
break;
167+
case 9:
168+
estate = "GFCI Self Test Failed";
169+
break;
170+
case 10:
171+
estate = "Over Temperature";
172+
break;
173+
case 254:
174+
estate = "Sleeping";
175+
break;
176+
case 255:
177+
estate = "Disabled";
178+
break;
179+
default:
180+
estate = "Invalid";
181+
break;
192182
}
183+
#endif
193184
}
194185
});
195186
break;
@@ -382,6 +373,8 @@ handleRapiRead()
382373

383374
void on_rapi_event()
384375
{
376+
DBUGF("Got ASYNC event %s", rapiSender.getToken(0));
377+
385378
if(!strcmp(rapiSender.getToken(0), "$ST"))
386379
{
387380
const char *val = rapiSender.getToken(1);

src/main.cpp

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -119,30 +119,32 @@ loop() {
119119
rapiSender.loop();
120120
divert_current_loop();
121121

122-
if(OPENEVSE_STATE_STARTING != state &&
123-
OPENEVSE_STATE_INVALID != state)
122+
if(OpenEVSE.isConnected())
124123
{
125-
126-
// Read initial state from OpenEVSE
127-
if (rapi_read == 0)
124+
if(OPENEVSE_STATE_STARTING != state &&
125+
OPENEVSE_STATE_INVALID != state)
128126
{
129-
DBUGLN("first read RAPI values");
130-
handleRapiRead(); //Read all RAPI values
131-
rapi_read=1;
132-
}
127+
// Read initial state from OpenEVSE
128+
if (rapi_read == 0)
129+
{
130+
DBUGLN("first read RAPI values");
131+
handleRapiRead(); //Read all RAPI values
132+
rapi_read=1;
133+
}
133134

134-
// -------------------------------------------------------------------
135-
// Do these things once every 2s
136-
// -------------------------------------------------------------------
137-
if ((millis() - Timer3) >= 2000) {
138-
uint32_t current = HAL.getFreeHeap();
139-
int32_t diff = (int32_t)(last_mem - current);
140-
if(diff != 0) {
141-
DEBUG.printf("Free memory %u - diff %d %d\n", current, diff, start_mem - current);
142-
last_mem = current;
135+
// -------------------------------------------------------------------
136+
// Do these things once every 2s
137+
// -------------------------------------------------------------------
138+
if ((millis() - Timer3) >= 2000) {
139+
uint32_t current = HAL.getFreeHeap();
140+
int32_t diff = (int32_t)(last_mem - current);
141+
if(diff != 0) {
142+
DEBUG.printf("Free memory %u - diff %d %d\n", current, diff, start_mem - current);
143+
last_mem = current;
144+
}
145+
update_rapi_values();
146+
Timer3 = millis();
143147
}
144-
update_rapi_values();
145-
Timer3 = millis();
146148
}
147149
}
148150
else
@@ -151,16 +153,13 @@ loop() {
151153
if ((millis() - Timer3) >= 1000)
152154
{
153155
// Check state the OpenEVSE is in.
154-
rapiSender.sendCmd("$GS", [](int ret) {
155-
if (RAPI_RESPONSE_OK == ret)
156+
OpenEVSE.begin(rapiSender, [](bool connected)
157+
{
158+
if(connected)
156159
{
157-
if(rapiSender.getTokenCnt() >= 3)
158-
{
159-
const char *val = rapiSender.getToken(1);
160-
DBUGVAR(val);
161-
state = strtol(val, NULL, 10);
162-
DBUGVAR(state);
163-
}
160+
OpenEVSE.getStatus([](int ret, uint8_t evse_state, uint32_t session_time, uint8_t pilot_state, uint32_t vflags) {
161+
state = evse_state;
162+
});
164163
} else {
165164
DBUGLN("OpenEVSE not responding or not connected");
166165
}

0 commit comments

Comments
 (0)