Skip to content

Commit

Permalink
Timestamp fix, edit src for cplint errors
Browse files Browse the repository at this point in the history
Add time st
  • Loading branch information
greiman committed Dec 5, 2020
1 parent e7b775a commit 1535ac2
Show file tree
Hide file tree
Showing 103 changed files with 1,810 additions and 1,148 deletions.
44 changes: 28 additions & 16 deletions examples/AvrAdcLogger/AvrAdcLogger.ino
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ MinimumSerial MinSerial;
//------------------------------------------------------------------------------
// Set USE_RTC nonzero for file timestamps.
// RAM use will be marginal on Uno with RTClib.
// Set USE_RTC nonzero for file timestamps.
// RAM use will be marginal on Uno with RTClib.
// 0 - RTC not used
// 1 - DS1307
// 2 - DS3231
// 3 - PCF8523
#define USE_RTC 0
#if USE_RTC
#include "RTClib.h"
#endif
#endif // USE_RTC
//------------------------------------------------------------------------------
// Pin definitions.
//
Expand Down Expand Up @@ -141,7 +147,7 @@ const uint16_t MIN_ADC_CYCLES = 15;
// Extra cpu cycles to setup ADC with more than one pin per sample.
const uint16_t ISR_SETUP_ADC = PIN_COUNT > 1 ? 100 : 0;

// Maximum cycles for timer0 system interrupt, millis, micros.
// Maximum cycles for timer0 system interrupt.
const uint16_t ISR_TIMER0 = 160;
//==============================================================================
const uint32_t MAX_FILE_SIZE = MAX_FILE_SIZE_MiB << 20;
Expand Down Expand Up @@ -303,8 +309,15 @@ void printUnusedStack() {
}
//------------------------------------------------------------------------------
#if USE_RTC
#if USE_RTC == 1
RTC_DS1307 rtc;

