123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- ///////////////////////// SD ////////////////////////////////////////////
- String getSubstring(String dataString, char separator, int index)
- {
- int found = 0;
- int strIndex[] = { 0, -1 };
- int maxIndex = dataString.length() - 1;
- for (int i = 0; i <= maxIndex && found <= index; i++) {
- if (dataString.charAt(i) == separator || i == maxIndex) {
- found++;
- strIndex[0] = strIndex[1] + 1;
- strIndex[1] = (i == maxIndex) ? i+1 : i;
- }
- }
- return found > index ? dataString.substring(strIndex[0], strIndex[1]) : "";
- }
- bool readSDFile() {
-
- if (!inibSDreading) { // if currently delaying, don't read a line
- if (btnFile.available()) {
- buf = btnFile.readStringUntil('\n');
-
- //check selector (1st word of line) and execute corresponding function
- String selector = getSubstring(buf, ' ', 0);
- //Serial.println(selector);
-
- if (selector == "sound") {
- String track = getSubstring(buf, ' ', 2) ;
- String out = getSubstring(buf, ' ', 1) ;
- Serial.println("Playing track " + track + " to output " + out);
- tsunami.trackPlayPoly(track.toInt(), out.toInt()-1, true);
- }
-
- else if (selector == "led") {
- // String mode = getSubstring(buf, ' ', 1);
- // if (mode == "L"){
- // int R = getSubstring(buf, ' ', 2).toInt();
- // int G = getSubstring(buf, ' ', 3).toInt();
- // int B = getSubstring(buf, ' ', 4).toInt();
- // for (int i ; i<NUM_LEDS_LUSTRE ; i++) {
- // lustreLeds[i].setRGB(R, G, B) ;
- // }
- // }
- // if (mode == "T"){
- // int R = getSubstring(buf, ' ', 2).toInt();
- // int G = getSubstring(buf, ' ', 3).toInt();
- // int B = getSubstring(buf, ' ', 4).toInt();
- // for (int i ; i<NUM_LEDS_TABLE ; i++) {
- // tableLeds[i].setRGB(R, G, B) ;
- // }
- // }
- // Serial.println("Led mode " + getSubstring(buf, ' ', 1));
- }
-
- else if (selector == "dimmer") {
- Serial.println("Dimmer fade à " + getSubstring(buf, ' ', 1) + " en " + getSubstring(buf, ' ', 2) + "ms");
- int dimmer_value = getSubstring(buf, ' ', 1).toInt();
- int dimmer_fade = getSubstring(buf, ' ', 2).toInt();
- dimmer.setTime(dimmer_fade);
- dimmer.set(dimmer_value);
- // Serial.println(dimmer_delta);
-
- }
-
- else if (selector == "delay") {
- String wait = getSubstring(buf, ' ', 1);
- Serial.println("delai " + wait + " ms");
- inibSDreading = true ;
- delay_start = millis();
- delay_length = wait.toInt() ;
- // delay_flag = 0 ;
- mgr.addListener(new EvtTimeListener(50 , true, (EvtAction)checkDelay));
-
- //delay(wait.toInt());
- }
-
- else if (selector == ""){}
-
- else {
- Serial.print(selector);
- Serial.println(": pas compris");
- }
-
-
- }
-
- else {
- Serial.println("EOF");
- btnFile.close();
- inibSDreading = true;
- EvtResetButtonContext();
- }
- }
- // else{Serial.println("not reading");}
- return false ;
-
- }
|