Skip to content

Commit 1535ac2

Browse files
committed
Timestamp fix, edit src for cplint errors
Add time st
1 parent e7b775a commit 1535ac2

File tree

103 files changed

+1810
-1148
lines changed

Some content is hidden

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

103 files changed

+1810
-1148
lines changed

examples/AvrAdcLogger/AvrAdcLogger.ino

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,16 @@ MinimumSerial MinSerial;
4444
//------------------------------------------------------------------------------
4545
// Set USE_RTC nonzero for file timestamps.
4646
// RAM use will be marginal on Uno with RTClib.
47+
// Set USE_RTC nonzero for file timestamps.
48+
// RAM use will be marginal on Uno with RTClib.
49+
// 0 - RTC not used
50+
// 1 - DS1307
51+
// 2 - DS3231
52+
// 3 - PCF8523
4753
#define USE_RTC 0
4854
#if USE_RTC
4955
#include "RTClib.h"
50-
#endif
56+
#endif // USE_RTC
5157
//------------------------------------------------------------------------------
5258
// Pin definitions.
5359
//
@@ -141,7 +147,7 @@ const uint16_t MIN_ADC_CYCLES = 15;
141147
// Extra cpu cycles to setup ADC with more than one pin per sample.
142148
const uint16_t ISR_SETUP_ADC = PIN_COUNT > 1 ? 100 : 0;
143149

