Skip to content

Commit

Permalink
Allow to configure all LEDs from UI (#1429)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoseperez committed Mar 21, 2019
1 parent 13fb5fa commit 0987e01
Show file tree
Hide file tree
Showing 18 changed files with 19,366 additions and 19,199 deletions.
2 changes: 1 addition & 1 deletion code/espurna/config/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
#define RELAY1_PIN 5
#define RELAY1_TYPE RELAY_TYPE_NORMAL

// Light RGBW
// LED
#define LED1_PIN 2
#define LED1_PIN_INVERSE 1

Expand Down
Binary file modified code/espurna/data/index.all.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.light.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.lightfox.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.rfbridge.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.rfm69.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.sensor.html.gz
Binary file not shown.
Binary file modified code/espurna/data/index.small.html.gz
Binary file not shown.
48 changes: 33 additions & 15 deletions code/espurna/led.ino
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ void _ledMode(unsigned char id, unsigned char mode) {
_leds[id].mode = mode;
}

unsigned char _ledRelay(unsigned char id) {
if (id >= _ledCount()) return false;
return _leds[id].relay;
}

void _ledRelay(unsigned char id, unsigned char relay) {
if (id >= _ledCount()) return;
_leds[id].relay = relay;
}

void _ledBlink(unsigned char id, unsigned long delayOff, unsigned long delayOn) {
if (id >= _ledCount()) return;
static unsigned long next = millis();
Expand All @@ -68,7 +78,12 @@ bool _ledWebSocketOnReceive(const char * key, JsonVariant& value) {
void _ledWebSocketOnSend(JsonObject& root) {
if (_ledCount() == 0) return;
root["ledVisible"] = 1;
root["ledMode0"] = _ledMode(0);
JsonArray& leds = root.createNestedArray("ledConfig");
for (byte i=0; i<_ledCount(); i++) {
JsonObject& led = leds.createNestedObject();
led["mode"] = getSetting("ledMode", i, "").toInt();
led["relay"] = getSetting("ledRelay", i, "").toInt();
}
}

#endif
Expand Down Expand Up @@ -133,6 +148,7 @@ unsigned char _ledCount() {
void _ledConfigure() {
for (unsigned int i=0; i < _leds.size(); i++) {
_ledMode(i, getSetting("ledMode", i, _ledMode(i)).toInt());
_ledRelay(i, getSetting("ledRelay", i, _ledRelay(i)).toInt());
}
_led_update = true;
}
Expand All @@ -146,32 +162,34 @@ void ledUpdate(bool value) {
void ledSetup() {

#if LED1_PIN != GPIO_NONE
_leds.push_back((led_t) { LED1_PIN, LED1_PIN_INVERSE, LED1_MODE, LED1_RELAY });
_leds.push_back((led_t) { LED1_PIN, LED1_PIN_INVERSE, LED1_MODE, LED1_RELAY - 1 });
#endif
#if LED2_PIN != GPIO_NONE
_leds.push_back((led_t) { LED2_PIN, LED2_PIN_INVERSE, LED2_MODE, LED2_RELAY });
_leds.push_back((led_t) { LED2_PIN, LED2_PIN_INVERSE, LED2_MODE, LED2_RELAY - 1 });
#endif
#if LED3_PIN != GPIO_NONE
_leds.push_back((led_t) { LED3_PIN, LED3_PIN_INVERSE, LED3_MODE, LED3_RELAY });
_leds.push_back((led_t) { LED3_PIN, LED3_PIN_INVERSE, LED3_MODE, LED3_RELAY - 1 });
#endif
#if LED4_PIN != GPIO_NONE
_leds.push_back((led_t) { LED4_PIN, LED4_PIN_INVERSE, LED4_MODE, LED4_RELAY });
_leds.push_back((led_t) { LED4_PIN, LED4_PIN_INVERSE, LED4_MODE, LED4_RELAY - 1 });
#endif
#if LED5_PIN != GPIO_NONE
_leds.push_back((led_t) { LED5_PIN, LED5_PIN_INVERSE, LED5_MODE, LED5_RELAY });
_leds.push_back((led_t) { LED5_PIN, LED5_PIN_INVERSE, LED5_MODE, LED5_RELAY - 1 });
#endif
#if LED6_PIN != GPIO_NONE
_leds.push_back((led_t) { LED6_PIN, LED6_PIN_INVERSE, LED6_MODE, LED6_RELAY });
_leds.push_back((led_t) { LED6_PIN, LED6_PIN_INVERSE, LED6_MODE, LED6_RELAY - 1 });
#endif
#if LED7_PIN != GPIO_NONE
_leds.push_back((led_t) { LED7_PIN, LED7_PIN_INVERSE, LED7_MODE, LED7_RELAY });
_leds.push_back((led_t) { LED7_PIN, LED7_PIN_INVERSE, LED7_MODE, LED7_RELAY - 1 });
#endif
#if LED8_PIN != GPIO_NONE
_leds.push_back((led_t) { LED8_PIN, LED8_PIN_INVERSE, LED8_MODE, LED8_RELAY });
_leds.push_back((led_t) { LED8_PIN, LED8_PIN_INVERSE, LED8_MODE, LED8_RELAY - 1 });
#endif

for (unsigned int i=0; i < _leds.size(); i++) {
pinMode(_leds[i].pin, OUTPUT);
setSetting("ledMode", i, _leds[i].mode);
setSetting("ledRelay", i, _leds[i].relay);
_ledStatus(i, false);
}

Expand Down Expand Up @@ -225,13 +243,13 @@ void ledLoop() {
if (wifi_state & WIFI_STATE_WPS || wifi_state & WIFI_STATE_SMARTCONFIG) {
_ledBlink(i, 100, 100);
} else if (wifi_state & WIFI_STATE_STA) {
if (relayStatus(_leds[i].relay-1)) {
if (relayStatus(_leds[i].relay)) {
_ledBlink(i, 4900, 100);
} else {
_ledBlink(i, 100, 4900);
}
} else if (wifi_state & WIFI_STATE_AP) {
if (relayStatus(_leds[i].relay-1)) {
if (relayStatus(_leds[i].relay)) {
_ledBlink(i, 900, 100);
} else {
_ledBlink(i, 100, 900);
Expand All @@ -247,13 +265,13 @@ void ledLoop() {
if (wifi_state & WIFI_STATE_WPS || wifi_state & WIFI_STATE_SMARTCONFIG) {
_ledBlink(i, 100, 100);
} else if (wifi_state & WIFI_STATE_STA) {
if (relayStatus(_leds[i].relay-1)) {
if (relayStatus(_leds[i].relay)) {
_ledBlink(i, 100, 4900);
} else {
_ledBlink(i, 4900, 100);
}
} else if (wifi_state & WIFI_STATE_AP) {
if (relayStatus(_leds[i].relay-1)) {
if (relayStatus(_leds[i].relay)) {
_ledBlink(i, 100, 900);
} else {
_ledBlink(i, 900, 100);
Expand All @@ -268,11 +286,11 @@ void ledLoop() {
if (!_led_update) continue;

if (_ledMode(i) == LED_MODE_FOLLOW) {
_ledStatus(i, relayStatus(_leds[i].relay-1));
_ledStatus(i, relayStatus(_leds[i].relay));
}

if (_ledMode(i) == LED_MODE_FOLLOW_INVERSE) {
_ledStatus(i, !relayStatus(_leds[i].relay-1));
_ledStatus(i, !relayStatus(_leds[i].relay));
}

if (_ledMode(i) == LED_MODE_FINDME) {
Expand Down
Loading

1 comment on commit 0987e01

@reaper7
Copy link
Contributor

@reaper7 reaper7 commented on 0987e01 Mar 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something went wrong with latest commits,
problem with missing tabs has returned again.
I have new LED tab but I do not have: HASS, MQTT, RF
When I back to commit 3b21e59 everything is fine again!

I see that others also have this problem: #1654

Please sign in to comment.