Skip to content

Commit 54bcecd

Browse files
authored
Merge pull request #71 from jsphuebner/copilot/change-led-color-codes
Refine LED state mapping and gate flashing blue to active SLAC communication
2 parents 7d151e8 + 062ec0f commit 54bcecd

5 files changed

Lines changed: 132 additions & 209 deletions

File tree

ccs/acOBC.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ static uint8_t previousStateBasicAcCharging = OBC_IDLE;
1919
https://openinverter.org/forum/viewtopic.php?p=66713#p66713
2020
and define
2121
0 invalid. Clara ignores the data.
22-
1 initializing. Clara locks the connector. Green light flashing.
22+
1 initializing. Clara locks the connector. LED green.
2323
2 charging. Clara activates the 1k3 resistor (StateC). LED blue.
2424
3 (pause. Clara ignores this value)
25-
4 charging finished. Clara deactivates the 1k3 resistor. Todo: also unlocking the connector? LED green/blue flashing.
25+
4 charging finished. Clara deactivates the 1k3 resistor. Todo: also unlocking the connector? LED green.
2626
5 charge error. LED red. Todo: Unlocking the connector?
2727
>=6 invalid. Clara ignores the data.
2828
*/
@@ -172,22 +172,16 @@ static void evaluateProximityPilot(void)
172172

173173
uint8_t acOBC_getRGB(void)
174174
{
175-
static uint8_t cycleDivider;
176-
cycleDivider++;
177-
178175
switch (previousStateBasicAcCharging) {
179176
case OBC_IDLE:
180-
return (cycleDivider & 2) ? RGB_BLUE : RGB_OFF;
181177
case OBC_LOCK:
182-
return RGB_BLUE;
183-
case OBC_CHARGE:
184-
return (cycleDivider & 2) ? RGB_GREEN : RGB_OFF;
185178
case OBC_COMPLETE:
186-
return RGB_CYAN;
179+
return RGB_GREEN; /* plugged in / ready (OBC_IDLE is treated as ready in this mapping) */
180+
case OBC_CHARGE:
181+
return RGB_BLUE; /* charging ongoing */
187182
case OBC_ERROR:
188-
return RGB_RED;
189-
default: //Every other state, flash red
190-
return (cycleDivider & 1) ? RGB_RED : RGB_OFF;
183+
default:
184+
return RGB_RED; /* error */
191185
}
192186
}
193187

