Skip to content

Commit 61cd8d8

Browse files
committed
examples: format all .ino files
This formats all the example source files using Arduino style rules.
1 parent e226251 commit 61cd8d8

File tree

88 files changed

+2783
-2854
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+2783
-2854
lines changed

libraries/ArduinoOTA/examples/BasicOTA/BasicOTA.ino

+14-7
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ void setup() {
3232

3333
ArduinoOTA.onStart([]() {
3434
String type;
35-
if (ArduinoOTA.getCommand() == U_FLASH)
35+
if (ArduinoOTA.getCommand() == U_FLASH) {
3636
type = "sketch";
37-
else // U_SPIFFS
37+
} else { // U_SPIFFS
3838
type = "filesystem";
39+
}
3940

4041
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
4142
Serial.println("Start updating " + type);
@@ -48,11 +49,17 @@ void setup() {
4849
});
4950
ArduinoOTA.onError([](ota_error_t error) {
5051
Serial.printf("Error[%u]: ", error);
51-
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
52-
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
53-
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
54-
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
55-
else if (error == OTA_END_ERROR) Serial.println("End Failed");
52+
if (error == OTA_AUTH_ERROR) {
53+
Serial.println("Auth Failed");
54+
} else if (error == OTA_BEGIN_ERROR) {
55+
Serial.println("Begin Failed");
56+
} else if (error == OTA_CONNECT_ERROR) {
57+
Serial.println("Connect Failed");
58+
} else if (error == OTA_RECEIVE_ERROR) {
59+
Serial.println("Receive Failed");
60+
} else if (error == OTA_END_ERROR) {
61+
Serial.println("End Failed");
62+
}
5663
});
5764
ArduinoOTA.begin();
5865
Serial.println("Ready");

libraries/ArduinoOTA/examples/OTALeds/OTALeds.ino

+30-28
Original file line numberDiff line numberDiff line change
@@ -12,54 +12,56 @@ int led_pin = 13;
1212
int dimmer_pin[] = {14, 5, 15};
1313

1414
void setup() {
15-
Serial.begin(115200);
15+
Serial.begin(115200);
1616

17-
/* switch on led */
18-
pinMode(led_pin, OUTPUT);
19-
digitalWrite(led_pin, LOW);
17+
/* switch on led */
18+
pinMode(led_pin, OUTPUT);
19+
digitalWrite(led_pin, LOW);
2020

21-
Serial.println("Booting");
22-
WiFi.mode(WIFI_STA);
21+
Serial.println("Booting");
22+
WiFi.mode(WIFI_STA);
2323

24-
WiFi.begin(ssid, password);
24+
WiFi.begin(ssid, password);
2525

26-
while (WiFi.waitForConnectResult() != WL_CONNECTED){
27-
WiFi.begin(ssid, password);
28-
Serial.println("Retrying connection...");
26+
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
27+
WiFi.begin(ssid, password);
28+
Serial.println("Retrying connection...");
2929
}
3030
/* switch off led */
3131
digitalWrite(led_pin, HIGH);
3232

3333
/* configure dimmers, and OTA server events */
3434
analogWriteRange(1000);
35-
analogWrite(led_pin,990);
35+
analogWrite(led_pin, 990);
3636

37-
for (int i=0; i<N_DIMMERS; i++)
38-
{
37+
for (int i = 0; i < N_DIMMERS; i++) {
3938
pinMode(dimmer_pin[i], OUTPUT);
40-
analogWrite(dimmer_pin[i],50);
39+
analogWrite(dimmer_pin[i], 50);
4140
}
4241

4342
ArduinoOTA.setHostname(host);
4443
ArduinoOTA.onStart([]() { // switch off all the PWMs during upgrade
45-
for(int i=0; i<N_DIMMERS;i++)
46-
analogWrite(dimmer_pin[i], 0);
47-
analogWrite(led_pin,0);
48-
});
44+
for (int i = 0; i < N_DIMMERS; i++) {
45+
analogWrite(dimmer_pin[i], 0);
46+
}
47+
analogWrite(led_pin, 0);
48+
});
4949

5050
ArduinoOTA.onEnd([]() { // do a fancy thing with our board led at end
51-
for (int i=0;i<30;i++)
52-
{
53-
analogWrite(led_pin,(i*100) % 1001);
54-
delay(50);
55-
}
56-
});
51+
for (int i = 0; i < 30; i++) {
52+
analogWrite(led_pin, (i * 100) % 1001);
53+
delay(50);
54+
}
55+
});
5756

