Add clang format.

pull/814/head
Travis J Dean 2020-03-30 05:19:09 -04:00
rodzic c54092c932
commit a47d48c973
2 zmienionych plików z 403 dodań i 430 usunięć

4
.clang-format 100644
Wyświetl plik

@ -0,0 +1,4 @@
---
BasedOnStyle: Webkit
IndentWidth: 2

Wyświetl plik

@ -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";
@ -48,8 +48,8 @@ bool useRGBW = false; //SK6812 strips can contain an extra White ch
bool turnOnAtBoot = true; //turn on LEDs at power-up bool turnOnAtBoot = true; //turn on LEDs at power-up
byte bootPreset = 0; //save preset to load after power-up byte bootPreset = 0; //save preset to load after power-up
byte col[]{255, 160, 0, 0}; //current RGB(W) primary color. col[] should be updated if you want to change the color. byte col[] { 255, 160, 0, 0 }; //current RGB(W) primary color. col[] should be updated if you want to change the color.
byte colSec[]{0, 0, 0, 0}; //current RGB(W) secondary color byte colSec[] { 0, 0, 0, 0 }; //current RGB(W) secondary color
byte briS = 128; //default brightness byte briS = 128; //default brightness
byte nightlightTargetBri = 0; //brightness after nightlight is over byte nightlightTargetBri = 0; //brightness after nightlight is over
@ -157,7 +157,7 @@ uint16_t userVar0 = 0, userVar1 = 0;
#ifdef WLED_ENABLE_DMX #ifdef WLED_ENABLE_DMX
//dmx CONFIG //dmx CONFIG
byte DMXChannels = 7; // number of channels per fixture byte DMXChannels = 7; // number of channels per fixture
byte DMXFixtureMap[15] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; byte DMXFixtureMap[15] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
// assigns the different channels to different functions. See wled21_dmx.ino for more information. // assigns the different channels to different functions. See wled21_dmx.ino for more information.
uint16_t DMXGap = 10; // gap between the fixtures. makes addressing easier because you don't have to memorize odd numbers when climbing up onto a rig. uint16_t DMXGap = 10; // gap between the fixtures. makes addressing easier because you don't have to memorize odd numbers when climbing up onto a rig.
uint16_t DMXStart = 10; // start address of the first fixture uint16_t DMXStart = 10; // start address of the first fixture
@ -172,12 +172,12 @@ bool interfacesInited = false;
bool wasConnected = false; bool wasConnected = false;
//color //color
byte colOld[]{0, 0, 0, 0}; //color before transition byte colOld[] { 0, 0, 0, 0 }; //color before transition
byte colT[]{0, 0, 0, 0}; //color that is currently displayed on the LEDs byte colT[] { 0, 0, 0, 0 }; //color that is currently displayed on the LEDs
byte colIT[]{0, 0, 0, 0}; //color that was last sent to LEDs byte colIT[] { 0, 0, 0, 0 }; //color that was last sent to LEDs
byte colSecT[]{0, 0, 0, 0}; byte colSecT[] { 0, 0, 0, 0 };
byte colSecOld[]{0, 0, 0, 0}; byte colSecOld[] { 0, 0, 0, 0 };
byte colSecIT[]{0, 0, 0, 0}; byte colSecIT[] { 0, 0, 0, 0 };
byte lastRandomIndex = 0; //used to save last random color so the new one is not the same byte lastRandomIndex = 0; //used to save last random color so the new one is not the same
@ -196,7 +196,7 @@ uint32_t nightlightDelayMs = 10;
uint8_t nightlightDelayMinsDefault = nightlightDelayMins; uint8_t nightlightDelayMinsDefault = nightlightDelayMins;
unsigned long nightlightStartTime; unsigned long nightlightStartTime;
byte briNlT = 0; //current nightlight brightness byte briNlT = 0; //current nightlight brightness
byte colNlT[]{0, 0, 0, 0}; //current nightlight color byte colNlT[] { 0, 0, 0, 0 }; //current nightlight color
//brightness //brightness
unsigned long lastOnTime = 0; unsigned long lastOnTime = 0;
@ -251,7 +251,7 @@ unsigned long overlayRefreshMs = 200;
unsigned long overlayRefreshedTime; unsigned long overlayRefreshedTime;
//cronixie //cronixie
byte dP[]{0, 0, 0, 0, 0, 0}; byte dP[] { 0, 0, 0, 0, 0, 0 };
bool cronixieInit = false; bool cronixieInit = false;
//countdown //countdown
@ -260,10 +260,10 @@ bool countdownOverTriggered = true;
//timer //timer
byte lastTimerMinute = 0; byte lastTimerMinute = 0;
byte timerHours[] = {0, 0, 0, 0, 0, 0, 0, 0}; byte timerHours[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
byte timerMinutes[] = {0, 0, 0, 0, 0, 0, 0, 0}; byte timerMinutes[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
byte timerMacro[] = {0, 0, 0, 0, 0, 0, 0, 0}; byte timerMacro[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
byte timerWeekday[] = {255, 255, 255, 255, 255, 255, 255, 255}; //weekdays to activate on byte timerWeekday[] = { 255, 255, 255, 255, 255, 255, 255, 255 }; //weekdays to activate on
//bit pattern of arr elem: 0b11111111: sun,sat,fri,thu,wed,tue,mon,validity //bit pattern of arr elem: 0b11111111: sun,sat,fri,thu,wed,tue,mon,validity
//blynk //blynk
@ -300,7 +300,7 @@ bool auxActive = false, auxActiveBefore = false;
String escapedMac; String escapedMac;
#ifndef WLED_DISABLE_ALEXA #ifndef WLED_DISABLE_ALEXA
Espalexa espalexa; Espalexa espalexa;
EspalexaDevice *espalexaDevice; EspalexaDevice* espalexaDevice;
#endif #endif
//dns server //dns server
@ -315,7 +315,7 @@ IPAddress ntpServerIP;
uint16_t ntpLocalPort = 2390; uint16_t ntpLocalPort = 2390;
// Temp buffer // Temp buffer
char *obuf; char* obuf;
uint16_t olen = 0; uint16_t olen = 0;
//presets //presets
@ -333,8 +333,8 @@ bool doPublishMqtt = false;
//server library objects //server library objects
AsyncWebServer server(80); AsyncWebServer server(80);
AsyncClient *hueClient = NULL; AsyncClient* hueClient = NULL;
AsyncMqttClient *mqtt = NULL; AsyncMqttClient* mqtt = NULL;
//udp interface objects //udp interface objects
WiFiUDP notifierUdp, rgbUdp; WiFiUDP notifierUdp, rgbUdp;
@ -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();
@ -378,7 +377,7 @@ bool oappendi(int i)
return oappend(s); return oappend(s);
} }
bool oappend(const char *txt) bool oappend(const char* txt)
{ {
uint16_t len = strlen(txt); uint16_t len = strlen(txt);
if (olen + len >= OMAX) if (olen + len >= OMAX)
@ -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;