add logging disabled when connected via usb
This commit is contained in:
parent
7b757c3c0b
commit
71e9fd7d4f
|
@ -318,7 +318,11 @@ void display_standingDisarmedDisplay(ESCSerialComm& escFront, ESCSerialComm& esc
|
||||||
display.setFont();
|
display.setFont();
|
||||||
display.setCursor(0,0);
|
display.setCursor(0,0);
|
||||||
|
|
||||||
display.print(getLogFilename());
|
if (datalogging) {
|
||||||
|
display.print(getLogFilename());
|
||||||
|
}else{
|
||||||
|
display.print("LOG DISABLED");
|
||||||
|
}
|
||||||
|
|
||||||
display.print(F(" ")); display.print(loopmillis/1000);
|
display.print(F(" ")); display.print(loopmillis/1000);
|
||||||
display.print(F("s"));
|
display.print(F("s"));
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <SD.h> //Format sd cart with FAT or FAT16. FAT32 for >1GB Cards on Teensy4.1
|
#include <SD.h> //Format sd cart with FAT or FAT16. FAT32 for >1GB Cards on Teensy4.1
|
||||||
|
|
||||||
//#define SDCHIPSELECT 14
|
//#define SDCHIPSELECT 14
|
||||||
|
boolean sdcard_available=false;
|
||||||
boolean datalogging=true;
|
boolean datalogging=true;
|
||||||
String datalogging_filename="UNKNOWN.txt";
|
String datalogging_filename="UNKNOWN.txt";
|
||||||
|
|
||||||
|
@ -23,34 +24,46 @@ void serialCommandLoop();
|
||||||
|
|
||||||
|
|
||||||
bool initLogging() {
|
bool initLogging() {
|
||||||
Serial.print("Initializing SD card...");
|
Serial.print("Datalogging is ");
|
||||||
// see if the card is present and can be initialized:
|
if (datalogging) {
|
||||||
if (!SD.begin(BUILTIN_SDCARD)) {
|
Serial.println("enabled");
|
||||||
Serial.println("Card failed, or not present");
|
}else{
|
||||||
display.println(F("SD Init Fail!")); display.display();
|
Serial.println("disabled");
|
||||||
datalogging=false; //disable logging
|
}
|
||||||
delay(1000);
|
Serial.print("Initializing SD card...");
|
||||||
return false;
|
// see if the card is present and can be initialized:
|
||||||
}else{
|
if (!SD.begin(BUILTIN_SDCARD)) {
|
||||||
Serial.println("Card initialized.");
|
Serial.println("Card failed, or not present");
|
||||||
display.print(F("LOG=")); display.display();
|
display.println(F("SD Init Fail!")); display.display();
|
||||||
if (datalogging){
|
sdcard_available=false; //disable logging
|
||||||
int filenumber=0;
|
datalogging=false;
|
||||||
char buffer[6];
|
delay(1000);
|
||||||
|
return false;
|
||||||
|
}else{
|
||||||
|
sdcard_available=true;
|
||||||
|
Serial.println("Card initialized.");
|
||||||
|
display.print(F("LOG=")); display.display();
|
||||||
|
|
||||||
|
int filenumber=0;
|
||||||
|
char buffer[6];
|
||||||
|
sprintf(buffer, "%04d", filenumber);
|
||||||
|
datalogging_filename="LOG_"+String(buffer)+".TXT";
|
||||||
|
while(SD.exists(datalogging_filename.c_str()) && filenumber<10000) {
|
||||||
|
//Serial.print(datalogging_filename); Serial.println(" exists");
|
||||||
|
filenumber++;
|
||||||
sprintf(buffer, "%04d", filenumber);
|
sprintf(buffer, "%04d", filenumber);
|
||||||
datalogging_filename="LOG_"+String(buffer)+".TXT";
|
datalogging_filename="LOG_"+String(buffer)+".TXT";
|
||||||
while(SD.exists(datalogging_filename.c_str()) && filenumber<10000) {
|
|
||||||
//Serial.print(datalogging_filename); Serial.println(" exists");
|
|
||||||
filenumber++;
|
|
||||||
sprintf(buffer, "%04d", filenumber);
|
|
||||||
datalogging_filename="LOG_"+String(buffer)+".TXT";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Serial.print(datalogging_filename); Serial.println(" is free");
|
Serial.print(datalogging_filename); Serial.println(" is free");
|
||||||
display.print(datalogging_filename); display.println(); display.display();
|
display.print(datalogging_filename);
|
||||||
}
|
if (!datalogging) { //datalogging is disabled during boot
|
||||||
}
|
display.print( "NO LOG");
|
||||||
return true;
|
}
|
||||||
|
display.println(); display.display();
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,7 +71,7 @@ void loggingLoop(unsigned long loopmillis,ESCSerialComm& escFront, ESCSerialComm
|
||||||
|
|
||||||
static unsigned long last_datalogging_write=0;
|
static unsigned long last_datalogging_write=0;
|
||||||
static boolean logging_headerWritten=false;
|
static boolean logging_headerWritten=false;
|
||||||
if (datalogging) {
|
if (datalogging && sdcard_available) {
|
||||||
#define LOGGINGINTERVAL 100
|
#define LOGGINGINTERVAL 100
|
||||||
if (loopmillis-last_datalogging_write>LOGGINGINTERVAL)
|
if (loopmillis-last_datalogging_write>LOGGINGINTERVAL)
|
||||||
{
|
{
|
||||||
|
@ -123,7 +136,7 @@ void loggingLoop(unsigned long loopmillis,ESCSerialComm& escFront, ESCSerialComm
|
||||||
|
|
||||||
void writeLogComment(unsigned long time, String msg) {
|
void writeLogComment(unsigned long time, String msg) {
|
||||||
//SerialRef.print("#"); SerialRef.print(time/1000.0,3); SerialRef.print(","); SerialRef.print(msg); SerialRef.println();
|
//SerialRef.print("#"); SerialRef.print(time/1000.0,3); SerialRef.print(","); SerialRef.print(msg); SerialRef.println();
|
||||||
if (datalogging) {
|
if (datalogging && sdcard_available) {
|
||||||
File dataFile = SD.open(datalogging_filename.c_str(), FILE_WRITE);
|
File dataFile = SD.open(datalogging_filename.c_str(), FILE_WRITE);
|
||||||
|
|
||||||
if (dataFile) { // if the file is available, write to it
|
if (dataFile) { // if the file is available, write to it
|
||||||
|
@ -156,6 +169,7 @@ bool loadTripSD()
|
||||||
myFile.close();
|
myFile.close();
|
||||||
Serial.println("TripSD: time written");
|
Serial.println("TripSD: time written");
|
||||||
}else{
|
}else{
|
||||||
|
Serial.println("TripSD: could not open stats.txt");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +212,7 @@ bool loadTripSD()
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeTrip(unsigned long loopmillis,ESCSerialComm& escFront, ESCSerialComm& escRear) {
|
void writeTrip(unsigned long loopmillis,ESCSerialComm& escFront, ESCSerialComm& escRear) {
|
||||||
if (datalogging) {
|
if (datalogging && sdcard_available) {
|
||||||
File myFile = SD.open("stats.txt", FILE_WRITE);
|
File myFile = SD.open("stats.txt", FILE_WRITE);
|
||||||
if (myFile) {
|
if (myFile) {
|
||||||
myFile.print("trp=");
|
myFile.print("trp=");
|
||||||
|
@ -216,7 +230,7 @@ void writeTrip(unsigned long loopmillis,ESCSerialComm& escFront, ESCSerialComm&
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetTrip() {
|
void resetTrip() {
|
||||||
if (datalogging) {
|
if (datalogging && sdcard_available) {
|
||||||
File myFile = SD.open("stats.txt", FILE_WRITE);
|
File myFile = SD.open("stats.txt", FILE_WRITE);
|
||||||
if (myFile) {
|
if (myFile) {
|
||||||
myFile.print("trp=");
|
myFile.print("trp=");
|
||||||
|
|
|
@ -69,11 +69,12 @@ void setup()
|
||||||
|
|
||||||
Serial1.begin(SERIAL_LOG_BAUD); //TX1=1, RX1=0
|
Serial1.begin(SERIAL_LOG_BAUD); //TX1=1, RX1=0
|
||||||
|
|
||||||
//Serial2.begin(SERIAL_CONTROL_BAUD); //control, TX2=10, RX2=9
|
|
||||||
//Serial3.begin(SERIAL_CONTROL_BAUD); //control, TX3=8, RX3=7
|
|
||||||
|
|
||||||
|
|
||||||
pinMode(PIN_PWRBUTTON, INPUT_PULLUP); //Pressed=High
|
pinMode(PIN_PWRBUTTON, INPUT_PULLUP); //Pressed=High
|
||||||
|
if (!digitalRead(PIN_PWRBUTTON)) { //button is not pressed during startup means teensy is powered externally (usb)
|
||||||
|
datalogging=false; //disable logging when connected via usb to not clutter up sd card
|
||||||
|
Serial.println("PWRBUTTON not pressed. Logging disabled!");
|
||||||
|
}
|
||||||
|
|
||||||
pinMode(PIN_LED_START, OUTPUT); //Active High
|
pinMode(PIN_LED_START, OUTPUT); //Active High
|
||||||
|
|
||||||
|
@ -102,7 +103,7 @@ void setup()
|
||||||
|
|
||||||
|
|
||||||
initResult=initLogging();
|
initResult=initLogging();
|
||||||
led_simpeProgress(2,initResult);
|
led_simpeProgress(2,(initResult ? (datalogging ? 1:2):0)); //0=sd card fail, 1=sd ok and logging, 2(warn)=sd ok and logging off
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -146,7 +147,7 @@ void setup()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (datalogging) { //sd init was successful
|
if (sdcard_available) { //sd init was successful
|
||||||
initResult=loadTripSD();
|
initResult=loadTripSD();
|
||||||
}else{
|
}else{
|
||||||
initResult=false;
|
initResult=false;
|
||||||
|
|
Loading…
Reference in New Issue