#elif USE_RTC == 2
RTC_DS3231 rtc;
#elif USE_RTC == 3
RTC_PCF8523 rtc;
#else // USE_RTC == type
#error USE_RTC type not implemented.
#endif // USE_RTC == type
// Call back for file timestamps. Only called for file create and sync().
void dateTime(uint16_t* date, uint16_t* time, uint8_t* ms10) {
DateTime now = rtc.now();
Expand Down Expand Up @@ -553,6 +566,15 @@ void binaryToCsv() {
Serial.println(F(" Seconds"));
}
//------------------------------------------------------------------------------
void clearSerialInput() {
uint32_t m = micros();
do {
if (Serial.read() >= 0) {
m = micros();
}
} while (micros() - m < 10000);
}
//------------------------------------------------------------------------------
void createBinFile() {
binFile.close();
while (sd.exists(binName)) {
Expand Down Expand Up @@ -719,7 +741,7 @@ void logData() {
//------------------------------------------------------------------------------
void openBinFile() {
char name[NAME_DIM];
serialClearInput();
clearSerialInput();
Serial.println(F("Enter file name"));
if (!serialReadLine(name, sizeof(name))) {
return;
Expand Down Expand Up @@ -772,12 +794,6 @@ void printData() {
Serial.println(F("Done"));
}
//------------------------------------------------------------------------------
void serialClearInput() {
do {
delay(10);
} while (Serial.read() >= 0);
}
//------------------------------------------------------------------------------
bool serialReadLine(char* str, size_t size) {
size_t n = 0;
while(!Serial.available()) {
Expand Down Expand Up @@ -840,9 +856,7 @@ void setup(void) {
void loop(void) {
printUnusedStack();
// Read any Serial data.
do {
delay(10);
} while (Serial.available() && Serial.read() >= 0);
clearSerialInput();
Serial.println();
Serial.println(F("type:"));
Serial.println(F("b - open existing bin file"));
Expand All @@ -860,9 +874,7 @@ void loop(void) {
digitalWrite(ERROR_LED_PIN, LOW);
}
// Read any Serial data.
do {
delay(10);
} while (Serial.available() && Serial.read() >= 0);
clearSerialInput();

if (c == 'b') {
openBinFile();
Expand Down
8 changes: 4 additions & 4 deletions examples/BackwardCompatibility/BackwardCompatibility.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// A simple read/write example for SD.h.
// Mostly from the SD.h ReadWrite example.
//
//
// Your SD must be formatted FAT16/FAT32.
//
// Set USE_SD_H nonzero to use SD.h.
Expand Down Expand Up @@ -28,14 +28,14 @@ void setup() {
#if USE_SD_H
Serial.println(F("Using SD.h. Set USE_SD_H zero to use SdFat.h."));
#else // USE_SD_H
Serial.println(F("Using SdFat.h. Set USE_SD_H nonzero to use SD.h."));
#endif // USE_SD_H
Serial.println(F("Using SdFat.h. Set USE_SD_H nonzero to use SD.h."));
#endif // USE_SD_H
Serial.println(F("\nType any character to begin."));
while (!Serial.available()) {
yield();
}
Serial.print("Initializing SD card...");

if (!SD.begin(SD_CS_PIN)) {
Serial.println("initialization failed!");
return;
Expand Down
22 changes: 14 additions & 8 deletions examples/ExFatFormatter/ExFatFormatter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

SdExFat sd;
//------------------------------------------------------------------------------
void clearSerialInput() {
uint32_t m = micros();
do {
if (Serial.read() >= 0) {
m = micros();
}
} while (micros() - m < 10000);
}
//------------------------------------------------------------------------------
void errorHalt() {
sd.printSdError(&Serial);
SysCall::halt();
Expand All @@ -41,20 +50,17 @@ void setup() {
Serial.begin(9600);
while (!Serial) {}
Serial.println(F("Type any character to begin"));

while (!Serial.available()) {
yield();
}
do {
delay(10);
} while(Serial.read() >= 0);

clearSerialInput();
Serial.println();
Serial.println(F(
"Your SD will be formated exFAT.\r\n"
"All data on the SD will be lost.\r\n"
"Type 'Y' to continue.\r\n"));

while (!Serial.available()) {
yield();
}
Expand All @@ -64,7 +70,7 @@ void setup() {
}
if (!sd.cardBegin(SD_CONFIG)) {
error("cardBegin failed");
}
}
if(!sd.format(&Serial)) {
error("format failed");
}
Expand Down
44 changes: 29 additions & 15 deletions examples/ExFatLogger/ExFatLogger.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const uint32_t LOG_INTERVAL_USEC = 2000;

// Set USE_RTC nonzero for file timestamps.
// RAM use will be marginal on Uno with RTClib.
// 0 - RTC not used
// 1 - DS1307
// 2 - DS3231
// 3 - PCF8523
#define USE_RTC 0
#if USE_RTC
#include "RTClib.h"
Expand Down Expand Up @@ -151,8 +155,15 @@ file_t csvFile;
char binName[] = "ExFatLogger00.bin";
//------------------------------------------------------------------------------
#if USE_RTC
#if USE_RTC == 1
RTC_DS1307 rtc;

#elif USE_RTC == 2
RTC_DS3231 rtc;
#elif USE_RTC == 3
RTC_PCF8523 rtc;
#else // USE_RTC == type
#error USE_RTC type not implemented.
#endif // USE_RTC == type
// Call back for file timestamps. Only called for file create and sync().
void dateTime(uint16_t* date, uint16_t* time, uint8_t* ms10) {
DateTime now = rtc.now();
Expand Down Expand Up @@ -211,6 +222,15 @@ void binaryToCsv() {
Serial.print(0.001*(millis() - t0));
Serial.println(F(" Seconds"));
}
//------------------------------------------------------------------------------
void clearSerialInput() {
uint32_t m = micros();
do {
if (Serial.read() >= 0) {
m = micros();
}
} while (micros() - m < 10000);
}
//-------------------------------------------------------------------------------
void createBinFile() {
binFile.close();
Expand Down Expand Up @@ -261,7 +281,7 @@ bool createCsvFile() {
if (!csvFile.open(csvName, O_WRONLY | O_CREAT | O_TRUNC)) {
error("open csvFile failed");
}
serialClearInput();
clearSerialInput();
Serial.print(F("Writing: "));
Serial.print(csvName);
Serial.println(F(" - type any character to stop"));
Expand Down Expand Up @@ -289,7 +309,7 @@ void logData() {
if (binFile.write(fifoBuf, 512) != 512) {
error("write first sector failed");
}
serialClearInput();
clearSerialInput();
Serial.println(F("Type any character to stop"));

// Wait until SD is not busy.
Expand Down Expand Up @@ -397,7 +417,7 @@ void logData() {
//------------------------------------------------------------------------------
void openBinFile() {
char name[FILE_NAME_DIM];
serialClearInput();
clearSerialInput();
Serial.println(F("Enter file name"));
if (!serialReadLine(name, sizeof(name))) {
return;
Expand Down Expand Up @@ -425,7 +445,7 @@ void printData() {
if (!binFile.seekSet(512)) {
error("seek failed");
}
serialClearInput();
clearSerialInput();
Serial.println(F("type any character to stop\n"));
delay(1000);
printRecord(&Serial, nullptr);
Expand All @@ -439,16 +459,10 @@ void printData() {
}
//------------------------------------------------------------------------------
void printUnusedStack() {
#if HAS_UNUSED_STACK
#if HAS_UNUSED_STACK
Serial.print(F("\nUnused stack: "));
Serial.println(UnusedStack());
#endif // HAS_UNUSED_STACK
}
//------------------------------------------------------------------------------
void serialClearInput() {
do {
delay(10);
} while (Serial.read() >= 0);
#endif // HAS_UNUSED_STACK
}
//------------------------------------------------------------------------------
bool serialReadLine(char* str, size_t size) {
Expand Down Expand Up @@ -476,7 +490,7 @@ void testSensor() {
const uint32_t interval = 200000;
int32_t diff;
data_t data;
serialClearInput();
clearSerialInput();
Serial.println(F("\nTesting - type any character to stop\n"));
delay(1000);
printRecord(&Serial, nullptr);
Expand Down Expand Up @@ -538,7 +552,7 @@ void setup() {
void loop() {
printUnusedStack();
// Read any Serial data.
serialClearInput();
clearSerialInput();

if (ERROR_LED_PIN >= 0) {
digitalWrite(ERROR_LED_PIN, LOW);
Expand Down
10 changes: 5 additions & 5 deletions examples/OpenNext/OpenNext.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define SD_FAT_TYPE 0
/*
Change the value of SD_CS_PIN if you are using SPI and
your hardware does not use the default value, SS.
your hardware does not use the default value, SS.
Common values are:
Arduino Ethernet shield: pin 4
Sparkfun SD shield: pin 8
Expand Down Expand Up @@ -57,12 +57,12 @@ FsFile file;
//------------------------------------------------------------------------------
void setup() {
Serial.begin(9600);
// Wait for USB Serial

// Wait for USB Serial
while (!Serial) {
SysCall::yield();
}

Serial.println("Type any character to start");
while (!Serial.available()) {
SysCall::yield();
Expand All @@ -72,7 +72,7 @@ void setup() {
if (!sd.begin(SD_CONFIG)) {
sd.initErrorHalt(&Serial);
}
// Open root directory
// Open root directory
if (!dir.open("/")){
error("dir.open failed");
}
Expand Down
18 changes: 12 additions & 6 deletions examples/QuickStart/QuickStart.ino
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ void cardOrSpeed() {
cout << F("Edit SPI_SPEED in this program to change it.\n");
}

void clearSerialInput() {
uint32_t m = micros();
do {
if (Serial.read() >= 0) {
m = micros();
}
} while (micros() - m < 10000);
}

void reformatMsg() {
cout << F("Try reformatting the card. For best results use\n");
cout << F("the SdFormatter program in SdFat/examples or download\n");
Expand Down Expand Up @@ -88,9 +97,7 @@ void setup() {
bool firstTry = true;
void loop() {
// Read any existing Serial data.
do {
delay(10);
} while (Serial.available() && Serial.read() >= 0);
clearSerialInput();

if (!firstTry) {
cout << F("\nRestarting\n");
Expand Down Expand Up @@ -171,9 +178,8 @@ void loop() {
return;
}
// Read any extra Serial data.
do {
delay(10);
} while (Serial.available() && Serial.read() >= 0);
clearSerialInput();

cout << F("\nSuccess! Type any character to restart.\n");
while (!Serial.available()) {
SysCall::yield();
Expand Down
Loading

0 comments on commit 1535ac2

Please sign in to comment.