Browse Source

Move LED control to its own module

fastled
Xose Pérez 8 years ago
parent
commit
9176240a0f
4 changed files with 64 additions and 25 deletions
  1. +7
    -0
      code/src/button.ino
  2. +4
    -0
      code/src/config/hardware.h
  3. +51
    -0
      code/src/led.ino
  4. +2
    -25
      code/src/main.ino

+ 7
- 0
code/src/button.ino View File

@ -55,6 +55,7 @@ void buttonLoop() {
} }
#else #else
#ifdef BUTTON_PIN
#include <DebounceEvent.h> #include <DebounceEvent.h>
DebounceEvent button1 = false; DebounceEvent button1 = false;
@ -71,4 +72,10 @@ void buttonLoop() {
} }
} }
#else
void buttonSetup() {}
void buttonLoop() {}
#endif
#endif #endif

+ 4
- 0
code/src/config/hardware.h View File

@ -71,6 +71,10 @@
#define LED_PIN 13 #define LED_PIN 13
#define LED_PIN_INVERSE 0 #define LED_PIN_INVERSE 0
// -----------------------------------------------------------------------------
// Electrodragon boards
// -----------------------------------------------------------------------------
#elif defined(ESP_RELAY_BOARD) #elif defined(ESP_RELAY_BOARD)
#define MANUFACTURER "ELECTRODRAGON" #define MANUFACTURER "ELECTRODRAGON"


+ 51
- 0
code/src/led.ino View File

@ -0,0 +1,51 @@
/*
ESPurna
LED MODULE
Copyright (C) 2016 by Xose Pérez <xose dot perez at gmail dot com>
*/
// -----------------------------------------------------------------------------
// 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

+ 2
- 25
code/src/main.ino View File

@ -41,31 +41,8 @@ String getIdentifier() {
return String(identifier); 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() { void hardwareSetup() {
Serial.begin(SERIAL_BAUDRATE); Serial.begin(SERIAL_BAUDRATE);
pinMode(LED_PIN, OUTPUT);
SPIFFS.begin(); SPIFFS.begin();
} }
@ -83,8 +60,6 @@ void getFSVersion(char * buffer) {
void hardwareLoop() { void hardwareLoop() {
showStatus();
// Heartbeat // Heartbeat
static unsigned long last_heartbeat = 0; static unsigned long last_heartbeat = 0;
if (mqttConnected()) { if (mqttConnected()) {
@ -129,6 +104,7 @@ void setup() {
hardwareSetup(); hardwareSetup();
buttonSetup(); buttonSetup();
ledSetup();
welcome(); welcome();
@ -173,6 +149,7 @@ void loop() {
hardwareLoop(); hardwareLoop();
buttonLoop(); buttonLoop();
ledLoop();
wifiLoop(); wifiLoop();
otaLoop(); otaLoop();
mqttLoop(); mqttLoop();


Loading…
Cancel
Save