diff --git a/code/src/button.ino b/code/src/button.ino index 53cafda5..4f5d6b26 100644 --- a/code/src/button.ino +++ b/code/src/button.ino @@ -55,6 +55,7 @@ void buttonLoop() { } #else +#ifdef BUTTON_PIN #include DebounceEvent button1 = false; @@ -71,4 +72,10 @@ void buttonLoop() { } } +#else + +void buttonSetup() {} +void buttonLoop() {} + +#endif #endif diff --git a/code/src/config/hardware.h b/code/src/config/hardware.h index 64aac77e..0d06161b 100644 --- a/code/src/config/hardware.h +++ b/code/src/config/hardware.h @@ -71,6 +71,10 @@ #define LED_PIN 13 #define LED_PIN_INVERSE 0 +// ----------------------------------------------------------------------------- +// Electrodragon boards +// ----------------------------------------------------------------------------- + #elif defined(ESP_RELAY_BOARD) #define MANUFACTURER "ELECTRODRAGON" diff --git a/code/src/led.ino b/code/src/led.ino new file mode 100644 index 00000000..cd8c1346 --- /dev/null +++ b/code/src/led.ino @@ -0,0 +1,51 @@ +/* + +ESPurna +LED MODULE + +Copyright (C) 2016 by Xose PĂ©rez + +*/ + +// ----------------------------------------------------------------------------- +// LED +// ----------------------------------------------------------------------------- + +#ifdef LED_PIN + +void blink(unsigned long delayOff, unsigned long delayOn) { + static unsigned long next = millis(); + static bool status = HIGH; + if (next < millis()) { + status = !status; + digitalWrite(LED_PIN, LED_PIN_INVERSE ? !status : status); + next += ((status) ? delayOff : delayOn); + } +} + +void showStatus() { + if (wifiConnected()) { + if (WiFi.getMode() == WIFI_AP) { + blink(2000, 2000); + } else { + blink(5000, 500); + } + } else { + blink(500, 500); + } +} + +void ledSetup() { + pinMode(LED_PIN, OUTPUT); +} + +void ledLoop() { + showStatus(); +} + +#else + +void ledSetup() {}; +void ledLoop() {}; + +#endif diff --git a/code/src/main.ino b/code/src/main.ino index 8b5593c6..31fde97b 100644 --- a/code/src/main.ino +++ b/code/src/main.ino @@ -41,31 +41,8 @@ String getIdentifier() { return String(identifier); } -void blink(unsigned long delayOff, unsigned long delayOn) { - static unsigned long next = millis(); - static bool status = HIGH; - if (next < millis()) { - status = !status; - digitalWrite(LED_PIN, LED_PIN_INVERSE ? !status : status); - next += ((status) ? delayOff : delayOn); - } -} - -void showStatus() { - if (wifiConnected()) { - if (WiFi.getMode() == WIFI_AP) { - blink(2000, 2000); - } else { - blink(5000, 500); - } - } else { - blink(500, 500); - } -} - void hardwareSetup() { Serial.begin(SERIAL_BAUDRATE); - pinMode(LED_PIN, OUTPUT); SPIFFS.begin(); } @@ -83,8 +60,6 @@ void getFSVersion(char * buffer) { void hardwareLoop() { - showStatus(); - // Heartbeat static unsigned long last_heartbeat = 0; if (mqttConnected()) { @@ -129,6 +104,7 @@ void setup() { hardwareSetup(); buttonSetup(); + ledSetup(); welcome(); @@ -173,6 +149,7 @@ void loop() { hardwareLoop(); buttonLoop(); + ledLoop(); wifiLoop(); otaLoop(); mqttLoop();