Skip to content

Commit

Permalink
Merge pull request #320 from OpenEVSE/jeremypoulter/issue317
Browse files Browse the repository at this point in the history
Added support for restricting the WiFi status to a single pixel
  • Loading branch information
glynhudson authored Feb 24, 2022
2 parents cd8c355 + ba2bca1 commit ead849a
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 8 deletions.
2 changes: 2 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ src_build_flags =
-D RAPI_PORT=Serial1
-D NEO_PIXEL_PIN=18
-D NEO_PIXEL_LENGTH=2
-D WIFI_PIXEL_NUMBER=1
-D RED_LED=0
-D GREEN_LED=2
-D BLUE_LED=4
Expand Down Expand Up @@ -236,6 +237,7 @@ src_build_flags =
${common.debug_flags}
-D NEO_PIXEL_PIN=17
-D NEO_PIXEL_LENGTH=2
-D WIFI_PIXEL_NUMBER=1
-D WIFI_BUTTON=0
-D WIFI_BUTTON_PRESSED_STATE=LOW
-D RAPI_PORT=Serial
Expand Down
109 changes: 101 additions & 8 deletions src/LedManagerTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,51 @@ unsigned long LedManagerTask::loop(MicroTasks::WakeReason reason)
setNewState(false);
return TEST_LED_TIME;

#ifdef WIFI_PIXEL_NUMBER
case LedState_Evse_State:
case LedState_WiFi_Access_Point_Waiting:
case LedState_WiFi_Access_Point_Connected:
case LedState_WiFi_Client_Connecting:
case LedState_WiFi_Client_Connected:
{
uint8_t lcdCol = _evse->getStateColour();
DBUGVAR(lcdCol);
uint32_t col = status_colour_map[lcdCol];
DBUGVAR(col, HEX);
uint8_t evseR = (col >> 16) & 0xff;
uint8_t evseG = (col >> 8) & 0xff;
uint8_t evseB = col & 0xff;

switch(state)
{
case LedState_Evse_State:
setAllRGB(evseR, evseG, evseB);
return MicroTask.Infinate;

case LedState_WiFi_Access_Point_Waiting:
setEvseAndWifiRGB(evseR, evseG, evseB, flashState ? 255 : 0, flashState ? 255 : 0, 0);
flashState = !flashState;
return CONNECTING_FLASH_TIME;

case LedState_WiFi_Access_Point_Connected:
setEvseAndWifiRGB(evseR, evseG, evseB, flashState ? 255 : 0, 0, flashState ? 255 : 0);
flashState = !flashState;
return CONNECTED_FLASH_TIME;

case LedState_WiFi_Client_Connecting:
setEvseAndWifiRGB(evseR, evseG, evseB, 0, flashState ? 255 : 0, flashState ? 255 : 0);
flashState = !flashState;
return CONNECTING_FLASH_TIME;

case LedState_WiFi_Client_Connected:
setEvseAndWifiRGB(evseR, evseG, evseB, 0, 255, 0);
return MicroTask.Infinate;

default:
break;
}
}
#else
case LedState_Evse_State:
{
uint8_t lcdCol = _evse->getStateColour();
Expand All @@ -193,28 +238,24 @@ unsigned long LedManagerTask::loop(MicroTasks::WakeReason reason)
} return MicroTask.Infinate;

case LedState_WiFi_Access_Point_Waiting:
setAllRGB(flashState ? 255 : 0,
flashState ? 255 : 0,
0);
setAllRGB(flashState ? 255 : 0, flashState ? 255 : 0, 0);
flashState = !flashState;
return CONNECTING_FLASH_TIME;

case LedState_WiFi_Access_Point_Connected:
setAllRGB(0, flashState ? 255 : 0, 0);
setAllRGB(flashState ? 255 : 0, 0, flashState ? 255 : 0);
flashState = !flashState;
return CONNECTED_FLASH_TIME;

case LedState_WiFi_Client_Connecting:
setAllRGB(flashState ? 255 : 0,
flashState ? 255 : 0,
0);
setAllRGB(0, flashState ? 255 : 0, flashState ? 255 : 0);
flashState = !flashState;
return CONNECTING_FLASH_TIME;

case LedState_WiFi_Client_Connected:
setAllRGB(0, 255, 0);
return MicroTask.Infinate;

#endif
}
#endif

Expand Down Expand Up @@ -317,6 +358,58 @@ void LedManagerTask::setAllRGB(uint8_t red, uint8_t green, uint8_t blue)
}
#endif

#if WIFI_PIXEL_NUMBER
void LedManagerTask::setEvseAndWifiRGB(uint8_t evseRed, uint8_t evseGreen, uint8_t evseBlue, uint8_t wifiRed, uint8_t wifiGreen, uint8_t wifiBlue)
{
DBUG("EVSE LED R:");
DBUG(evseRed);
DBUG(" G:");
DBUG(evseGreen);
DBUG(" B:");
DBUGLN(evseBlue);

DBUG("WiFi LED R:");
DBUG(wifiRed);
DBUG(" G:");
DBUG(wifiGreen);
DBUG(" B:");
DBUGLN(wifiBlue);

if(brightness) { // See notes in setBrightness()
evseRed = (evseRed * brightness) >> 8;
evseGreen = (evseGreen * brightness) >> 8;
evseBlue = (evseBlue * brightness) >> 8;
wifiRed = (wifiRed * brightness) >> 8;
wifiGreen = (wifiGreen * brightness) >> 8;
wifiBlue = (wifiBlue * brightness) >> 8;
}

#if defined(NEO_PIXEL_PIN) && defined(NEO_PIXEL_LENGTH)
uint32_t col = strip.gamma32(strip.Color(evseRed, evseGreen, evseBlue));
DBUGVAR(col, HEX);
strip.fill(col);
strip.setPixelColor(WIFI_PIXEL_NUMBER, wifiRed, wifiGreen, wifiBlue);
strip.show();
#endif

#if defined(RED_LED) && defined(GREEN_LED) && defined(BLUE_LED)
analogWrite(RED_LED, pgm_read_byte(&gamma8[wifiRed]));
analogWrite(GREEN_LED, pgm_read_byte(&gamma8[wifiGreen]));
analogWrite(BLUE_LED, pgm_read_byte(&gamma8[wifiBlue]));

#ifdef WIFI_BUTTON_SHARE_LED
#if RED_LED == WIFI_BUTTON_SHARE_LED
buttonShareState = wifiRed;
#elif GREEN_LED == WIFI_BUTTON_SHARE_LED
buttonShareState = wifiGreen;
#elif BLUE_LED == WIFI_BUTTON_SHARE_LED
buttonShareState = wifiBlue;
#endif
#endif
#endif
}
#endif

#ifdef WIFI_LED
void LedManagerTask::setWiFiLed(uint8_t state)
{
Expand Down
3 changes: 3 additions & 0 deletions src/LedManagerTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class LedManagerTask : public MicroTasks::Task
#if RGB_LED
void setAllRGB(uint8_t red, uint8_t green, uint8_t blue);
#endif
#if RGB_LED
void setEvseAndWifiRGB(uint8_t evseRed, uint8_t evseGreen, uint8_t evseBlue, uint8_t wifiRed, uint8_t wifiGreen, uint8_t wifiBlue);
#endif

#ifdef WIFI_LED
void setWiFiLed(uint8_t state);
Expand Down

0 comments on commit ead849a

Please sign in to comment.