144-
// Maximum cycles for timer0 system interrupt, millis, micros.
150+
// Maximum cycles for timer0 system interrupt.
145151
const uint16_t ISR_TIMER0 = 160;
146152
//==============================================================================
147153
const uint32_t MAX_FILE_SIZE = MAX_FILE_SIZE_MiB << 20;
@@ -303,8 +309,15 @@ void printUnusedStack() {
303309
}
304310
//------------------------------------------------------------------------------
305311
#if USE_RTC
312+
#if USE_RTC == 1
306313
RTC_DS1307 rtc;
307-
314+
#elif USE_RTC == 2
315+
RTC_DS3231 rtc;
316+
#elif USE_RTC == 3
317+
RTC_PCF8523 rtc;
318+
#else // USE_RTC == type
319+
#error USE_RTC type not implemented.
320+
#endif // USE_RTC == type
308321
// Call back for file timestamps. Only called for file create and sync().
309322
void dateTime(uint16_t* date, uint16_t* time, uint8_t* ms10) {
310323
DateTime now = rtc.now();
@@ -553,6 +566,15 @@ void binaryToCsv() {
553566
Serial.println(F(" Seconds"));
554567
}
555568
//------------------------------------------------------------------------------
569+
void clearSerialInput() {
570+
uint32_t m = micros();
571+
do {
572+
if (Serial.read() >= 0) {
573+
m = micros();
574+
}
575+
} while (micros() - m < 10000);
576+
}
577+
//------------------------------------------------------------------------------
556578
void createBinFile() {
557579
binFile.close();
558580
while (sd.exists(binName)) {
@@ -719,7 +741,7 @@ void logData() {
719741
//------------------------------------------------------------------------------
720742
void openBinFile() {
721743
char name[NAME_DIM];
722-
serialClearInput();
744+
clearSerialInput();
723745
Serial.println(F("Enter file name"));
724746
if (!serialReadLine(name, sizeof(name))) {
725747
return;
@@ -772,12 +794,6 @@ void printData() {
772794
Serial.println(F("Done"));
773795
}
774796
//------------------------------------------------------------------------------
775-
void serialClearInput() {
776-
do {
777-
delay(10);
778-
} while (Serial.read() >= 0);
779-
}
780-
//------------------------------------------------------------------------------
781797
bool serialReadLine(char* str, size_t size) {
782798
size_t n = 0;
783799
while(!Serial.available()) {
@@ -840,9 +856,7 @@ void setup(void) {
840856
void loop(void) {
841857
printUnusedStack();
842858
// Read any Serial data.
843-
do {
844-
delay(10);
845-
} while (Serial.available() && Serial.read() >= 0);
859+
clearSerialInput();
846860
Serial.println();
847861
Serial.println(F("type:"));
848862
Serial.println(F("b - open existing bin file"));
@@ -860,9 +874,7 @@ void loop(void) {
860874
digitalWrite(ERROR_LED_PIN, LOW);
861875
}
862876
// Read any Serial data.
863-
do {
864-
delay(10);
865-
} while (Serial.available() && Serial.read() >= 0);
877+
clearSerialInput();
866878

867879
if (c == 'b') {
868880
openBinFile();

examples/BackwardCompatibility/BackwardCompatibility.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// A simple read/write example for SD.h.
22
// Mostly from the SD.h ReadWrite example.
3-
//
3+
//
44
// Your SD must be formatted FAT16/FAT32.
55
//
66
// Set USE_SD_H nonzero to use SD.h.
@@ -28,14 +28,14 @@ void setup() {
2828
#if USE_SD_H
2929
Serial.println(F("Using SD.h. Set USE_SD_H zero to use SdFat.h."));
3030
#else // USE_SD_H
31-
Serial.println(F("Using SdFat.h. Set USE_SD_H nonzero to use SD.h."));
32-
#endif // USE_SD_H
31+
Serial.println(F("Using SdFat.h. Set USE_SD_H nonzero to use SD.h."));
32+
#endif // USE_SD_H
3333
Serial.println(F("\nType any character to begin."));
3434
while (!Serial.available()) {
3535
yield();
3636
}
3737
Serial.print("Initializing SD card...");
38-
38+
3939
if (!SD.begin(SD_CS_PIN)) {
4040
Serial.println("initialization failed!");
4141
return;

examples/ExFatFormatter/ExFatFormatter.ino

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/*
55
Change the value of SD_CS_PIN if you are using SPI and
6-
your hardware does not use the default value, SS.
6+
your hardware does not use the default value, SS.
77
Common values are:
88
Arduino Ethernet shield: pin 4
99
Sparkfun SD shield: pin 8
@@ -31,6 +31,15 @@ const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
3131

3232
SdExFat sd;
3333
//------------------------------------------------------------------------------
34+
void clearSerialInput() {
35+
uint32_t m = micros();
36+
do {
37+
if (Serial.read() >= 0) {
38+
m = micros();
39+
}
40+
} while (micros() - m < 10000);
41+
}
42+
//------------------------------------------------------------------------------
3443
void errorHalt() {
3544
sd.printSdError(&Serial);
3645
SysCall::halt();
@@ -41,20 +50,17 @@ void setup() {
4150
Serial.begin(9600);
4251
while (!Serial) {}
4352
Serial.println(F("Type any character to begin"));
44-
53+
4554
while (!Serial.available()) {
4655
yield();
4756
}
48-
do {
49-
delay(10);
50-
} while(Serial.read() >= 0);
51-
57+
clearSerialInput();
5258
Serial.println();
5359
Serial.println(F(
5460
"Your SD will be formated exFAT.\r\n"
5561
"All data on the SD will be lost.\r\n"
5662
"Type 'Y' to continue.\r\n"));
57-
63+
5864
while (!Serial.available()) {
5965
yield();
6066
}
@@ -64,7 +70,7 @@ void setup() {
6470
}
6571
if (!sd.cardBegin(SD_CONFIG)) {
6672
error("cardBegin failed");
67-
}
73+
}
6874
if(!sd.format(&Serial)) {
6975
error("format failed");
7076
}

examples/ExFatLogger/ExFatLogger.ino

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ const uint32_t LOG_INTERVAL_USEC = 2000;
2424

2525
// Set USE_RTC nonzero for file timestamps.
2626
// RAM use will be marginal on Uno with RTClib.
27+
// 0 - RTC not used
28+
// 1 - DS1307
29+
// 2 - DS3231
30+
// 3 - PCF8523
2731
#define USE_RTC 0
2832
#if USE_RTC
2933
#include "RTClib.h"
@@ -151,8 +155,15 @@ file_t csvFile;
151155
char binName[] = "ExFatLogger00.bin";
152156
//------------------------------------------------------------------------------
153157
#if USE_RTC
158+
#if USE_RTC == 1
154159
RTC_DS1307 rtc;
155-
160+
#elif USE_RTC == 2
161+
RTC_DS3231 rtc;
162+
#elif USE_RTC == 3
163+
RTC_PCF8523 rtc;
164+
#else // USE_RTC == type
165+
#error USE_RTC type not implemented.
166+
#endif // USE_RTC == type
156167
// Call back for file timestamps. Only called for file create and sync().
157168
void dateTime(uint16_t* date, uint16_t* time, uint8_t* ms10) {
158169
DateTime now = rtc.now();
@@ -211,6 +222,15 @@ void binaryToCsv() {
211222
Serial.print(0.001*(millis() - t0));
212223
Serial.println(F(" Seconds"));
213224
}
225+
//------------------------------------------------------------------------------
226+
void clearSerialInput() {
227+
uint32_t m = micros();
228+
do {
229+
if (Serial.read() >= 0) {
230+
m = micros();
231+
}
232+
} while (micros() - m < 10000);
233+
}
214234
//-------------------------------------------------------------------------------
215235
void createBinFile() {
216236
binFile.close();
@@ -261,7 +281,7 @@ bool createCsvFile() {
261281
if (!csvFile.open(csvName, O_WRONLY | O_CREAT | O_TRUNC)) {
262282
error("open csvFile failed");
263283
}
264-
serialClearInput();
284+
clearSerialInput();
265285
Serial.print(F("Writing: "));
266286
Serial.print(csvName);
267287
Serial.println(F(" - type any character to stop"));
@@ -289,7 +309,7 @@ void logData() {
289309
if (binFile.write(fifoBuf, 512) != 512) {
290310
error("write first sector failed");
291311
}
292-
serialClearInput();
312+
clearSerialInput();
293313
Serial.println(F("Type any character to stop"));
294314

295315
// Wait until SD is not busy.
@@ -397,7 +417,7 @@ void logData() {
397417
//------------------------------------------------------------------------------
398418
void openBinFile() {
399419
char name[FILE_NAME_DIM];
400-
serialClearInput();
420+
clearSerialInput();
401421
Serial.println(F("Enter file name"));
402422
if (!serialReadLine(name, sizeof(name))) {
403423
return;
@@ -425,7 +445,7 @@ void printData() {
425445
if (!binFile.seekSet(512)) {
426446
error("seek failed");
427447
}
428-
serialClearInput();
448+
clearSerialInput();
429449
Serial.println(F("type any character to stop\n"));
430450
delay(1000);
431451
printRecord(&Serial, nullptr);
@@ -439,16 +459,10 @@ void printData() {
439459
}
440460
//------------------------------------------------------------------------------
441461
void printUnusedStack() {
442-
#if HAS_UNUSED_STACK
462+
#if HAS_UNUSED_STACK
443463
Serial.print(F("\nUnused stack: "));
444464
Serial.println(UnusedStack());
445-
#endif // HAS_UNUSED_STACK
446-
}
447-
//------------------------------------------------------------------------------
448-
void serialClearInput() {
449-
do {
450-
delay(10);
451-
} while (Serial.read() >= 0);
465+
#endif // HAS_UNUSED_STACK
452466
}
453467
//------------------------------------------------------------------------------
454468
bool serialReadLine(char* str, size_t size) {
@@ -476,7 +490,7 @@ void testSensor() {
476490
const uint32_t interval = 200000;
477491
int32_t diff;
478492
data_t data;
479-
serialClearInput();
493+
clearSerialInput();
480494
Serial.println(F("\nTesting - type any character to stop\n"));
481495
delay(1000);
482496
printRecord(&Serial, nullptr);
@@ -538,7 +552,7 @@ void setup() {
538552
void loop() {
539553
printUnusedStack();
540554
// Read any Serial data.
541-
serialClearInput();
555+
clearSerialInput();
542556

543557
if (ERROR_LED_PIN >= 0) {
544558
digitalWrite(ERROR_LED_PIN, LOW);

examples/OpenNext/OpenNext.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define SD_FAT_TYPE 0
99
/*
1010
Change the value of SD_CS_PIN if you are using SPI and
11-
your hardware does not use the default value, SS.
11+
your hardware does not use the default value, SS.
1212
Common values are:
1313
Arduino Ethernet shield: pin 4
1414
Sparkfun SD shield: pin 8
@@ -57,12 +57,12 @@ FsFile file;
5757
//------------------------------------------------------------------------------
5858
void setup() {
5959
Serial.begin(9600);
60-
61-
// Wait for USB Serial
60+
61+
// Wait for USB Serial
6262
while (!Serial) {
6363
SysCall::yield();
6464
}
65-
65+
6666
Serial.println("Type any character to start");
6767
while (!Serial.available()) {
6868
SysCall::yield();
@@ -72,7 +72,7 @@ void setup() {
7272
if (!sd.begin(SD_CONFIG)) {
7373
sd.initErrorHalt(&Serial);
7474
}
75-
// Open root directory
75+
// Open root directory
7676
if (!dir.open("/")){
7777
error("dir.open failed");
7878
}

examples/QuickStart/QuickStart.ino

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ void cardOrSpeed() {
4848
cout << F("Edit SPI_SPEED in this program to change it.\n");
4949
}
5050

51+
void clearSerialInput() {
52+
uint32_t m = micros();
53+
do {
54+
if (Serial.read() >= 0) {
55+
m = micros();
56+
}
57+
} while (micros() - m < 10000);
58+
}
59+
5160
void reformatMsg() {
5261
cout << F("Try reformatting the card. For best results use\n");
5362
cout << F("the SdFormatter program in SdFat/examples or download\n");
@@ -88,9 +97,7 @@ void setup() {
8897
bool firstTry = true;
8998
void loop() {
9099
// Read any existing Serial data.
91-
do {
92-
delay(10);
93-
} while (Serial.available() && Serial.read() >= 0);
100+
clearSerialInput();
94101

95102
if (!firstTry) {
96103
cout << F("\nRestarting\n");
@@ -171,9 +178,8 @@ void loop() {
171178
return;
172179
}
173180
// Read any extra Serial data.
174-
do {
175-
delay(10);
176-
} while (Serial.available() && Serial.read() >= 0);
181+
clearSerialInput();
182+
177183
cout << F("\nSuccess! Type any character to restart.\n");
178184
while (!Serial.available()) {
179185
SysCall::yield();

0 commit comments

Comments
 (0)