Skip to content

Commit 195fbb1

Browse files
committed
ethernet: format examples
1 parent 716a208 commit 195fbb1

File tree

10 files changed

+269
-294
lines changed

10 files changed

+269
-294
lines changed

libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void setup() {
4949
// start serial port:
5050
Serial.begin(9600);
5151
while (!Serial) {
52-
; // wait for serial port to connect. Needed for native USB port only
52+
; // wait for serial port to connect. Needed for native USB port only
5353
}
5454

5555
// in Zephyr system check if Ethernet is ready before proceeding to initialize
@@ -65,7 +65,7 @@ void setup() {
6565
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
6666
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
6767
while (true) {
68-
delay(1); // do nothing, no point running without Ethernet hardware
68+
delay(1); // do nothing, no point running without Ethernet hardware
6969
}
7070
}
7171
if (Ethernet.linkStatus() == LinkOFF) {
@@ -83,7 +83,7 @@ void loop() {
8383
// check for any new client connecting, and say hello (before any incoming data)
8484
ZephyrClient newClient = server.accept();
8585
if (newClient) {
86-
for (byte i=0; i < 8; i++) {
86+
for (byte i = 0; i < 8; i++) {
8787
if (!clients[i]) {
8888
Serial.print("We have a new client #");
8989
Serial.println(i);
@@ -98,13 +98,13 @@ void loop() {
9898
}
9999

100100
// check for incoming data from all clients
101-
for (byte i=0; i < 8; i++) {
101+
for (byte i = 0; i < 8; i++) {
102102
if (clients[i] && clients[i].available() > 0) {
103103
// read bytes from a client
104104
byte buffer[80];
105105
int count = clients[i].read(buffer, 80);
106106
// write the bytes to all other connected clients
107-
for (byte j=0; j < 8; j++) {
107+
for (byte j = 0; j < 8; j++) {
108108
if (j != i && clients[j].connected()) {
109109
clients[j].write(buffer, count);
110110
}
@@ -113,7 +113,7 @@ void loop() {
113113
}
114114

115115
// stop any clients which disconnect
116-
for (byte i=0; i < 8; i++) {
116+
for (byte i = 0; i < 8; i++) {
117117
if (clients[i] && !clients[i].connected()) {
118118
Serial.print("disconnect client #");
119119
Serial.println(i);

libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void setup() {
6161
// start serial port:
6262
Serial.begin(9600);
6363
while (!Serial) {
64-
; // wait for serial port to connect. Needed for native USB port only
64+
; // wait for serial port to connect. Needed for native USB port only
6565
}
6666

6767
// in Zephyr system check if Ethernet is ready before proceeding to initialize
@@ -77,7 +77,7 @@ void setup() {
7777
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
7878
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
7979
while (true) {
80-
delay(1); // do nothing, no point running without Ethernet hardware
80+
delay(1); // do nothing, no point running without Ethernet hardware
8181
}
8282
}
8383
if (Ethernet.linkStatus() == LinkOFF) {
@@ -101,7 +101,6 @@ void setup() {
101101

102102
//Set the sensor to high resolution mode tp start readings:
103103
writeRegister(0x03, 0x0A);
104-
105104
}
106105

107106
void loop() {
@@ -130,8 +129,8 @@ void getData() {
130129
temperature = (float)tempData / 20.0;
131130

132131
//Read the pressure data highest 3 bits:
133-
byte pressureDataHigh = readRegister(0x1F, 1);
134-
pressureDataHigh &= 0b00000111; //you only needs bits 2 to 0
132+
byte pressureDataHigh = readRegister(0x1F, 1);
133+
pressureDataHigh &= 0b00000111; //you only needs bits 2 to 0
135134

136135
//Read the pressure data lower 16 bits:
137136
unsigned int pressureDataLow = readRegister(0x20, 2);
@@ -196,13 +195,13 @@ void writeRegister(byte registerName, byte registerValue) {
196195
// of the byte:
197196
registerName <<= 2;
198197
// command (read or write) goes in the lower two bits:
199-
registerName |= 0b00000010; //Write command
198+
registerName |= 0b00000010; //Write command
200199

201200
// take the chip select low to select the device:
202201
digitalWrite(chipSelectPin, LOW);
203202

204-
SPI.transfer(registerName); //Send register location
205-
SPI.transfer(registerValue); //Send value to record into register
203+
SPI.transfer(registerName); //Send register location
204+
SPI.transfer(registerValue); //Send value to record into register
206205

207206
// take the chip select high to de-select:
208207
digitalWrite(chipSelectPin, HIGH);
@@ -211,14 +210,14 @@ void writeRegister(byte registerName, byte registerValue) {
211210

212211
//Read register from the SCP1000:
213212
unsigned int readRegister(byte registerName, int numBytes) {
214-
byte inByte = 0; // incoming from the SPI read
215-
unsigned int result = 0; // result to return
213+
byte inByte = 0; // incoming from the SPI read
214+
unsigned int result = 0; // result to return
216215

217216
// SCP1000 expects the register name in the upper 6 bits
218217
// of the byte:
219-
registerName <<= 2;
218+
registerName <<= 2;
220219
// command (read or write) goes in the lower two bits:
221-
registerName &= 0b11111100; //Read command
220+
registerName &= 0b11111100; //Read command
222221

223222
// take the chip select low to select the device:
224223
digitalWrite(chipSelectPin, LOW);

libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino

Lines changed: 59 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -9,76 +9,73 @@
99

1010
#include "ZephyrEthernet.h"
1111

12-
void setup()
13-
{
14-
// start serial port:
15-
Serial.begin(9600);
16-
while (!Serial) {
17-
; // wait for serial port to connect. Needed for native USB port only
18-
}
12+
void setup() {
13+
// start serial port:
14+
Serial.begin(9600);
15+
while (!Serial) {
16+
; // wait for serial port to connect. Needed for native USB port only
17+
}
1918

20-
// in Zephyr system check if Ethernet is ready before proceeding to initialize
21-
while (Ethernet.linkStatus() != LinkON) {
22-
Serial.println("Waiting for link on");
23-
delay(100);
24-
}
19+
// in Zephyr system check if Ethernet is ready before proceeding to initialize
20+
while (Ethernet.linkStatus() != LinkON) {
21+
Serial.println("Waiting for link on");
22+
delay(100);
23+
}
2524

26-
// start the Ethernet connection:
27-
Serial.println("Initialize Ethernet with DHCP:");
28-
if (Ethernet.begin() == 0) {
29-
Serial.println("Failed to configure Ethernet using DHCP");
30-
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
31-
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
32-
} else if (Ethernet.linkStatus() == LinkOFF) {
33-
Serial.println("Ethernet cable is not connected.");
34-
}
35-
// no point in carrying on, so do nothing forevermore:
36-
while (true) {
37-
delay(1);
38-
}
25+
// start the Ethernet connection:
26+
Serial.println("Initialize Ethernet with DHCP:");
27+
if (Ethernet.begin() == 0) {
28+
Serial.println("Failed to configure Ethernet using DHCP");
29+
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
30+
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
31+
} else if (Ethernet.linkStatus() == LinkOFF) {
32+
Serial.println("Ethernet cable is not connected.");
3933
}
40-
// print your local IP address:
41-
Serial.print("My IP address: ");
42-
Serial.println(Ethernet.localIP());
34+
// no point in carrying on, so do nothing forevermore:
35+
while (true) {
36+
delay(1);
37+
}
38+
}
39+
// print your local IP address:
40+
Serial.print("My IP address: ");
41+
Serial.println(Ethernet.localIP());
4342
}
4443

45-
void loop()
46-
{
47-
if (Ethernet.linkStatus() != LinkON) {
48-
Serial.println(Ethernet.linkStatus());
49-
connectEth();
50-
}
44+
void loop() {
45+
if (Ethernet.linkStatus() != LinkON) {
46+
Serial.println(Ethernet.linkStatus());
47+
connectEth();
48+
}
5149
}
5250

53-
void connectEth()
54-
{
55-
// in Zephyr system check if Ethernet is ready before proceeding to initialize
56-
Serial.print("Waiting for link on");
57-
while (Ethernet.linkStatus() != LinkON) {
58-
Serial.print(".");
59-
delay(100);
60-
}
61-
Serial.println();
51+
void connectEth() {
52+
// in Zephyr system check if Ethernet is ready before proceeding to initialize
53+
Serial.print("Waiting for link on");
54+
while (Ethernet.linkStatus() != LinkON) {
55+
Serial.print(".");
56+
delay(100);
57+
}
58+
Serial.println();
6259

63-
// start the Ethernet connection:
64-
Serial.println("Initialize Ethernet with DHCP:");
65-
if (Ethernet.begin() == 0) {
66-
Serial.println("Failed to configure Ethernet using DHCP");
67-
// Check for Ethernet hardware present
68-
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
69-
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
70-
while (true) {
71-
delay(1); // do nothing, no point running without Ethernet hardware
72-
}
73-
}
74-
if (Ethernet.linkStatus() == LinkOFF) {
75-
Serial.println("Ethernet cable is not connected.");
76-
}
77-
} else {
78-
Serial.print(" DHCP assigned IP ");
79-
Serial.println(Ethernet.localIP());
60+
// start the Ethernet connection:
61+
Serial.println("Initialize Ethernet with DHCP:");
62+
if (Ethernet.begin() == 0) {
63+
Serial.println("Failed to configure Ethernet using DHCP");
64+
// Check for Ethernet hardware present
65+
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
66+
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
67+
while (true) {
68+
delay(1); // do nothing, no point running without Ethernet hardware
69+
}
8070
}
71+
if (Ethernet.linkStatus() == LinkOFF) {
72+
Serial.println("Ethernet cable is not connected.");
73+
}
74+
} else {
75+
Serial.print(" DHCP assigned IP ");
76+
Serial.println(Ethernet.localIP());
77+
}
8178

82-
Serial.println("You're connected to the network");
83-
Serial.println();
79+
Serial.println("You're connected to the network");
80+
Serial.println();
8481
}

libraries/Ethernet/examples/TelnetClient/TelnetClient.ino

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
Telnet client
33
44
This sketch connects to a telnet server.
@@ -19,7 +19,7 @@ IPAddress ip(192, 168, 1, 177);
1919

2020
// Enter the IP address of the server you're connecting to:
2121
IPAddress server(1, 1, 1, 1);
22-
int port = 23; // Telnet port
22+
int port = 23; // Telnet port
2323

2424
// Initialize the Ethernet client library
2525
// with the IP address and port of the server
@@ -32,7 +32,7 @@ void setup() {
3232
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
3333
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
3434
while (true) {
35-
delay(1); // do nothing, no point running without Ethernet hardware
35+
delay(1); // do nothing, no point running without Ethernet hardware
3636
}
3737
}
3838

@@ -48,7 +48,7 @@ void setup() {
4848
// Open serial communications and wait for port to open:
4949
Serial.begin(9600);
5050
while (!Serial) {
51-
; // wait for serial port to connect. Needed for native USB port only
51+
; // wait for serial port to connect. Needed for native USB port only
5252
}
5353

5454
// give the Ethernet shield a second to initialize:
@@ -92,7 +92,3 @@ void loop() {
9292
}
9393
}
9494
}
95-
96-
97-
98-

libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// The IP address will be dependent on your local network:
1414
IPAddress ip(192, 168, 1, 177);
1515

16-
unsigned int localPort = 8888; // local port to listen on
16+
unsigned int localPort = 8888; // local port to listen on
1717

1818
// buffers for receiving and sending data
1919
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; // buffer to hold incoming packet,
@@ -26,7 +26,7 @@ void setup() {
2626
// Open serial communications and wait for port to open:
2727
Serial.begin(9600);
2828
while (!Serial) {
29-
; // wait for serial port to connect. Needed for native USB port only
29+
; // wait for serial port to connect. Needed for native USB port only
3030
}
3131

3232
// in Zephyr system check if Ethernet is ready before proceeding to initialize
@@ -42,7 +42,7 @@ void setup() {
4242
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
4343
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
4444
while (true) {
45-
delay(1); // do nothing, no point running without Ethernet hardware
45+
delay(1); // do nothing, no point running without Ethernet hardware
4646
}
4747
}
4848
if (Ethernet.linkStatus() == LinkOFF) {
@@ -61,7 +61,7 @@ void loop() {
6161
Serial.println(packetSize);
6262
Serial.print("From ");
6363
IPAddress remote = Udp.remoteIP();
64-
for (int i=0; i < 4; i++) {
64+
for (int i = 0; i < 4; i++) {
6565
Serial.print(remote[i], DEC);
6666
if (i < 3) {
6767
Serial.print(".");
@@ -123,5 +123,3 @@ void loop() {
123123
println();
124124
}
125125
*/
126-
127-

0 commit comments

Comments
 (0)