123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- /////////////////////////////Events/////////////////////////////////
- ///*resetButtonContext create a listener for each button
- // * when triggered, thoses listener execute the same functions with the index of the pressed button :
- // * resetButtonContext and kill any running sequence
- // * buttonFocus -> lights the current button and shuts the others
- // * readSequence -> reads a text file on the SD card with the sequence of actions to execute
- // */
- bool checkDelay() {
- //Serial.println("checkDelay");
- //if (delay_flag == 0 ) { delay_flag = 1 ;}
- if (millis() - delay_start > delay_length ) {
- inibSDreading = false ;
- }
- //else {inibSDreading = false ;}
- return false ;
- }
- bool updateAll() {
- FadeLed::update();
- //tsunami.update();
- updateLeds() ;
- // FastLED.show();
- return false;
-
- }
- void tlcWrite(){
- for (int ledIndex ; ledIndex < 12 ; ledIndex++) { //sizeof(ledState)/sizeof(uint32_t)
-
- int indexDiv = ledIndex / 3 ;
-
- tlc.setLED(indexDiv, ledState[indexDiv*3], ledState[indexDiv*3+1], ledState[indexDiv*3+2]);
- // Serial.print(ledState[ledIndex]);
- // Serial.print(" ");
- }
- // Serial.println();
- tlc.write();
- }
- void buttonFocus(int index) {
- currentButton = index ;
- //Serial.println(currentButton);
- //turn off all leds but currentButton one
- for (int i ; i < sizeof(ledState)/sizeof(uint32_t) ; i++) {
- if (i == currentButton ) {
- ledState[11-i] = 65535 ;
- }
- else { ledState[11-i] = 50 ; }
- tlcWrite();
- }
-
- EvtResetButtonContext() ; //clean context before starting reading the file
-
- //et après ya plein de trucs à faire
- String file = "button";
- file+=index ;
- file+=".txt";
- btnFile = SD.open(file.c_str()) ;
- // btnFile = SD.open("button0.txt");
- Serial.println("opening " + file);
- if (!btnFile) {
- Serial.println("The text file cannot be opened");
- // return false;
- }
- // while(
- inibSDreading = false ;
- //mgr.addListener(new EvtTimeListener(10, true, (EvtAction)readSDFile));
- //mgr.addListener(new EvtTimeListener(50, true, (EvtAction)fadeDimmer));
- //readSDFile();
- }
- void stopAll() {
- tsunami.stopAllTracks();
- dimmer.setTime(1);
- dimmer.off();
- for (int i ; i<NUM_LEDS_LUSTRE ; i++) {
- lustreLeds[i] = CRGB::Black ;
- tableLeds[i] = CRGB::Black ;
- }
- FastLED.show();
- for (int i ; i < sizeof(ledState)/sizeof(uint32_t) ; i++) {
- if (i == 4 ) {
- ledState[11-i] = 65535 ;
- }
- else { ledState[11-i] = 50 ; }
- tlcWrite();
- }
-
-
- EvtResetButtonContext();
- }
- ///////////////////// CONTEXT ///////////////////////////////
- bool button0(){
- buttonFocus(0) ;
- lustre_targetPalette = FLAMINGO ;
- //lustre_currentBrightness = 0;
- return false;
- }
- bool button1(){
- buttonFocus(1) ;
- lustre_targetPalette = SOLEIL;
- //lustre_currentBrightness = 0;
- // testAll();
- return false;
- }
- bool button2(){
- buttonFocus(2) ;
- lustre_targetPalette = CREPUSCULE ;
- //lustre_currentBrightness = 0;
-
- return false;
- }
- bool button3(){
- buttonFocus(3) ;
- lustre_targetPalette =TIGER_DOWN_MER;
- //lustre_currentBrightness = 0;
- return false;
- }
- bool button4(){
- buttonFocus(4) ;
- lustre_currentBrightness = 0;
- // stopAll();
- return false;
- }
- bool button5(){
- buttonFocus(5) ;
- return false;
- }
- bool button6(){
- buttonFocus(6) ;
- return false;
- }
- bool button7(){
- buttonFocus(7) ;
- return false;
- }
- bool button8(){
- buttonFocus(8) ;
- return false;
- }
- bool button9(){
- buttonFocus(9) ;
- return false;
- }
- void EvtResetButtonContext () {
- Serial.println("Resetting event context");
- mgr.resetContext();
- // button listeners
- mgr.addListener(new EvtPinListener(BUTTON_PIN[0], (EvtAction)button0));
- mgr.addListener(new EvtPinListener(BUTTON_PIN[1], (EvtAction)button1));
- mgr.addListener(new EvtPinListener(BUTTON_PIN[2], (EvtAction)button2));
- mgr.addListener(new EvtPinListener(BUTTON_PIN[3], (EvtAction)button3));
- mgr.addListener(new EvtPinListener(BUTTON_PIN[4], (EvtAction)button4));
- mgr.addListener(new EvtPinListener(BUTTON_PIN[5], (EvtAction)button5));
- mgr.addListener(new EvtPinListener(BUTTON_PIN[6], (EvtAction)button6));
- mgr.addListener(new EvtPinListener(BUTTON_PIN[7], (EvtAction)button7));
- mgr.addListener(new EvtPinListener(BUTTON_PIN[8], (EvtAction)button8));
- mgr.addListener(new EvtPinListener(BUTTON_PIN[9], (EvtAction)button9));
- // controlled time listeners
- // pSD = new EvtTimeListener(5, true, (EvtAction)readSDFile);
- inibSDreading = true ;
- mgr.addListener(new EvtTimeListener(10, true, (EvtAction)readSDFile));
- mgr.addListener(new EvtTimeListener(25, true, (EvtAction)updateAll));
- //mgr.addListener(new EvtTimeListener(40, true, (EvtAction)fastLeds));
-
- }
|