Add clang format.

This commit is contained in:
Travis J Dean 2020-03-30 05:19:09 -04:00
parent c54092c932
commit a47d48c973
2 changed files with 403 additions and 430 deletions

4
.clang-format Normal file
View File

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

View File

@ -1,19 +1,19 @@
#include "wled.h"
#include <Arduino.h>
#include "led.h"
#include "ir.h"
#include "notify.h"
#include "alexa.h"
#include "overlay.h"
#include "file.h"
#include "button.h"
#include "ntp.h"
#include "usermod.h"
#include "blynk.h"
#include "button.h"
#include "file.h"
#include "hue.h"
#include "ir.h"
#include "led.h"
#include "mqtt.h"
#include "notify.h"
#include "ntp.h"
#include "overlay.h"
#include "usermod.h"
#include "wled_eeprom.h"
#include "wled_server.h"
#include <Arduino.h>
// Global Variable definitions
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
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 colSec[]{0, 0, 0, 0}; //current RGB(W) secondary 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 briS = 128; //default brightness
byte nightlightTargetBri = 0; //brightness after nightlight is over
@ -157,7 +157,7 @@ uint16_t userVar0 = 0, userVar1 = 0;
#ifdef WLED_ENABLE_DMX
//dmx CONFIG
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.
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
@ -172,12 +172,12 @@ bool interfacesInited = false;
bool wasConnected = false;
//color
byte colOld[]{0, 0, 0, 0}; //color before transition
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 colSecT[]{0, 0, 0, 0};
byte colSecOld[]{0, 0, 0, 0};
byte colSecIT[]{0, 0, 0, 0};
byte colOld[] { 0, 0, 0, 0 }; //color before transition
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 colSecT[] { 0, 0, 0, 0 };
byte colSecOld[] { 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
@ -196,7 +196,7 @@ uint32_t nightlightDelayMs = 10;
uint8_t nightlightDelayMinsDefault = nightlightDelayMins;
unsigned long nightlightStartTime;
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
unsigned long lastOnTime = 0;
@ -251,7 +251,7 @@ unsigned long overlayRefreshMs = 200;
unsigned long overlayRefreshedTime;
//cronixie
byte dP[]{0, 0, 0, 0, 0, 0};
byte dP[] { 0, 0, 0, 0, 0, 0 };
bool cronixieInit = false;
//countdown
@ -260,10 +260,10 @@ bool countdownOverTriggered = true;
//timer
byte lastTimerMinute = 0;
byte timerHours[] = {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 timerWeekday[] = {255, 255, 255, 255, 255, 255, 255, 255}; //weekdays to activate on
byte timerHours[] = { 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 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
//blynk
@ -300,7 +300,7 @@ bool auxActive = false, auxActiveBefore = false;
String escapedMac;
#ifndef WLED_DISABLE_ALEXA
Espalexa espalexa;
EspalexaDevice *espalexaDevice;
EspalexaDevice* espalexaDevice;
#endif
//dns server
@ -315,7 +315,7 @@ IPAddress ntpServerIP;
uint16_t ntpLocalPort = 2390;
// Temp buffer
char *obuf;
char* obuf;
uint16_t olen = 0;
//presets
@ -333,8 +333,8 @@ bool doPublishMqtt = false;
//server library objects
AsyncWebServer server(80);
AsyncClient *hueClient = NULL;
AsyncMqttClient *mqtt = NULL;
AsyncClient* hueClient = NULL;
AsyncMqttClient* mqtt = NULL;
//udp interface objects
WiFiUDP notifierUdp, rgbUdp;
@ -353,8 +353,8 @@ unsigned long wifiStateChangedTime = 0;
int loops = 0;
#endif
WLED::WLED() {
WLED::WLED()
{
}
//turns all LEDs off and restarts ESP
@ -362,8 +362,7 @@ void WLED::reset()
{
briT = 0;
long dly = millis();
while (millis() - dly < 250)
{
while (millis() - dly < 250) {
yield(); //enough time to send response to client
}
setAllLeds();
@ -378,7 +377,7 @@ bool oappendi(int i)
return oappend(s);
}
bool oappend(const char *txt)
bool oappend(const char* txt)
{
uint16_t len = strlen(txt);
if (olen + len >= OMAX)
@ -442,8 +441,7 @@ void WLED::loop()
//DEBUG serial logging
#ifdef WLED_DEBUG
if (millis() - debugTime > 9999)
{
if (millis() - debugTime > 9999) {
DEBUG_PRINTLN("---DEBUG INFO---");
DEBUG_PRINT("Runtime: ");
DEBUG_PRINTLN(millis());
@ -453,8 +451,7 @@ void WLED::loop()
DEBUG_PRINTLN(ESP.getFreeHeap());
DEBUG_PRINT("Wifi state: ");
DEBUG_PRINTLN(WiFi.status());
if (WiFi.status() != lastWifiState)
{
if (WiFi.status() != lastWifiState) {
wifiStateChangedTime = millis();
}
lastWifiState = WiFi.status();
@ -539,13 +536,11 @@ void WLED::setup()
strcpy(cmDNS, "wled-");
sprintf(cmDNS + 5, "%*s", 6, escapedMac.c_str() + 6);
}
if (mqttDeviceTopic[0] == 0)
{
if (mqttDeviceTopic[0] == 0) {
strcpy(mqttDeviceTopic, "wled/");
sprintf(mqttDeviceTopic + 5, "%*s", 6, escapedMac.c_str() + 6);
}
if (mqttClientID[0] == 0)
{
if (mqttClientID[0] == 0) {
strcpy(mqttClientID, "WLED-");
sprintf(mqttClientID + 5, "%*s", 6, escapedMac.c_str() + 6);
}
@ -553,8 +548,7 @@ void WLED::setup()
strip.service();
#ifndef WLED_DISABLE_OTA
if (aOtaEnabled)
{
if (aOtaEnabled) {
ArduinoOTA.onStart([]() {
#ifdef ESP8266
wifi_set_sleep_type(NONE_SLEEP_T);
@ -622,12 +616,10 @@ void WLED::initAP(bool resetAP)
{
DEBUG_PRINTLN("Init AP interfaces");
server.begin();
if (udpPort > 0 && udpPort != ntpLocalPort)
{
if (udpPort > 0 && udpPort != ntpLocalPort) {
udpConnected = notifierUdp.begin(udpPort);
}
if (udpRgbPort > 0 && udpRgbPort != ntpLocalPort && udpRgbPort != udpPort)
{
if (udpRgbPort > 0 && udpRgbPort != ntpLocalPort && udpRgbPort != udpPort) {
udpRgbConnected = rgbUdp.begin(udpRgbPort);
}
@ -644,32 +636,23 @@ void WLED::initConnection()
WiFi.setPhyMode(WIFI_PHY_MODE_11N);
#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));
}
else
{
} else {
WiFi.config(0U, 0U, 0U);
}
lastReconnectAttempt = millis();
if (!WLED_WIFI_CONFIGURED)
{
if (!WLED_WIFI_CONFIGURED) {
DEBUG_PRINT("No connection configured. ");
if (!apActive)
initAP(); //instantly go to ap mode
return;
}
else if (!apActive)
{
if (apBehavior == AP_BEHAVIOR_ALWAYS)
{
} else if (!apActive) {
if (apBehavior == AP_BEHAVIOR_ALWAYS) {
initAP();
}
else
{
} else {
DEBUG_PRINTLN("Access point disabled.");
WiFi.softAPdisconnect(true);
}
@ -698,8 +681,7 @@ void WLED::initInterfaces()
{
DEBUG_PRINTLN("Init STA interfaces");
if (hueIP[0] == 0)
{
if (hueIP[0] == 0) {
hueIP[0] = WiFi.localIP()[0];
hueIP[1] = WiFi.localIP()[1];
hueIP[2] = WiFi.localIP()[2];
@ -716,8 +698,7 @@ void WLED::initInterfaces()
strip.service();
// Set up mDNS responder:
if (strlen(cmDNS) > 0)
{
if (strlen(cmDNS) > 0) {
if (!aOtaEnabled)
MDNS.begin(cmDNS);
@ -728,8 +709,7 @@ void WLED::initInterfaces()
}
server.begin();
if (udpPort > 0 && udpPort != ntpLocalPort)
{
if (udpPort > 0 && udpPort != ntpLocalPort) {
udpConnected = notifierUdp.begin(udpPort);
if (udpConnected && udpRgbPort != udpPort)
udpRgbConnected = rgbUdp.begin(udpRgbPort);
@ -757,11 +737,9 @@ void WLED::handleConnection()
initConnection();
//reconnect WiFi to clear stale allocations if heap gets too low
if (millis() - heapTime > 5000)
{
if (millis() - heapTime > 5000) {
uint32_t heap = ESP.getFreeHeap();
if (heap < 9000 && lastHeap < 9000)
{
if (heap < 9000 && lastHeap < 9000) {
DEBUG_PRINT("Heap too low! ");
DEBUG_PRINTLN(heap);
forceReconnect = true;
@ -771,8 +749,7 @@ void WLED::handleConnection()
}
byte stac = 0;
if (apActive)
{
if (apActive) {
#ifdef ESP8266
stac = wifi_softap_get_station_num();
#else
@ -780,13 +757,11 @@ void WLED::handleConnection()
esp_wifi_ap_get_sta_list(&stationList);
stac = stationList.num;
#endif
if (stac != stacO)
{
if (stac != stacO) {
stacO = stac;
DEBUG_PRINT("Connected AP clients: ");
DEBUG_PRINTLN(stac);
if (!WLED_CONNECTED && WLED_WIFI_CONFIGURED)
{ //trying to connect, but not connected
if (!WLED_CONNECTED && WLED_WIFI_CONFIGURED) { //trying to connect, but not connected
if (stac)
WiFi.disconnect(); //disable search so that AP can work
else
@ -794,8 +769,7 @@ void WLED::handleConnection()
}
}
}
if (forceReconnect)
{
if (forceReconnect) {
DEBUG_PRINTLN("Forcing reconnect.");
initConnection();
interfacesInited = false;
@ -803,10 +777,8 @@ void WLED::handleConnection()
wasConnected = false;
return;
}
if (!WLED_CONNECTED)
{
if (interfacesInited)
{
if (!WLED_CONNECTED) {
if (interfacesInited) {
DEBUG_PRINTLN("Disconnected!");
interfacesInited = false;
initConnection();
@ -815,9 +787,7 @@ void WLED::handleConnection()
initConnection();
if (!apActive && millis() - lastReconnectAttempt > 12000 && (!wasConnected || apBehavior == AP_BEHAVIOR_NO_CONN))
initAP();
}
else if (!interfacesInited)
{ //newly connected
} else if (!interfacesInited) { //newly connected
DEBUG_PRINTLN("");
DEBUG_PRINT("Connected! IP address: ");
DEBUG_PRINTLN(WiFi.localIP());
@ -825,8 +795,7 @@ void WLED::handleConnection()
userConnected();
//shut down AP
if (apBehavior != AP_BEHAVIOR_ALWAYS && apActive)
{
if (apBehavior != AP_BEHAVIOR_ALWAYS && apActive) {
dnsServer.stop();
WiFi.softAPdisconnect(true);
apActive = false;