Skip to content

Commit a7c7fb7

Browse files
committed
Fixed bug 178. Log numbers should display correctly over 15 bits.
1 parent e798391 commit a7c7fb7

File tree

1 file changed

+40
-24
lines changed

1 file changed

+40
-24
lines changed

firmware/OpenLog_v3/OpenLog_v3.ino

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,12 @@
173173
Adds 80 bytes
174174
175175
Increased escape character limits to 0 and 254. If set to zero, it will not check for escape characters.
176-
176+
177+
8/20/2015
178+
Using codebender because Arduino IDE is unusable on a laptop with a high density screen. Grrr.
179+
Working on issue 168.
180+
Fixed issue 178. Thanks jremington!
181+
177182
*/
178183

179184
#include <SdFat.h> //We do not use the built-in SD.h file because it calls Serial.print
@@ -456,7 +461,7 @@ char* newlog(void)
456461
char new_file_name[13];
457462
while(1)
458463
{
459-
sprintf_P(new_file_name, PSTR("LOG%05d.TXT"), new_file_number); //Splice the new file number into this file name
464+
sprintf_P(new_file_name, PSTR("LOG%05u.TXT"), new_file_number); //Splice the new file number into this file name
460465

461466
//Try to open file, if fail (file doesn't exist), then break
462467
if (newFile.open(&currentDirectory, new_file_name, O_CREAT | O_EXCL | O_WRITE)) break;
@@ -569,14 +574,14 @@ byte append_file(char* file_name)
569574
{
570575
//Start recording incoming characters
571576
//With no escape characters, do this infinitely
572-
while(1) {
573-
574-
byte n = NewSerial.read(localBuffer, sizeof(localBuffer)); //Read characters from global buffer into the local buffer
575-
if (n > 0) //If we have characters, check for escape characters
577+
while(1)
578+
{
579+
byte charsToRecord = NewSerial.read(localBuffer, sizeof(localBuffer)); //Read characters from global buffer into the local buffer
580+
if (charsToRecord > 0) //If we have characters, check for escape characters
576581
{
577-
workingFile.write(localBuffer, n); //Record the buffer to the card
582+
workingFile.write(localBuffer, charsToRecord); //Record the buffer to the card
578583

579-
STAT1_PORT ^= (1<<STAT1); //Toggle the STAT1 LED each time we record the buffer
584+
toggleLED(statled1); //STAT1_PORT ^= (1<<STAT1); //Toggle the STAT1 LED each time we record the buffer
580585

581586
if((millis() - lastSyncTime) > MAX_TIME_BEFORE_SYNC_MSEC) //This will force a sync approximately every 5 seconds
582587
{
@@ -603,31 +608,34 @@ byte append_file(char* file_name)
603608
escape_chars_received = 0; // Clear the esc flag as it has timed out
604609
lastSyncTime = millis(); //Reset the last sync time to now
605610
}
606-
607611
}
608-
609612
}
610613

611614
//We only get this far if escape characters are more than zero
612615

613616
//Start recording incoming characters
614-
while(escape_chars_received < setting_max_escape_character) {
617+
while(escape_chars_received < setting_max_escape_character)
618+
{
615619

616-
byte n = NewSerial.read(localBuffer, sizeof(localBuffer)); //Read characters from global buffer into the local buffer
617-
if (n > 0) //If we have characters, check for escape characters
620+
byte charsToRecord = NewSerial.read(localBuffer, sizeof(localBuffer)); //Read characters from global buffer into the local buffer
621+
if (charsToRecord > 0) //If we have characters, check for escape characters
618622
{
619623

620624
if (localBuffer[0] == setting_escape_character)
621625
{
622626
escape_chars_received++;
623627

624628
//Scan the local buffer for esacape characters
625-
for(checkedSpot = 1 ; checkedSpot < n ; checkedSpot++) {
629+
for(checkedSpot = 1 ; checkedSpot < charsToRecord ; checkedSpot++)
630+
{
626631
if(localBuffer[checkedSpot] == setting_escape_character) {
627632
escape_chars_received++;
628-
//If n is greater than 3 there's a chance here where we receive three esc chars
633+
//If charsToRecord is greater than 3 there's a chance here where we receive three esc chars
629634
// and then reset the variable: 26 26 26 A T + would not escape correctly
630-
if(escape_chars_received == setting_max_escape_character) break;
635+
if(escape_chars_received == setting_max_escape_character)
636+
{
637+
break;
638+
}
631639
}
632640
else
633641
escape_chars_received = 0;
@@ -636,9 +644,9 @@ byte append_file(char* file_name)
636644
else
637645
escape_chars_received = 0;
638646

639-
workingFile.write(localBuffer, n); //Record the buffer to the card
647+
workingFile.write(localBuffer, charsToRecord); //Record the buffer to the card
640648

641-
STAT1_PORT ^= (1<<STAT1); //Toggle the STAT1 LED each time we record the buffer
649+
toggleLED(statled1); //STAT1_PORT ^= (1<<STAT1); //Toggle the STAT1 LED each time we record the buffer
642650

643651
if((millis() - lastSyncTime) > MAX_TIME_BEFORE_SYNC_MSEC) //This will force a sync approximately every 5 seconds
644652
{
@@ -712,12 +720,12 @@ void check_emergency_reset(void)
712720
for(byte i = 0 ; i < 40 ; i++)
713721
{
714722
delay(25);
715-
STAT1_PORT ^= (1<<STAT1); //Blink the stat LEDs
723+
toggleLED(statled1); //STAT1_PORT ^= (1<<STAT1); //Blink the stat LEDs
716724

717725
if(digitalRead(0) == HIGH) return; //Check to see if RX is not low anymore
718726

719727
delay(25);
720-
STAT2_PORT ^= (1<<STAT2); //Blink the stat LEDs
728+
toggleLED(statled2); //STAT2_PORT ^= (1<<STAT2); //Blink the stat LEDs
721729

722730
if(digitalRead(0) == HIGH) return; //Check to see if RX is not low anymore
723731
}
@@ -742,8 +750,8 @@ void check_emergency_reset(void)
742750
while(1)
743751
{
744752
delay(500);
745-
STAT1_PORT ^= (1<<STAT1); //Blink the stat LEDs
746-
STAT2_PORT ^= (1<<STAT2); //Blink the stat LEDs
753+
toggleLED(statled1); //STAT1_PORT ^= (1<<STAT1); //Blink the stat LEDs
754+
toggleLED(statled2); //STAT2_PORT ^= (1<<STAT2); //Blink the stat LEDs
747755
}
748756
}
749757

@@ -1856,7 +1864,9 @@ byte read_line(char* buffer, byte buffer_length)
18561864
while (!NewSerial.available());
18571865
byte c = NewSerial.read();
18581866

1859-
STAT1_PORT ^= (1<<STAT1); //Blink the stat LED while typing
1867+
//This fails to compile in Arduino 1.6.1
1868+
//STAT1_PORT ^= (1<<STAT1); //Blink the stat LED while typing
1869+
toggleLED(statled1);
18601870

18611871
if(c == 0x08 || c == 0x7f) { //Backspace characters
18621872
if(read_length < 1)
@@ -2528,4 +2538,10 @@ byte lsPrintNext(SdFile * theDir, char * cmdStr, byte flags, byte indent)
25282538
return status;
25292539
}
25302540

2531-
2541+
//Given a pin, it will toggle it from high to low or vice versa
2542+
void toggleLED(byte pinNumber)
2543+
{
2544+
if(digitalRead(pinNumber)) digitalWrite(pinNumber, LOW);
2545+
else digitalWrite(pinNumber, HIGH);
2546+
}
2547+

0 commit comments

Comments
 (0)