2020-03-28 13:30:51 +01:00
# ifndef WLED_H
# define WLED_H
/*
Main sketch , global variable declarations
2020-03-30 10:21:47 +02:00
@ title WLED project sketch
@ version 0.9 .1
@ author Christian Schwinne
2020-03-28 13:30:51 +01:00
*/
2020-03-30 10:21:47 +02:00
// ESP8266-01 (blue) got too little storage space to work with all features of WLED. To use it, you must use ESP8266 Arduino Core v2.4.2 and the setting 512K(No SPIFFS).
2020-03-28 13:30:51 +01:00
2020-03-30 10:21:47 +02:00
// ESP8266-01 (black) has 1MB flash and can thus fit the whole program. Use 1M(64K SPIFFS).
// Uncomment some of the following lines to disable features to compile for ESP8266-01 (max flash size 434kB):
// Alternatively, with platformio pass your chosen flags to your custom build target in platformio.ini.override
2020-03-28 13:30:51 +01:00
2020-03-30 10:21:47 +02:00
// You are required to disable over-the-air updates:
2020-03-28 13:30:51 +01:00
//#define WLED_DISABLE_OTA //saves 14kb
2020-03-30 10:21:47 +02:00
// You need to choose some of these features to disable:
2020-03-28 13:30:51 +01:00
//#define WLED_DISABLE_ALEXA //saves 11kb
//#define WLED_DISABLE_BLYNK //saves 6kb
//#define WLED_DISABLE_CRONIXIE //saves 3kb
//#define WLED_DISABLE_HUESYNC //saves 4kb
//#define WLED_DISABLE_INFRARED //there is no pin left for this on ESP8266-01, saves 12kb
2020-03-30 10:21:47 +02:00
# define WLED_ENABLE_MQTT //saves 12kb
# define WLED_ENABLE_ADALIGHT //saves 500b only
2020-03-28 13:30:51 +01:00
//#define WLED_ENABLE_DMX //uses 3.5kb
# define WLED_DISABLE_FILESYSTEM //SPIFFS is not used by any WLED feature yet
//#define WLED_ENABLE_FS_SERVING //Enable sending html file from SPIFFS before serving progmem version
//#define WLED_ENABLE_FS_EDITOR //enable /edit page for editing SPIFFS content. Will also be disabled with OTA lock
2020-03-30 10:21:47 +02:00
// to toggle usb serial debug (un)comment the following line
2020-03-28 13:30:51 +01:00
//#define WLED_DEBUG
2020-03-30 10:21:47 +02:00
// Library inclusions.
2020-03-28 13:30:51 +01:00
# include <Arduino.h>
# ifdef ESP8266
# include <ESP8266WiFi.h>
# include <ESP8266mDNS.h>
# include <ESPAsyncTCP.h>
extern " C "
{
# include <user_interface.h>
}
# else //ESP32
# include <WiFi.h>
# include "esp_wifi.h"
# include <ESPmDNS.h>
# include <AsyncTCP.h>
# include "SPIFFS.h"
# endif
# include <ESPAsyncWebServer.h>
# include <EEPROM.h>
# include <WiFiUdp.h>
# include <DNSServer.h>
# ifndef WLED_DISABLE_OTA
# include <ArduinoOTA.h>
# endif
# include <SPIFFSEditor.h>
# include "src/dependencies/time/TimeLib.h"
# include "src/dependencies/timezone/Timezone.h"
# ifndef WLED_DISABLE_ALEXA
# define ESPALEXA_ASYNC
# define ESPALEXA_NO_SUBPAGE
# define ESPALEXA_MAXDEVICES 1
// #define ESPALEXA_DEBUG
# include "src/dependencies/espalexa/Espalexa.h"
# endif
# ifndef WLED_DISABLE_BLYNK
# include "src/dependencies/blynk/BlynkSimpleEsp.h"
# endif
# include "src/dependencies/e131/ESPAsyncE131.h"
# include "src/dependencies/async-mqtt-client/AsyncMqttClient.h"
# include "src/dependencies/json/AsyncJson-v6.h"
# include "src/dependencies/json/ArduinoJson-v6.h"
# include "html_ui.h"
# include "html_settings.h"
# include "html_other.h"
# include "FX.h"
# include "ir_codes.h"
# include "const.h"
# ifndef CLIENT_SSID
# define CLIENT_SSID DEFAULT_CLIENT_SSID
# endif
# ifndef CLIENT_PASS
# define CLIENT_PASS ""
# endif
# if IR_PIN < 0
# ifndef WLED_DISABLE_INFRARED
# define WLED_DISABLE_INFRARED
# endif
# endif
# ifndef WLED_DISABLE_INFRARED
# include <IRremoteESP8266.h>
# include <IRrecv.h>
# include <IRutils.h>
# endif
// remove flicker because PWM signal of RGB channels can become out of phase
# if defined(WLED_USE_ANALOG_LEDS) && defined(ESP8266)
# include "src/dependencies/arduino/core_esp8266_waveform.h"
# endif
// enable additional debug output
# ifdef WLED_DEBUG
# ifndef ESP8266
# include <rom/rtc.h>
# endif
# endif
2020-03-30 10:21:47 +02:00
// version code in format yymmddb (b = daily build)
2020-03-30 10:51:56 +02:00
# define VERSION 2003301
2020-03-28 13:30:51 +01:00
2020-03-30 10:21:47 +02:00
// Global external variable declaration. See wled.cpp for definitions and comments.
2020-03-28 13:30:51 +01:00
extern char versionString [ ] ;
extern char apPass [ 65 ] ;
extern char otaPass [ 33 ] ;
2020-03-30 10:21:47 +02:00
extern byte auxDefaultState ;
extern byte auxTriggeredState ;
extern char ntpServerName [ 33 ] ;
2020-03-28 13:30:51 +01:00
extern char clientSSID [ 33 ] ;
extern char clientPass [ 65 ] ;
2020-03-30 10:21:47 +02:00
extern char cmDNS [ 33 ] ;
extern char apSSID [ 33 ] ;
extern byte apChannel ;
extern byte apHide ;
extern byte apBehavior ;
extern IPAddress staticIP ;
extern IPAddress staticGateway ;
extern IPAddress staticSubnet ;
extern bool noWifiSleep ;
extern uint16_t ledCount ;
extern bool useRGBW ;
# define ABL_MILLIAMPS_DEFAULT 850;
extern bool turnOnAtBoot ;
extern byte bootPreset ;
extern byte col [ ] ;
extern byte colSec [ ] ;
extern byte briS ;
extern byte nightlightTargetBri ;
2020-03-28 13:30:51 +01:00
extern byte nightlightDelayMins ;
2020-03-30 10:21:47 +02:00
extern bool nightlightFade ;
extern bool nightlightColorFade ;
extern bool fadeTransition ;
extern uint16_t transitionDelay ;
extern bool skipFirstLed ;
extern byte briMultiplier ;
extern char serverDescription [ 33 ] ;
extern bool syncToggleReceive ;
2020-03-28 13:30:51 +01:00
extern bool buttonEnabled ;
2020-03-30 10:21:47 +02:00
extern byte irEnabled ;
extern uint16_t udpPort ;
extern uint16_t udpRgbPort ;
extern bool receiveNotificationBrightness ;
extern bool receiveNotificationColor ;
extern bool receiveNotificationEffects ;
extern bool notifyDirect ;
extern bool notifyButton ;
extern bool notifyAlexa ;
extern bool notifyMacro ;
extern bool notifyHue ;
extern bool notifyTwice ;
extern bool alexaEnabled ;
extern char alexaInvocationName [ 33 ] ;
extern char blynkApiKey [ 36 ] ;
extern uint16_t realtimeTimeoutMs ;
extern int arlsOffset ;
extern bool receiveDirect ;
extern bool arlsDisableGammaCorrection ;
extern bool arlsForceMaxBri ;
2020-03-28 13:30:51 +01:00
# define E131_MAX_UNIVERSE_COUNT 9
2020-03-30 10:21:47 +02:00
extern uint16_t e131Universe ;
extern uint8_t DMXMode ;
extern uint16_t DMXAddress ;
extern uint8_t DMXOldDimmer ;
extern uint8_t e131LastSequenceNumber [ E131_MAX_UNIVERSE_COUNT ] ;
extern bool e131Multicast ;
extern bool e131SkipOutOfSequence ;
2020-03-28 13:30:51 +01:00
extern bool mqttEnabled ;
2020-03-30 10:21:47 +02:00
extern char mqttDeviceTopic [ 33 ] ;
extern char mqttGroupTopic [ 33 ] ;
extern char mqttServer [ 33 ] ;
extern char mqttUser [ 41 ] ;
extern char mqttPass [ 41 ] ;
extern char mqttClientID [ 41 ] ;
2020-03-28 13:30:51 +01:00
extern uint16_t mqttPort ;
2020-03-30 10:21:47 +02:00
extern bool huePollingEnabled ;
extern uint16_t huePollIntervalMs ;
extern char hueApiKey [ 47 ] ;
extern byte huePollLightId ;
extern IPAddress hueIP ;
2020-03-28 13:30:51 +01:00
extern bool hueApplyOnOff ;
extern bool hueApplyBri ;
extern bool hueApplyColor ;
2020-03-30 10:21:47 +02:00
extern bool ntpEnabled ;
extern bool useAMPM ;
extern byte currentTimezone ;
extern int utcOffsetSecs ;
extern byte overlayDefault ;
extern byte overlayMin ;
2020-03-28 13:30:51 +01:00
extern byte overlayMax ;
2020-03-30 10:21:47 +02:00
extern byte analogClock12pixel ;
extern bool analogClockSecondsTrail ;
extern bool analogClock5MinuteMarks ;
extern char cronixieDisplay [ 7 ] ;
extern bool cronixieBacklight ;
extern bool countdownMode ;
extern byte countdownYear , countdownMonth ;
2020-03-28 13:30:51 +01:00
extern byte countdownDay , countdownHour ;
extern byte countdownMin , countdownSec ;
2020-03-30 10:21:47 +02:00
extern byte macroBoot ;
extern byte macroNl ;
2020-03-28 13:30:51 +01:00
extern byte macroCountdown ;
extern byte macroAlexaOn , macroAlexaOff ;
extern byte macroButton , macroLongPress , macroDoublePress ;
2020-03-30 10:21:47 +02:00
extern bool otaLock ;
extern bool wifiLock ;
extern bool aOtaEnabled ;
2020-03-28 13:30:51 +01:00
extern uint16_t userVar0 , userVar1 ;
# ifdef WLED_ENABLE_DMX
2020-03-30 10:21:47 +02:00
extern byte DMXChannels ;
2020-03-28 13:30:51 +01:00
extern byte DMXFixtureMap [ 15 ] ;
2020-03-30 10:21:47 +02:00
extern
extern uint16_t DMXGap ;
extern uint16_t DMXStart ;
2020-03-28 13:30:51 +01:00
# endif
extern bool apActive ;
extern bool forceReconnect ;
extern uint32_t lastReconnectAttempt ;
extern bool interfacesInited ;
extern bool wasConnected ;
2020-03-30 10:21:47 +02:00
extern byte colOld [ ] ;
extern byte colT [ ] ;
extern byte colIT [ ] ;
2020-03-28 13:30:51 +01:00
extern byte colSecT [ ] ;
extern byte colSecOld [ ] ;
extern byte colSecIT [ ] ;
2020-03-30 10:21:47 +02:00
extern byte lastRandomIndex ;
2020-03-28 13:30:51 +01:00
extern bool transitionActive ;
extern uint16_t transitionDelayDefault ;
extern uint16_t transitionDelayTemp ;
extern unsigned long transitionStartTime ;
2020-03-30 10:21:47 +02:00
extern float tperLast ;
2020-03-28 13:30:51 +01:00
extern bool jsonTransitionOnce ;
extern bool nightlightActive ;
extern bool nightlightActiveOld ;
extern uint32_t nightlightDelayMs ;
extern uint8_t nightlightDelayMinsDefault ;
extern unsigned long nightlightStartTime ;
2020-03-30 10:21:47 +02:00
extern byte briNlT ;
extern byte colNlT [ ] ;
2020-03-28 13:30:51 +01:00
extern unsigned long lastOnTime ;
extern bool offMode ;
extern byte bri ;
extern byte briOld ;
extern byte briT ;
extern byte briIT ;
2020-03-30 10:21:47 +02:00
extern byte briLast ;
extern byte whiteLast ;
2020-03-28 13:30:51 +01:00
extern bool buttonPressedBefore ;
extern bool buttonLongPressed ;
extern unsigned long buttonPressedTime ;
extern unsigned long buttonWaitTime ;
extern bool notifyDirectDefault ;
extern bool receiveNotifications ;
extern unsigned long notificationSentTime ;
extern byte notificationSentCallMode ;
extern bool notificationTwoRequired ;
extern byte effectCurrent ;
extern byte effectSpeed ;
extern byte effectIntensity ;
extern byte effectPalette ;
extern bool udpConnected , udpRgbConnected ;
extern bool showWelcomePage ;
extern byte hueError ;
extern float hueXLast , hueYLast ;
extern uint16_t hueHueLast , hueCtLast ;
extern byte hueSatLast , hueBriLast ;
extern unsigned long hueLastRequestSent ;
extern bool hueAuthRequired ;
extern bool hueReceived ;
extern bool hueStoreAllowed , hueNewKey ;
extern byte overlayCurrent ;
extern byte overlaySpeed ;
extern unsigned long overlayRefreshMs ;
extern unsigned long overlayRefreshedTime ;
extern byte dP [ ] ;
extern bool cronixieInit ;
extern unsigned long countdownTime ;
extern bool countdownOverTriggered ;
extern byte lastTimerMinute ;
extern byte timerHours [ ] ;
extern byte timerMinutes [ ] ;
extern byte timerMacro [ ] ;
2020-03-30 10:21:47 +02:00
extern byte timerWeekday [ ] ;
2020-03-28 13:30:51 +01:00
extern bool blynkEnabled ;
extern bool presetCyclingEnabled ;
extern byte presetCycleMin , presetCycleMax ;
extern uint16_t presetCycleTime ;
extern unsigned long presetCycledTime ;
extern byte presetCycCurr ;
extern bool presetApplyBri ;
extern bool saveCurrPresetCycConf ;
extern byte realtimeMode ;
extern IPAddress realtimeIP ;
extern unsigned long realtimeTimeout ;
extern long lastMqttReconnectAttempt ;
extern long lastInterfaceUpdate ;
extern byte interfaceUpdateCallMode ;
2020-03-30 10:21:47 +02:00
extern char mqttStatusTopic [ 40 ] ;
2020-03-28 13:30:51 +01:00
# if AUXPIN >= 0
extern byte auxTime ;
extern unsigned long auxStartTime ;
extern bool auxActive ;
# endif
extern String escapedMac ;
# ifndef WLED_DISABLE_ALEXA
extern Espalexa espalexa ;
extern EspalexaDevice * espalexaDevice ;
# endif
extern DNSServer dnsServer ;
extern bool ntpConnected ;
extern time_t local ;
extern unsigned long ntpLastSyncTime ;
extern unsigned long ntpPacketSentTime ;
extern IPAddress ntpServerIP ;
extern uint16_t ntpLocalPort ;
# define NTP_PACKET_SIZE 48
# define MAX_LEDS 1500
# define MAX_LEDS_DMA 500
# define OMAX 2048
extern char * obuf ;
extern uint16_t olen ;
extern uint16_t savedPresets ;
extern int8_t currentPreset ;
extern bool isPreset ;
extern byte errorFlag ;
extern String messageHead , messageSub ;
extern byte optionType ;
2020-03-30 10:21:47 +02:00
extern bool doReboot ;
2020-03-28 13:30:51 +01:00
extern bool doPublishMqtt ;
extern AsyncWebServer server ;
extern AsyncClient * hueClient ;
extern AsyncMqttClient * mqtt ;
extern WiFiUDP notifierUdp , rgbUdp ;
extern WiFiUDP ntpUdp ;
extern ESPAsyncE131 e131 ;
extern bool e131NewData ;
extern WS2812FX strip ;
# define WLED_CONNECTED (WiFi.status() == WL_CONNECTED)
# define WLED_WIFI_CONFIGURED (strlen(clientSSID) >= 1 && strcmp(clientSSID, DEFAULT_CLIENT_SSID) != 0)
//debug macros
# ifdef WLED_DEBUG
# define DEBUG_PRINT(x) Serial.print(x)
# define DEBUG_PRINTLN(x) Serial.println(x)
# define DEBUG_PRINTF(x) Serial.printf(x)
extern unsigned long debugTime ;
extern int lastWifiState ;
extern unsigned long wifiStateChangedTime ;
extern int loops ;
# else
# define DEBUG_PRINT(x)
# define DEBUG_PRINTLN(x)
# define DEBUG_PRINTF(x)
# endif
2020-03-30 10:21:47 +02:00
// append new c string to temp buffer efficiently
2020-03-28 13:30:51 +01:00
bool oappend ( const char * txt ) ;
2020-03-30 10:21:47 +02:00
// append new number to temp buffer efficiently
2020-03-28 13:30:51 +01:00
bool oappendi ( int i ) ;
class WLED
{
public :
2020-03-30 10:35:52 +02:00
WLED ( ) ;
2020-03-28 13:30:51 +01:00
static WLED & instance ( )
{
static WLED instance ;
return instance ;
}
//boot starts here
2020-03-30 10:43:37 +02:00
void setup ( ) ;
2020-03-30 10:35:52 +02:00
void loop ( ) ;
void reset ( ) ;
2020-03-28 13:30:51 +01:00
void beginStrip ( ) ;
void handleConnection ( ) ;
void initAP ( bool resetAP = false ) ;
void initConnection ( ) ;
void initInterfaces ( ) ;
} ;
# endif // WLED_H