Просмотр исходного кода

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 лет назад
Родитель
Сommit
0f5ea19ca2
2 измененных файлов с 8 добавлено и 19 удалено
  1. 4 4
      SDcard.ino
  2. 4 15
      eventually.ino

+ 4 - 4
SDcard.ino

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

+ 4 - 15
eventually.ino

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