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";
@ -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();
@ -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;