ccs/hardwareInterface.cpp

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static void hwIf_handleContactorRequests(void)
233233
dutyContactor1 = 0;
234234
ContactorOnTimer1=0;
235235
}
236-
236+
237237
if (ContactorRequest & 2) {
238238
/* contactor 2 is requested */
239239
if (ContactorOnTimer2==0) {
@@ -254,85 +254,69 @@ static void hwIf_handleContactorRequests(void)
254254

255255
static void handleApplicationRGBLeds(void)
256256
{
257-
LedBlinkDivider++;
257+
LedBlinkDivider++; /* Called every 30ms, so (LedBlinkDivider & 1) toggles every cycle. */
258258
if (acOBC_isBasicAcCharging()) {
259259
/* In case of analog AC charging, we take the LED state from the acOBC handler, and do not care for the PLC modem state. */
260260
hardwareInterface_setRGB(acOBC_getRGB());
261261
return;
262262
}
263-
if (checkpointNumber<100)
263+
if (checkpointNumber<150)
264264
{
265265
/* modem is sleeping (or defective), or modem search ongoing */
266266
hardwareInterface_setRGB(RGB_WHITE);
267-
return;
268-
}
269-
else if ((checkpointNumber>=100) && (checkpointNumber<150))
270-
{
271-
/* One modem detected. This is the normal "ready" case. */
272-
hardwareInterface_setRGB(RGB_GREEN);
273267
}
274-
else if ((checkpointNumber>150) && (checkpointNumber<=530))
268+
else if (checkpointNumber<400)
275269
{
276-
if (LedBlinkDivider & 4)
270+
/* SLAC/SDP etc. Flash green only when at least SLAC is ongoing. */
271+
if (connMgr_getConnectionLevel() >= CONNLEVEL_15_SLAC_ONGOING)
277272
{
278-
hardwareInterface_setRGB(RGB_GREEN);
273+
if (LedBlinkDivider & 1)
274+
{
275+
hardwareInterface_setRGB(RGB_GREEN);
276+
}
277+
else
278+
{
279+
hardwareInterface_setRGB(RGB_OFF);
280+
}
279281
}
280282
else
281-
{
282-
hardwareInterface_setRGB(RGB_OFF);
283-
}
284-
}
285-
else if ((checkpointNumber>=540) /* Auth finished */ && (checkpointNumber<560 /* CableCheck */))
286-
{
287-
if (LedBlinkDivider & 2)
288283
{
289284
hardwareInterface_setRGB(RGB_GREEN);
290285
}
291-
else
292-
{
293-
hardwareInterface_setRGB(RGB_OFF);
294-
}
295286
}
296-
else if (checkpointNumber>=560 /* CableCheck */)
287+
else if (checkpointNumber<540)
297288
{
298-
if (LedBlinkDivider & 2)
289+
/* up to ChargeParameterDiscovery: green + flashing blue */
290+
if (LedBlinkDivider & 1)
299291
{
300-
hardwareInterface_setRGB(RGB_BLUE);
292+
hardwareInterface_setRGB(RGB_CYAN);
301293
}
302294
else
303295
{
304-
hardwareInterface_setRGB(RGB_OFF);
296+
hardwareInterface_setRGB(RGB_GREEN);
305297
}
306298
}
307-
else if ((checkpointNumber>=570 /* PreCharge */) && (checkpointNumber<700 /* charge loop start */))
299+
else if (checkpointNumber<700)
308300
{
309-
if (LedBlinkDivider & 1) /* very fast flashing during the PreCharge */
301+
/* up to/including WaitForPowerDeliveryResponse: flashing blue */
302+
if (LedBlinkDivider & 3)
310303
{
311-
hardwareInterface_setRGB(RGB_BLUE);
304+
hardwareInterface_setRGB(RGB_OFF);
312305
}
313306
else
314307
{
315-
hardwareInterface_setRGB(RGB_OFF);
308+
hardwareInterface_setRGB(RGB_BLUE);
316309
}
317310
}
318-
else if ((checkpointNumber>=700 /* charge loop */) && (checkpointNumber<800 /* charge loop */))
311+
else if (checkpointNumber<800)
319312
{
313+
/* CurrentDemand charging loop */
320314
hardwareInterface_setRGB(RGB_BLUE);
321315
}
322-
else if ((checkpointNumber>=800 /* charge end */) && (checkpointNumber<900 /* welding detection */))
323-
{
324-
if (LedBlinkDivider & 1)
325-
{
326-
hardwareInterface_setRGB(RGB_BLUE);
327-
}
328-
else
329-
{
330-
hardwareInterface_setRGB(RGB_GREEN);
331-
}
332-
}
333-
else if (checkpointNumber==900 /* session stop */)
316+
else if (checkpointNumber<=1000)
334317
{
335-
hardwareInterface_setRGB(RGB_CYAN);
318+
/* plugged in / ready (not actively charging) */
319+
hardwareInterface_setRGB(RGB_GREEN);
336320
}
337321
else if (checkpointNumber>1000) /* error states */
338322
{
@@ -474,7 +458,7 @@ void hardwareInterface_cyclic(void)
474458
/* make an exception: the lock/unlock actuator test shall always be possible, to be able to test also
475459
while the plug is inserted. */
476460
if ((Param::GetInt(Param::ActuatorTest)==TEST_CLOSELOCK) ||
477-
(Param::GetInt(Param::ActuatorTest)==TEST_OPENLOCK)) {
461+
(Param::GetInt(Param::ActuatorTest)==TEST_OPENLOCK)) {
478462
blActuatorTestAllowed = 1;
479463
}
480464
if (blActuatorTestAllowed) {
@@ -503,5 +487,3 @@ void hardwareInterface_init(void)
503487
hardwareInteface_setHBridge(0, 0); /* both low */
504488
hardwareInteface_setContactorPwm(0, 0); /* both off */
505489
}
506-
507-

0 commit comments

Comments
 (0)