Skip to content

Commit b5a130a

Browse files
author
Federico Fissore
committed
Examples: mass code format. See example_formatter.conf
1 parent c13cf02 commit b5a130a

File tree

18 files changed

+179
-188
lines changed

18 files changed

+179
-188
lines changed

libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino

+11-9
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,28 @@
1010

1111
#include <EEPROM.h>
1212

13-
void setup()
14-
{
13+
void setup() {
1514

1615
/***
17-
Iterate through each byte of the EEPROM storage.
18-
16+
Iterate through each byte of the EEPROM storage.
17+
1918
Larger AVR processors have larger EEPROM sizes, E.g:
2019
- Arduno Duemilanove: 512b EEPROM storage.
2120
- Arduino Uno: 1kb EEPROM storage.
2221
- Arduino Mega: 4kb EEPROM storage.
23-
22+
2423
Rather than hard-coding the length, you should use the pre-provided length function.
25-
This will make your code portable to all AVR processors.
24+
This will make your code portable to all AVR processors.
2625
***/
27-
28-
for ( int i = 0 ; i < EEPROM.length() ; i++ )
26+
27+
for (int i = 0 ; i < EEPROM.length() ; i++) {
2928
EEPROM.write(i, 0);
29+
}
3030

3131
// turn the LED on when we're done
3232
digitalWrite(13, HIGH);
3333
}
3434

35-
void loop(){ /** Empty loop. **/ }
35+
void loop() {
36+
/** Empty loop. **/
37+
}

libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino

+24-22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/***
22
Written by Christopher Andrews.
33
CRC algorithm generated by pycrc, MIT licence ( https://github.com/tpircher/pycrc ).
4-
4+
55
A CRC is a simple way of checking whether data has changed or become corrupted.
66
This example calculates a CRC value directly on the EEPROM values.
77
The purpose of this example is to highlight how the EEPROM object can be used just like an array.
@@ -10,40 +10,42 @@
1010
#include <Arduino.h>
1111
#include <EEPROM.h>
1212

13-
void setup(){
14-
13+
void setup() {
14+
1515
//Start serial
1616
Serial.begin(9600);
1717
while (!Serial) {
1818
; // wait for serial port to connect. Needed for Leonardo only
1919
}
2020

2121
//Print length of data to run CRC on.
22-
Serial.print( "EEPROM length: " );
23-
Serial.println( EEPROM.length() );
24-
22+
Serial.print("EEPROM length: ");
23+
Serial.println(EEPROM.length());
24+
2525
//Print the result of calling eeprom_crc()
26-
Serial.print( "CRC32 of EEPROM data: 0x" );
27-
Serial.println( eeprom_crc(), HEX );
28-
Serial.print( "\n\nDone!" );
26+
Serial.print("CRC32 of EEPROM data: 0x");
27+
Serial.println(eeprom_crc(), HEX);
28+
Serial.print("\n\nDone!");
2929
}
3030

31-
void loop(){ /* Empty loop */ }
31+
void loop() {
32+
/* Empty loop */
33+
}
34+
35+
unsigned long eeprom_crc(void) {
3236

33-
unsigned long eeprom_crc( void ){
34-
3537
const unsigned long crc_table[16] = {
36-
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
37-
0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
38-
0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
39-
0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
40-
};
41-
38+
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
39+
0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
40+
0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
41+
0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
42+
};
43+
4244
unsigned long crc = ~0L;
43-
44-
for( int index = 0 ; index < EEPROM.length() ; ++index ){
45-
crc = crc_table[( crc ^ EEPROM[index] ) & 0x0f] ^ (crc >> 4);
46-
crc = crc_table[( crc ^ ( EEPROM[index] >> 4 )) & 0x0f] ^ (crc >> 4);
45+
46+
for (int index = 0 ; index < EEPROM.length() ; ++index) {
47+
crc = crc_table[(crc ^ EEPROM[index]) & 0x0f] ^ (crc >> 4);
48+
crc = crc_table[(crc ^ (EEPROM[index] >> 4)) & 0x0f] ^ (crc >> 4);
4749
crc = ~crc;
4850
}
4951
return crc;
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,68 @@
11
/***
22
eeprom_get example.
3-
3+
44
This shows how to use the EEPROM.get() method.
5-
5+
66
To pre-set the EEPROM data, run the example sketch eeprom_put.
7-
This sketch will run without it, however, the values shown
7+
This sketch will run without it, however, the values shown
88
will be shown from what ever is already on the EEPROM.
9-
9+
1010
This may cause the serial object to print out a large string
1111
of garbage if there is no null character inside one of the strings
1212
loaded.
13-
13+
1414
Written by Christopher Andrews 2015
15-
Released under MIT licence.
15+
Released under MIT licence.
1616
***/
1717

1818
#include <EEPROM.h>
1919

20-
void setup(){
21-
20+
void setup() {
21+
2222
float f = 0.00f; //Variable to store data read from EEPROM.
2323
int eeAddress = 0; //EEPROM address to start reading from
24-
25-
Serial.begin( 9600 );
24+
25+
Serial.begin(9600);
2626
while (!Serial) {
2727
; // wait for serial port to connect. Needed for Leonardo only
2828
}
29-
Serial.print( "Read float from EEPROM: " );
29+
Serial.print("Read float from EEPROM: ");
3030

3131
//Get the float data from the EEPROM at position 'eeAddress'
32-
EEPROM.get( eeAddress, f );
33-
Serial.println( f, 3 ); //This may print 'ovf, nan' if the data inside the EEPROM is not a valid float.
34-
32+
EEPROM.get(eeAddress, f);
33+
Serial.println(f, 3); //This may print 'ovf, nan' if the data inside the EEPROM is not a valid float.
34+
3535
/***
3636
As get also returns a reference to 'f', you can use it inline.
3737
E.g: Serial.print( EEPROM.get( eeAddress, f ) );
3838
***/
39-
40-
/***
41-
Get can be used with custom structures too.
39+
40+
/***
41+
Get can be used with custom structures too.
4242
I have separated this into an extra function.
4343
***/
44-
44+
4545
secondTest(); //Run the next test.
4646
}
4747

48-
struct MyObject{
48+
struct MyObject {
4949
float field1;
5050
byte field2;
5151
char name[10];
5252
};
5353

54-
void secondTest(){
54+
void secondTest() {
5555
int eeAddress = sizeof(float); //Move address to the next byte after float 'f'.
5656

5757
MyObject customVar; //Variable to store custom object read from EEPROM.
58-
EEPROM.get( eeAddress, customVar );
59-
60-
Serial.println( "Read custom object from EEPROM: " );
61-
Serial.println( customVar.field1 );
62-
Serial.println( customVar.field2 );
63-
Serial.println( customVar.name );
58+
EEPROM.get(eeAddress, customVar);
59+
60+
Serial.println("Read custom object from EEPROM: ");
61+
Serial.println(customVar.field1);
62+
Serial.println(customVar.field2);
63+
Serial.println(customVar.name);
6464
}
6565

66-
void loop(){ /* Empty loop */ }
66+
void loop() {
67+
/* Empty loop */
68+
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/***
22
eeprom_iteration example.
3-
3+
44
A set of example snippets highlighting the
55
simplest methods for traversing the EEPROM.
6-
7-
Running this sketch is not necessary, this is
6+
7+
Running this sketch is not necessary, this is
88
simply highlighting certain programming methods.
9-
9+
1010
Written by Christopher Andrews 2015
1111
Released under MIT licence.
1212
***/
@@ -18,40 +18,40 @@ void setup() {
1818
/***
1919
Iterate the EEPROM using a for loop.
2020
***/
21-
22-
for( int index = 0 ; index < EEPROM.length() ; index++ ){
21+
22+
for (int index = 0 ; index < EEPROM.length() ; index++) {
2323

2424
//Add one to each cell in the EEPROM
2525
EEPROM[ index ] += 1;
2626
}
27-
27+
2828
/***
2929
Iterate the EEPROM using a while loop.
3030
***/
31-
31+
3232
int index = 0;
33-
34-
while( index < EEPROM.length() ){
35-
33+
34+
while (index < EEPROM.length()) {
35+
3636
//Add one to each cell in the EEPROM
37-
EEPROM[ index ] += 1;
37+
EEPROM[ index ] += 1;
3838
index++;
3939
}
40-
40+
4141
/***
4242
Iterate the EEPROM using a do-while loop.
4343
***/
44-
44+
4545
int idx = 0; //Used 'idx' to avoid name conflict with 'index' above.
46-
47-
do{
48-
46+
47+
do {
48+
4949
//Add one to each cell in the EEPROM
50-
EEPROM[ idx ] += 1;
50+
EEPROM[ idx ] += 1;
5151
idx++;
52-
}while( idx < EEPROM.length() );
53-
54-
52+
} while (idx < EEPROM.length());
53+
54+
5555
} //End of setup function.
5656

57-
void loop(){}
57+
void loop() {}
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
/***
22
eeprom_put example.
3-
3+
44
This shows how to use the EEPROM.put() method.
5-
Also, this sketch will pre-set the EEPROM data for the
5+
Also, this sketch will pre-set the EEPROM data for the
66
example sketch eeprom_get.
7-
7+
88
Note, unlike the single byte version EEPROM.write(),
99
the put method will use update semantics. As in a byte
1010
will only be written to the EEPROM if the data is actually
1111
different.
1212
1313
Written by Christopher Andrews 2015
14-
Released under MIT licence.
14+
Released under MIT licence.
1515
***/
1616

1717
#include <EEPROM.h>
1818

19-
struct MyObject{
19+
struct MyObject {
2020
float field1;
2121
byte field2;
2222
char name[10];
2323
};
2424

25-
void setup(){
25+
void setup() {
2626

2727
Serial.begin(9600);
2828
while (!Serial) {
@@ -31,15 +31,15 @@ void setup(){
3131

3232
float f = 123.456f; //Variable to store in EEPROM.
3333
int eeAddress = 0; //Location we want the data to be put.
34-
35-
34+
35+
3636
//One simple call, with the address first and the object second.
37-
EEPROM.put( eeAddress, f );
38-
37+
EEPROM.put(eeAddress, f);
38+
3939
Serial.println("Written float data type!");
40-
40+
4141
/** Put is designed for use with custom structures also. **/
42-
42+
4343
//Data to store.
4444
MyObject customVar = {
4545
3.14f,
@@ -48,9 +48,11 @@ void setup(){
4848
};
4949

5050
eeAddress += sizeof(float); //Move address to the next byte after float 'f'.
51-
52-
EEPROM.put( eeAddress, customVar );
53-
Serial.print( "Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!" );
51+
52+
EEPROM.put(eeAddress, customVar);
53+
Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!");
5454
}
5555

56-
void loop(){ /* Empty loop */ }
56+
void loop() {
57+
/* Empty loop */
58+
}

0 commit comments

Comments
 (0)