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

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

@ -71,6 +71,10 @@
#define LED_PIN 13
#define LED_PIN_INVERSE 0
// -----------------------------------------------------------------------------
// Electrodragon boards
// -----------------------------------------------------------------------------
#elif defined(ESP_RELAY_BOARD)
#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);
}
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();


Loading…
Cancel
Save