Browse Source

bugfix : small delay while reading button file

added LF to the last line of all files, was causing readStringUntil to
wait for timeout.
Set timeout to 100ms to ensure fast response even if LF is lacking or
any other miswriting to come
all buttons are now very reactive and no freeze was seen after some
hours of tests
Etienne Landon 7 years ago
parent
commit
0f5ea19ca2
2 changed files with 8 additions and 19 deletions
  1. 4 4
      SDcard.ino
  2. 4 15
      eventually.ino

+ 4 - 4
SDcard.ino

@@ -63,9 +63,10 @@ bool readSDconfig(){
 bool readSDFile() {
 bool readSDFile() {
   
   
   if (!inibSDreading) { // if currently delaying, don't read a line 
   if (!inibSDreading) { // if currently delaying, don't read a line 
+    
     if (btnFile.available()) {
     if (btnFile.available()) {
       buf = btnFile.readStringUntil('\n');
       buf = btnFile.readStringUntil('\n');
-      Serial.println("readline");
+      //Serial.println("readline");
       //check selector (1st word of line) and execute corresponding function
       //check selector (1st word of line) and execute corresponding function
       String selector = getSubstring(buf, ' ', 0);
       String selector = getSubstring(buf, ' ', 0);
       //Serial.println(selector);
       //Serial.println(selector);
@@ -183,7 +184,7 @@ bool readSDFile() {
         //delay(wait.toInt());
         //delay(wait.toInt());
       }
       }
   
   
-      //else if (selector == ""){}
+      else if (selector == ""){}
      
      
       else {
       else {
         Serial.print(selector);
         Serial.print(selector);
@@ -196,8 +197,7 @@ bool readSDFile() {
     else {
     else {
       Serial.println("EOF");
       Serial.println("EOF");
       inibSDreading = true;
       inibSDreading = true;
-      Serial.println(inibSDreading);
-//      btnFile.close();
+      //btnFile.close();
       //EvtResetButtonContext();
       //EvtResetButtonContext();
       
       
       
       

+ 4 - 15
eventually.ino

@@ -77,7 +77,8 @@ void buttonFocus(int index) {
   String file = "button";
   String file = "button";
   file+=index ;
   file+=index ;
   file+=".txt";
   file+=".txt";
-  btnFile = SD.open(file.c_str()) ;
+  btnFile = SD.open(file.c_str(), FILE_READ) ;
+  btnFile.setTimeout(100);
   //btnFile = SD.open("button0.txt");
   //btnFile = SD.open("button0.txt");
   Serial.println("");
   Serial.println("");
   Serial.println("opening " + file);
   Serial.println("opening " + file);
@@ -88,11 +89,11 @@ void buttonFocus(int index) {
 //   while(
 //   while(
    
    
    EvtResetButtonContext() ; //clean context before starting reading the file
    EvtResetButtonContext() ; //clean context before starting reading the file
-   Serial.println("ended buttonReset");
+   //Serial.println("ended buttonReset");
    delay_length = 0 ;
    delay_length = 0 ;
    inibSDreading = false ;
    inibSDreading = false ;
    
    
-   Serial.println("ended focus");
+   //Serial.println("ended focus");
    //mgr.addListener(new EvtTimeListener(10, true, (EvtAction)readSDFile));
    //mgr.addListener(new EvtTimeListener(10, true, (EvtAction)readSDFile));
    //mgr.addListener(new EvtTimeListener(50, true, (EvtAction)fadeDimmer));
    //mgr.addListener(new EvtTimeListener(50, true, (EvtAction)fadeDimmer));
    //readSDFile();
    //readSDFile();
@@ -138,34 +139,22 @@ void audioVolume(){
 
 
 bool button0(){
 bool button0(){
   buttonFocus(0) ;
   buttonFocus(0) ;
-  //lustre_targetPalette = palette_FLAMINGO ;
-  //lustre_currentBrightness = 255;
   return false;
   return false;
 }
 }
 bool button1(){
 bool button1(){
   buttonFocus(1) ;
   buttonFocus(1) ;
-  //lustre_targetPalette = palette_SOLEIL;
-  //lustre_currentBrightness = 0;
-//  testAll(); 
   return false;
   return false;
 }
 }
 bool button2(){
 bool button2(){
   buttonFocus(2) ;
   buttonFocus(2) ;
-  //lustre_targetPalette = palette_CREPUSCULE ;
-  //lustre_currentBrightness = 0;
-  
   return false;
   return false;
 }
 }
 bool button3(){
 bool button3(){
   buttonFocus(3) ;
   buttonFocus(3) ;
-  //lustre_targetPalette =palette_MER;
-  //lustre_currentBrightness = 0;
   return false;
   return false;
 }
 }
 bool button4(){
 bool button4(){
   buttonFocus(4) ;
   buttonFocus(4) ;
-  //lustre_currentBrightness = 0;
-//  stopAll();
   return false;
   return false;
 }
 }
 bool button5(){
 bool button5(){