kopia lustrzana https://github.com/Aircoookie/WLED
Add clang format.
rodzic
c54092c932
commit
a47d48c973
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
BasedOnStyle: Webkit
|
||||||
|
IndentWidth: 2
|
||||||
|
|
107
wled00/wled.cpp
107
wled00/wled.cpp
|
@ -1,19 +1,19 @@
|
||||||
#include "wled.h"
|
#include "wled.h"
|
||||||
#include <Arduino.h>
|
|
||||||
#include "led.h"
|
|
||||||
#include "ir.h"
|
|
||||||
#include "notify.h"
|
|
||||||
#include "alexa.h"
|
#include "alexa.h"
|
||||||
#include "overlay.h"
|
|
||||||
#include "file.h"
|
|
||||||
#include "button.h"
|
|
||||||
#include "ntp.h"
|
|
||||||
#include "usermod.h"
|
|
||||||
#include "blynk.h"
|
#include "blynk.h"
|
||||||
|
#include "button.h"
|
||||||
|
#include "file.h"
|
||||||
#include "hue.h"
|
#include "hue.h"
|
||||||
|
#include "ir.h"
|
||||||
|
#include "led.h"
|
||||||
#include "mqtt.h"
|
#include "mqtt.h"
|
||||||
|
#include "notify.h"
|
||||||
|
#include "ntp.h"
|
||||||
|
#include "overlay.h"
|
||||||
|
#include "usermod.h"
|
||||||
#include "wled_eeprom.h"
|
#include "wled_eeprom.h"
|
||||||
#include "wled_server.h"
|
#include "wled_server.h"
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
// Global Variable definitions
|
// Global Variable definitions
|
||||||
char versionString[] = "0.9.1";
|
char versionString[] = "0.9.1";
|
||||||
|
@ -353,8 +353,8 @@ unsigned long wifiStateChangedTime = 0;
|
||||||
int loops = 0;
|
int loops = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
WLED::WLED() {
|
WLED::WLED()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//turns all LEDs off and restarts ESP
|
//turns all LEDs off and restarts ESP
|
||||||
|
@ -362,8 +362,7 @@ void WLED::reset()
|
||||||
{
|
{
|
||||||
briT = 0;
|
briT = 0;
|
||||||
long dly = millis();
|
long dly = millis();
|
||||||
while (millis() - dly < 250)
|
while (millis() - dly < 250) {
|
||||||
{
|
|
||||||
yield(); //enough time to send response to client
|
yield(); //enough time to send response to client
|
||||||
}
|
}
|
||||||
setAllLeds();
|
setAllLeds();
|
||||||
|
@ -442,8 +441,7 @@ void WLED::loop()
|
||||||
|
|
||||||
//DEBUG serial logging
|
//DEBUG serial logging
|
||||||
#ifdef WLED_DEBUG
|
#ifdef WLED_DEBUG
|
||||||
if (millis() - debugTime > 9999)
|
if (millis() - debugTime > 9999) {
|
||||||
{
|
|
||||||
DEBUG_PRINTLN("---DEBUG INFO---");
|
DEBUG_PRINTLN("---DEBUG INFO---");
|
||||||
DEBUG_PRINT("Runtime: ");
|
DEBUG_PRINT("Runtime: ");
|
||||||
DEBUG_PRINTLN(millis());
|
DEBUG_PRINTLN(millis());
|
||||||
|
@ -453,8 +451,7 @@ void WLED::loop()
|
||||||
DEBUG_PRINTLN(ESP.getFreeHeap());
|
DEBUG_PRINTLN(ESP.getFreeHeap());
|
||||||
DEBUG_PRINT("Wifi state: ");
|
DEBUG_PRINT("Wifi state: ");
|
||||||
DEBUG_PRINTLN(WiFi.status());
|
DEBUG_PRINTLN(WiFi.status());
|
||||||
if (WiFi.status() != lastWifiState)
|
if (WiFi.status() != lastWifiState) {
|
||||||
{
|
|
||||||
wifiStateChangedTime = millis();
|
wifiStateChangedTime = millis();
|
||||||
}
|
}
|
||||||
lastWifiState = WiFi.status();
|
lastWifiState = WiFi.status();
|
||||||
|
@ -539,13 +536,11 @@ void WLED::setup()
|
||||||
strcpy(cmDNS, "wled-");
|
strcpy(cmDNS, "wled-");
|
||||||
sprintf(cmDNS + 5, "%*s", 6, escapedMac.c_str() + 6);
|
sprintf(cmDNS + 5, "%*s", 6, escapedMac.c_str() + 6);
|
||||||
}
|
}
|
||||||
if (mqttDeviceTopic[0] == 0)
|
if (mqttDeviceTopic[0] == 0) {
|
||||||
{
|
|
||||||
strcpy(mqttDeviceTopic, "wled/");
|
strcpy(mqttDeviceTopic, "wled/");
|
||||||
sprintf(mqttDeviceTopic + 5, "%*s", 6, escapedMac.c_str() + 6);
|
sprintf(mqttDeviceTopic + 5, "%*s", 6, escapedMac.c_str() + 6);
|
||||||
}
|
}
|
||||||
if (mqttClientID[0] == 0)
|
if (mqttClientID[0] == 0) {
|
||||||
{
|
|
||||||
strcpy(mqttClientID, "WLED-");
|
strcpy(mqttClientID, "WLED-");
|
||||||
sprintf(mqttClientID + 5, "%*s", 6, escapedMac.c_str() + 6);
|
sprintf(mqttClientID + 5, "%*s", 6, escapedMac.c_str() + 6);
|
||||||
}
|
}
|
||||||
|
@ -553,8 +548,7 @@ void WLED::setup()
|
||||||
strip.service();
|
strip.service();
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_OTA
|
#ifndef WLED_DISABLE_OTA
|
||||||
if (aOtaEnabled)
|
if (aOtaEnabled) {
|
||||||
{
|
|
||||||
ArduinoOTA.onStart([]() {
|
ArduinoOTA.onStart([]() {
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
wifi_set_sleep_type(NONE_SLEEP_T);
|
wifi_set_sleep_type(NONE_SLEEP_T);
|
||||||
|
@ -622,12 +616,10 @@ void WLED::initAP(bool resetAP)
|
||||||
{
|
{
|
||||||
DEBUG_PRINTLN("Init AP interfaces");
|
DEBUG_PRINTLN("Init AP interfaces");
|
||||||
server.begin();
|
server.begin();
|
||||||
if (udpPort > 0 && udpPort != ntpLocalPort)
|
if (udpPort > 0 && udpPort != ntpLocalPort) {
|
||||||
{
|
|
||||||
udpConnected = notifierUdp.begin(udpPort);
|
udpConnected = notifierUdp.begin(udpPort);
|
||||||
}
|
}
|
||||||
if (udpRgbPort > 0 && udpRgbPort != ntpLocalPort && udpRgbPort != udpPort)
|
if (udpRgbPort > 0 && udpRgbPort != ntpLocalPort && udpRgbPort != udpPort) {
|
||||||
{
|
|
||||||
udpRgbConnected = rgbUdp.begin(udpRgbPort);
|
udpRgbConnected = rgbUdp.begin(udpRgbPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -644,32 +636,23 @@ void WLED::initConnection()
|
||||||
WiFi.setPhyMode(WIFI_PHY_MODE_11N);
|
WiFi.setPhyMode(WIFI_PHY_MODE_11N);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (staticIP[0] != 0 && staticGateway[0] != 0)
|
if (staticIP[0] != 0 && staticGateway[0] != 0) {
|
||||||
{
|
|
||||||
WiFi.config(staticIP, staticGateway, staticSubnet, IPAddress(8, 8, 8, 8));
|
WiFi.config(staticIP, staticGateway, staticSubnet, IPAddress(8, 8, 8, 8));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
WiFi.config(0U, 0U, 0U);
|
WiFi.config(0U, 0U, 0U);
|
||||||
}
|
}
|
||||||
|
|
||||||
lastReconnectAttempt = millis();
|
lastReconnectAttempt = millis();
|
||||||
|
|
||||||
if (!WLED_WIFI_CONFIGURED)
|
if (!WLED_WIFI_CONFIGURED) {
|
||||||
{
|
|
||||||
DEBUG_PRINT("No connection configured. ");
|
DEBUG_PRINT("No connection configured. ");
|
||||||
if (!apActive)
|
if (!apActive)
|
||||||
initAP(); //instantly go to ap mode
|
initAP(); //instantly go to ap mode
|
||||||
return;
|
return;
|
||||||
}
|
} else if (!apActive) {
|
||||||
else if (!apActive)
|
if (apBehavior == AP_BEHAVIOR_ALWAYS) {
|
||||||
{
|
|
||||||
if (apBehavior == AP_BEHAVIOR_ALWAYS)
|
|
||||||
{
|
|
||||||
initAP();
|
initAP();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
DEBUG_PRINTLN("Access point disabled.");
|
DEBUG_PRINTLN("Access point disabled.");
|
||||||
WiFi.softAPdisconnect(true);
|
WiFi.softAPdisconnect(true);
|
||||||
}
|
}
|
||||||
|
@ -698,8 +681,7 @@ void WLED::initInterfaces()
|
||||||
{
|
{
|
||||||
DEBUG_PRINTLN("Init STA interfaces");
|
DEBUG_PRINTLN("Init STA interfaces");
|
||||||
|
|
||||||
if (hueIP[0] == 0)
|
if (hueIP[0] == 0) {
|
||||||
{
|
|
||||||
hueIP[0] = WiFi.localIP()[0];
|
hueIP[0] = WiFi.localIP()[0];
|
||||||
hueIP[1] = WiFi.localIP()[1];
|
hueIP[1] = WiFi.localIP()[1];
|
||||||
hueIP[2] = WiFi.localIP()[2];
|
hueIP[2] = WiFi.localIP()[2];
|
||||||
|
@ -716,8 +698,7 @@ void WLED::initInterfaces()
|
||||||
|
|
||||||
strip.service();
|
strip.service();
|
||||||
// Set up mDNS responder:
|
// Set up mDNS responder:
|
||||||
if (strlen(cmDNS) > 0)
|
if (strlen(cmDNS) > 0) {
|
||||||
{
|
|
||||||
if (!aOtaEnabled)
|
if (!aOtaEnabled)
|
||||||
MDNS.begin(cmDNS);
|
MDNS.begin(cmDNS);
|
||||||
|
|
||||||
|
@ -728,8 +709,7 @@ void WLED::initInterfaces()
|
||||||
}
|
}
|
||||||
server.begin();
|
server.begin();
|
||||||
|
|
||||||
if (udpPort > 0 && udpPort != ntpLocalPort)
|
if (udpPort > 0 && udpPort != ntpLocalPort) {
|
||||||
{
|
|
||||||
udpConnected = notifierUdp.begin(udpPort);
|
udpConnected = notifierUdp.begin(udpPort);
|
||||||
if (udpConnected && udpRgbPort != udpPort)
|
if (udpConnected && udpRgbPort != udpPort)
|
||||||
udpRgbConnected = rgbUdp.begin(udpRgbPort);
|
udpRgbConnected = rgbUdp.begin(udpRgbPort);
|
||||||
|
@ -757,11 +737,9 @@ void WLED::handleConnection()
|
||||||
initConnection();
|
initConnection();
|
||||||
|
|
||||||
//reconnect WiFi to clear stale allocations if heap gets too low
|
//reconnect WiFi to clear stale allocations if heap gets too low
|
||||||
if (millis() - heapTime > 5000)
|
if (millis() - heapTime > 5000) {
|
||||||
{
|
|
||||||
uint32_t heap = ESP.getFreeHeap();
|
uint32_t heap = ESP.getFreeHeap();
|
||||||
if (heap < 9000 && lastHeap < 9000)
|
if (heap < 9000 && lastHeap < 9000) {
|
||||||
{
|
|
||||||
DEBUG_PRINT("Heap too low! ");
|
DEBUG_PRINT("Heap too low! ");
|
||||||
DEBUG_PRINTLN(heap);
|
DEBUG_PRINTLN(heap);
|
||||||
forceReconnect = true;
|
forceReconnect = true;
|
||||||
|
@ -771,8 +749,7 @@ void WLED::handleConnection()
|
||||||
}
|
}
|
||||||
|
|
||||||
byte stac = 0;
|
byte stac = 0;
|
||||||
if (apActive)
|
if (apActive) {
|
||||||
{
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
stac = wifi_softap_get_station_num();
|
stac = wifi_softap_get_station_num();
|
||||||
#else
|
#else
|
||||||
|
@ -780,13 +757,11 @@ void WLED::handleConnection()
|
||||||
esp_wifi_ap_get_sta_list(&stationList);
|
esp_wifi_ap_get_sta_list(&stationList);
|
||||||
stac = stationList.num;
|
stac = stationList.num;
|
||||||
#endif
|
#endif
|
||||||
if (stac != stacO)
|
if (stac != stacO) {
|
||||||
{
|
|
||||||
stacO = stac;
|
stacO = stac;
|
||||||
DEBUG_PRINT("Connected AP clients: ");
|
DEBUG_PRINT("Connected AP clients: ");
|
||||||
DEBUG_PRINTLN(stac);
|
DEBUG_PRINTLN(stac);
|
||||||
if (!WLED_CONNECTED && WLED_WIFI_CONFIGURED)
|
if (!WLED_CONNECTED && WLED_WIFI_CONFIGURED) { //trying to connect, but not connected
|
||||||
{ //trying to connect, but not connected
|
|
||||||
if (stac)
|
if (stac)
|
||||||
WiFi.disconnect(); //disable search so that AP can work
|
WiFi.disconnect(); //disable search so that AP can work
|
||||||
else
|
else
|
||||||
|
@ -794,8 +769,7 @@ void WLED::handleConnection()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (forceReconnect)
|
if (forceReconnect) {
|
||||||
{
|
|
||||||
DEBUG_PRINTLN("Forcing reconnect.");
|
DEBUG_PRINTLN("Forcing reconnect.");
|
||||||
initConnection();
|
initConnection();
|
||||||
interfacesInited = false;
|
interfacesInited = false;
|
||||||
|
@ -803,10 +777,8 @@ void WLED::handleConnection()
|
||||||
wasConnected = false;
|
wasConnected = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!WLED_CONNECTED)
|
if (!WLED_CONNECTED) {
|
||||||
{
|
if (interfacesInited) {
|
||||||
if (interfacesInited)
|
|
||||||
{
|
|
||||||
DEBUG_PRINTLN("Disconnected!");
|
DEBUG_PRINTLN("Disconnected!");
|
||||||
interfacesInited = false;
|
interfacesInited = false;
|
||||||
initConnection();
|
initConnection();
|
||||||
|
@ -815,9 +787,7 @@ void WLED::handleConnection()
|
||||||
initConnection();
|
initConnection();
|
||||||
if (!apActive && millis() - lastReconnectAttempt > 12000 && (!wasConnected || apBehavior == AP_BEHAVIOR_NO_CONN))
|
if (!apActive && millis() - lastReconnectAttempt > 12000 && (!wasConnected || apBehavior == AP_BEHAVIOR_NO_CONN))
|
||||||
initAP();
|
initAP();
|
||||||
}
|
} else if (!interfacesInited) { //newly connected
|
||||||
else if (!interfacesInited)
|
|
||||||
{ //newly connected
|
|
||||||
DEBUG_PRINTLN("");
|
DEBUG_PRINTLN("");
|
||||||
DEBUG_PRINT("Connected! IP address: ");
|
DEBUG_PRINT("Connected! IP address: ");
|
||||||
DEBUG_PRINTLN(WiFi.localIP());
|
DEBUG_PRINTLN(WiFi.localIP());
|
||||||
|
@ -825,8 +795,7 @@ void WLED::handleConnection()
|
||||||
userConnected();
|
userConnected();
|
||||||
|
|
||||||
//shut down AP
|
//shut down AP
|
||||||
if (apBehavior != AP_BEHAVIOR_ALWAYS && apActive)
|
if (apBehavior != AP_BEHAVIOR_ALWAYS && apActive) {
|
||||||
{
|
|
||||||
dnsServer.stop();
|
dnsServer.stop();
|
||||||
WiFi.softAPdisconnect(true);
|
WiFi.softAPdisconnect(true);
|
||||||
apActive = false;
|
apActive = false;
|
||||||
|
|
Ładowanie…
Reference in New Issue