173
173
Adds 80 bytes
174
174
175
175
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
+
177
182
*/
178
183
179
184
#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)
456
461
char new_file_name[13 ];
457
462
while (1 )
458
463
{
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
460
465
461
466
// Try to open file, if fail (file doesn't exist), then break
462
467
if (newFile.open (¤tDirectory, new_file_name, O_CREAT | O_EXCL | O_WRITE)) break ;
@@ -569,14 +574,14 @@ byte append_file(char* file_name)
569
574
{
570
575
// Start recording incoming characters
571
576
// 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
576
581
{
577
- workingFile.write (localBuffer, n ); // Record the buffer to the card
582
+ workingFile.write (localBuffer, charsToRecord ); // Record the buffer to the card
578
583
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
580
585
581
586
if ((millis () - lastSyncTime) > MAX_TIME_BEFORE_SYNC_MSEC) // This will force a sync approximately every 5 seconds
582
587
{
@@ -603,31 +608,34 @@ byte append_file(char* file_name)
603
608
escape_chars_received = 0 ; // Clear the esc flag as it has timed out
604
609
lastSyncTime = millis (); // Reset the last sync time to now
605
610
}
606
-
607
611
}
608
-
609
612
}
610
613
611
614
// We only get this far if escape characters are more than zero
612
615
613
616
// Start recording incoming characters
614
- while (escape_chars_received < setting_max_escape_character) {
617
+ while (escape_chars_received < setting_max_escape_character)
618
+ {
615
619
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
618
622
{
619
623
620
624
if (localBuffer[0 ] == setting_escape_character)
621
625
{
622
626
escape_chars_received++;
623
627
624
628
// Scan the local buffer for esacape characters
625
- for (checkedSpot = 1 ; checkedSpot < n ; checkedSpot++) {
629
+ for (checkedSpot = 1 ; checkedSpot < charsToRecord ; checkedSpot++)
630
+ {
626
631
if (localBuffer[checkedSpot] == setting_escape_character) {
627
632
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
629
634
// 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
+ }
631
639
}
632
640
else
633
641
escape_chars_received = 0 ;
@@ -636,9 +644,9 @@ byte append_file(char* file_name)
636
644
else
637
645
escape_chars_received = 0 ;
638
646
639
- workingFile.write (localBuffer, n ); // Record the buffer to the card
647
+ workingFile.write (localBuffer, charsToRecord ); // Record the buffer to the card
640
648
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
642
650
643
651
if ((millis () - lastSyncTime) > MAX_TIME_BEFORE_SYNC_MSEC) // This will force a sync approximately every 5 seconds
644
652
{
@@ -712,12 +720,12 @@ void check_emergency_reset(void)
712
720
for (byte i = 0 ; i < 40 ; i++)
713
721
{
714
722
delay (25 );
715
- STAT1_PORT ^= (1 <<STAT1); // Blink the stat LEDs
723
+ toggleLED (statled1); // STAT1_PORT ^= (1<<STAT1); //Blink the stat LEDs
716
724
717
725
if (digitalRead (0 ) == HIGH) return ; // Check to see if RX is not low anymore
718
726
719
727
delay (25 );
720
- STAT2_PORT ^= (1 <<STAT2); // Blink the stat LEDs
728
+ toggleLED (statled2); // STAT2_PORT ^= (1<<STAT2); //Blink the stat LEDs
721
729
722
730
if (digitalRead (0 ) == HIGH) return ; // Check to see if RX is not low anymore
723
731
}
@@ -742,8 +750,8 @@ void check_emergency_reset(void)
742
750
while (1 )
743
751
{
744
752
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
747
755
}
748
756
}
749
757
@@ -1856,7 +1864,9 @@ byte read_line(char* buffer, byte buffer_length)
1856
1864
while (!NewSerial.available ());
1857
1865
byte c = NewSerial.read ();
1858
1866
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);
1860
1870
1861
1871
if (c == 0x08 || c == 0x7f ) { // Backspace characters
1862
1872
if (read_length < 1 )
@@ -2528,4 +2538,10 @@ byte lsPrintNext(SdFile * theDir, char * cmdStr, byte flags, byte indent)
2528
2538
return status;
2529
2539
}
2530
2540
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