Skip to content

Commit 15b41e7

Browse files
author
Guðni Már Gilbert
committed
Optimise autostart_stilltocheck variable
Make the variable static within the checkautostart function. When the function is called for the first time autostart_stilltocheck is set to true and will continue to live after the function is exited. After it is set to false within checkautostart() it will continue to be false forever. Using static this way is more efficient than using a global variable Saves 6 bytes of flash and 1 byte of SRAM
1 parent 9bb8797 commit 15b41e7

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Firmware/cardreader.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ CardReader::CardReader()
3030
memset(workDirParents, 0, sizeof(workDirParents));
3131
presort_flag = false;
3232

33-
autostart_stilltocheck=true; //the SD start is delayed, because otherwise the serial cannot answer fast enough to make contact with the host software.
3433
lastnr=0;
3534
//power to SD reader
3635
#if SDPOWER > -1
@@ -614,14 +613,17 @@ void CardReader::write_command_no_newline(char *buf)
614613

615614
void CardReader::checkautostart(bool force)
616615
{
616+
// The SD start is delayed because otherwise the serial cannot answer
617+
// fast enough to make contact with the host software.
618+
static bool autostart_stilltocheck = true;
617619
if(!force)
618620
{
619621
if(!autostart_stilltocheck)
620622
return;
621623
if(autostart_atmillis.expired(5000))
622624
return;
623625
}
624-
autostart_stilltocheck=false;
626+
autostart_stilltocheck = false;
625627
if(!cardOK)
626628
{
627629
initsd();

Firmware/cardreader.h

-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ class CardReader
133133
ShortTimer autostart_atmillis;
134134
uint32_t sdpos ;
135135

136-
bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
137-
138136
uint16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory.
139137

140138
bool diveSubfolder (const char *&fileName);

0 commit comments

Comments
 (0)