58-
ArduinoOTA.onError([](ota_error_t error) { (void)error; ESP.restart(); });
57+
ArduinoOTA.onError([](ota_error_t error) {
58+
(void)error;
59+
ESP.restart();
60+
});
5961

60-
/* setup the OTA server */
61-
ArduinoOTA.begin();
62-
Serial.println("Ready");
62+
/* setup the OTA server */
63+
ArduinoOTA.begin();
64+
Serial.println("Ready");
6365

6466
}
6567

libraries/DNSServer/examples/CaptivePortal/CaptivePortal.ino

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ DNSServer dnsServer;
88
ESP8266WebServer webServer(80);
99

1010
String responseHTML = ""
11-
"<!DOCTYPE html><html><head><title>CaptivePortal</title></head><body>"
12-
"<h1>Hello World!</h1><p>This is a captive portal example. All requests will "
13-
"be redirected here.</p></body></html>";
11+
"<!DOCTYPE html><html><head><title>CaptivePortal</title></head><body>"
12+
"<h1>Hello World!</h1><p>This is a captive portal example. All requests will "
13+
"be redirected here.</p></body></html>";
1414

1515
void setup() {
1616
WiFi.mode(WIFI_AP);

libraries/DNSServer/examples/CaptivePortalAdvanced/CaptivePortalAdvanced.ino

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
#include <ESP8266WiFi.h>
2-
#include <WiFiClient.h>
2+
#include <WiFiClient.h>
33
#include <ESP8266WebServer.h>
44
#include <DNSServer.h>
55
#include <ESP8266mDNS.h>
66
#include <EEPROM.h>
77

88
/*
9-
* This example serves a "hello world" on a WLAN and a SoftAP at the same time.
10-
* The SoftAP allow you to configure WLAN parameters at run time. They are not setup in the sketch but saved on EEPROM.
11-
*
12-
* Connect your computer or cell phone to wifi network ESP_ap with password 12345678. A popup may appear and it allow you to go to WLAN config. If it does not then navigate to http://192.168.4.1/wifi and config it there.
13-
* Then wait for the module to connect to your wifi and take note of the WLAN IP it got. Then you can disconnect from ESP_ap and return to your regular WLAN.
14-
*
15-
* Now the ESP8266 is in your network. You can reach it through http://192.168.x.x/ (the IP you took note of) or maybe at http://esp8266.local too.
16-
*
17-
* This is a captive portal because through the softAP it will redirect any http request to http://192.168.4.1/
18-
*/
9+
This example serves a "hello world" on a WLAN and a SoftAP at the same time.
10+
The SoftAP allow you to configure WLAN parameters at run time. They are not setup in the sketch but saved on EEPROM.
11+
12+
Connect your computer or cell phone to wifi network ESP_ap with password 12345678. A popup may appear and it allow you to go to WLAN config. If it does not then navigate to http://192.168.4.1/wifi and config it there.
13+
Then wait for the module to connect to your wifi and take note of the WLAN IP it got. Then you can disconnect from ESP_ap and return to your regular WLAN.
14+
15+
Now the ESP8266 is in your network. You can reach it through http://192.168.x.x/ (the IP you took note of) or maybe at http://esp8266.local too.
16+
17+
This is a captive portal because through the softAP it will redirect any http request to http://192.168.4.1/
18+
*/
1919

2020
/* Set these to your desired softAP credentials. They are not configurable at runtime */
2121
const char *softAP_ssid = "ESP_ap";
@@ -61,7 +61,7 @@ void setup() {
6161
Serial.print("AP IP address: ");
6262
Serial.println(WiFi.softAPIP());
6363

64-
/* Setup the DNS server redirecting all the domains to the apIP */
64+
/* Setup the DNS server redirecting all the domains to the apIP */
6565
dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
6666
dnsServer.start(DNS_PORT, "*", apIP);
6767

@@ -71,7 +71,7 @@ void setup() {
7171
server.on("/wifisave", handleWifiSave);
7272
server.on("/generate_204", handleRoot); //Android captive portal. Maybe not needed. Might be handled by notFound handler.
7373
server.on("/fwlink", handleRoot); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler.
74-
server.onNotFound ( handleNotFound );
74+
server.onNotFound(handleNotFound);
7575
server.begin(); // Web server start
7676
Serial.println("HTTP server started");
7777
loadCredentials(); // Load WLAN credentials from network
@@ -81,37 +81,37 @@ void setup() {
8181
void connectWifi() {
8282
Serial.println("Connecting as wifi client...");
8383
WiFi.disconnect();
84-
WiFi.begin ( ssid, password );
84+
WiFi.begin(ssid, password);
8585
int connRes = WiFi.waitForConnectResult();
86-
Serial.print ( "connRes: " );
87-
Serial.println ( connRes );
86+
Serial.print("connRes: ");
87+
Serial.println(connRes);
8888
}
8989

9090
void loop() {
9191
if (connect) {
92-
Serial.println ( "Connect requested" );
92+
Serial.println("Connect requested");
9393
connect = false;
9494
connectWifi();
9595
lastConnectTry = millis();
9696
}
9797
{
9898
unsigned int s = WiFi.status();
99-
if (s == 0 && millis() > (lastConnectTry + 60000) ) {
99+
if (s == 0 && millis() > (lastConnectTry + 60000)) {
100100
/* If WLAN disconnected and idle try to connect */
101101
/* Don't set retry time too low as retry interfere the softAP operation */
102102
connect = true;
103103
}
104104
if (status != s) { // WLAN status change
105-
Serial.print ( "Status: " );
106-
Serial.println ( s );
105+
Serial.print("Status: ");
106+
Serial.println(s);
107107
status = s;
108108
if (s == WL_CONNECTED) {
109109
/* Just connected to WLAN */
110-
Serial.println ( "" );
111-
Serial.print ( "Connected to " );
112-
Serial.println ( ssid );
113-
Serial.print ( "IP address: " );
114-
Serial.println ( WiFi.localIP() );
110+
Serial.println("");
111+
Serial.print("Connected to ");
112+
Serial.println(ssid);
113+
Serial.print("IP address: ");
114+
Serial.println(WiFi.localIP());
115115

116116
// Setup MDNS responder
117117
if (!MDNS.begin(myHostname)) {

libraries/DNSServer/examples/CaptivePortalAdvanced/credentials.ino

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22
void loadCredentials() {
33
EEPROM.begin(512);
44
EEPROM.get(0, ssid);
5-
EEPROM.get(0+sizeof(ssid), password);
6-
char ok[2+1];
7-
EEPROM.get(0+sizeof(ssid)+sizeof(password), ok);
5+
EEPROM.get(0 + sizeof(ssid), password);
6+
char ok[2 + 1];
7+
EEPROM.get(0 + sizeof(ssid) + sizeof(password), ok);
88
EEPROM.end();
99
if (String(ok) != String("OK")) {
1010
ssid[0] = 0;
1111
password[0] = 0;
1212
}
1313
Serial.println("Recovered credentials:");
1414
Serial.println(ssid);
15-
Serial.println(strlen(password)>0?"********":"<no password>");
15+
Serial.println(strlen(password) > 0 ? "********" : "<no password>");
1616
}
1717

1818
/** Store WLAN credentials to EEPROM */
1919
void saveCredentials() {
2020
EEPROM.begin(512);
2121
EEPROM.put(0, ssid);
22-
EEPROM.put(0+sizeof(ssid), password);
23-
char ok[2+1] = "OK";
24-
EEPROM.put(0+sizeof(ssid)+sizeof(password), ok);
22+
EEPROM.put(0 + sizeof(ssid), password);
23+
char ok[2 + 1] = "OK";
24+
EEPROM.put(0 + sizeof(ssid) + sizeof(password), ok);
2525
EEPROM.commit();
2626
EEPROM.end();
2727
}

libraries/DNSServer/examples/CaptivePortalAdvanced/handleHttp.ino

+8-8
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ void handleRoot() {
2626

2727
/** Redirect to captive portal if we got a request for another domain. Return true in that case so the page handler do not try to handle the request again. */
2828
boolean captivePortal() {
29-
if (!isIp(server.hostHeader()) && server.hostHeader() != (String(myHostname)+".local")) {
29+
if (!isIp(server.hostHeader()) && server.hostHeader() != (String(myHostname) + ".local")) {
3030
Serial.print("Request redirected to captive portal");
3131
server.sendHeader("Location", String("http://") + toStringIp(server.client().localIP()), true);
32-
server.send ( 302, "text/plain", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
32+
server.send(302, "text/plain", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
3333
server.client().stop(); // Stop is needed because we sent no content length
3434
return true;
3535
}
@@ -75,7 +75,7 @@ void handleWifi() {
7575
Serial.println("scan done");
7676
if (n > 0) {
7777
for (int i = 0; i < n; i++) {
78-
server.sendContent(String() + "\r\n<tr><td>SSID " + WiFi.SSID(i) + String((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":" *") + " (" + WiFi.RSSI(i) + ")</td></tr>");
78+
server.sendContent(String() + "\r\n<tr><td>SSID " + WiFi.SSID(i) + String((WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " : " *") + " (" + WiFi.RSSI(i) + ")</td></tr>");
7979
}
8080
} else {
8181
server.sendContent(String() + "<tr><td>No WLAN found</td></tr>");
@@ -101,7 +101,7 @@ void handleWifiSave() {
101101
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
102102
server.sendHeader("Pragma", "no-cache");
103103
server.sendHeader("Expires", "-1");
104-
server.send ( 302, "text/plain", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
104+
server.send(302, "text/plain", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
105105
server.client().stop(); // Stop is needed because we sent no content length
106106
saveCredentials();
107107
connect = strlen(ssid) > 0; // Request WLAN connect with new credentials if there is a SSID
@@ -115,17 +115,17 @@ void handleNotFound() {
115115
message += "URI: ";
116116
message += server.uri();
117117
message += "\nMethod: ";
118-
message += ( server.method() == HTTP_GET ) ? "GET" : "POST";
118+
message += (server.method() == HTTP_GET) ? "GET" : "POST";
119119
message += "\nArguments: ";
120120
message += server.args();
121121
message += "\n";
122122

123-
for ( uint8_t i = 0; i < server.args(); i++ ) {
124-
message += " " + server.argName ( i ) + ": " + server.arg ( i ) + "\n";
123+
for (uint8_t i = 0; i < server.args(); i++) {
124+
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
125125
}
126126
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
127127
server.sendHeader("Pragma", "no-cache");
128128
server.sendHeader("Expires", "-1");
129-
server.send ( 404, "text/plain", message );
129+
server.send(404, "text/plain", message);
130130
}
131131

Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
/*
2-
* EEPROM Clear
3-
*
4-
* Sets all of the bytes of the EEPROM to 0.
5-
* This example code is in the public domain.
2+
EEPROM Clear
63
7-
*/
4+
Sets all of the bytes of the EEPROM to 0.
5+
This example code is in the public domain.
6+
7+
*/
88

99
#include <EEPROM.h>
1010

11-
void setup()
12-
{
11+
void setup() {
1312
EEPROM.begin(512);
1413
// write a 0 to all 512 bytes of the EEPROM
15-
for (int i = 0; i < 512; i++)
14+
for (int i = 0; i < 512; i++) {
1615
EEPROM.write(i, 0);
16+
}
1717

1818
// turn the LED on when we're done
1919
pinMode(13, OUTPUT);
2020
digitalWrite(13, HIGH);
2121
EEPROM.end();
2222
}
2323

24-
void loop()
25-
{
24+
void loop() {
2625
}

0 commit comments

Comments
 (0)