123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- // Use this function to configure the internal Bounce object to suit you. See the documentation at: https://github.com/thomasfredericks/Bounce2/wiki
- // This function can be left out if the defaults are acceptable - just don't call configureButton
- void configurePushButton(Bounce &bouncedButton)
- {
- // Set the debounce interval to 15ms - default is 10ms
- bouncedButton.interval(15);
- }
- void setupInputsButtons()
- {
- //pinMode(PIN_PIRSENSOR, INPUT);
- buttonPlus.configureButton(configurePushButton);
- //buttonPlus.onPress(onButtonPressed); // When the button is first pressed, call the function onButtonPressed (further down the page)
- buttonPlus.onHoldRepeat(1000, 350, onButtonHeld); // Once the button has been held for 1 second (1000ms) call onButtonHeld. Call it again every 350ms until it is let go
- buttonPlus.onRelease(50, 500, onButtonReleased); // When the button is held >50ms and released after <500ms, call onButtonReleased
- buttonMinus.configureButton(configurePushButton);
- //buttonMinus.onPress(onButtonPressed); // When the button is first pressed, call the function onButtonPressed (further down the page)
- buttonMinus.onHoldRepeat(1000, 350, onButtonHeld); // Once the button has been held for 1 second (1000ms) call onButtonHeld. Call it again every 350ms until it is let go
- buttonMinus.onRelease(50, 500, onButtonReleased); // When the button is held >50ms and released after <500ms, call onButtonReleased
- buttonMode.configureButton(configurePushButton);
- //buttonMode.onPress(onButtonPressed); // When the button is first pressed, call the function onButtonPressed (further down the page)
- //buttonMode.onHold(1000, onButtonHeldNoRepeat); // Once the button has been held for 1 second (1000ms) call onButtonHeld
- buttonMode.onHoldRepeat(1000, 1000, onButtonHeld); // Once the button has been held for 1 second (1000ms) call onButtonHeld
- buttonMode.onRelease(50, 500, onButtonReleased); // When the button is held >50ms and released after <500ms, call onButtonReleased
- pirSensor.configureButton(configurePushButton);
- //pirSensor.onPress(onButtonPressed); // When the button is first pressed, call the function onButtonPressed (further down the page)
- pirSensor.onHold(150, onButtonHeldNoRepeat); // Once the button has been held for 1 second (1000ms) call onButtonHeld
- pirSensor.onRelease(150, onButtonReleased); // When the button is held >50ms and released after <500ms, call onButtonReleased
- }
- // btn is a reference to the button that fired the event. That means you can use the same event handler for many buttons
- //void onButtonPressed(Button& btn) {
- //
- //}
- // duration reports back how long it has been since the button was originally pressed.
- // repeatCount tells us how many times this function has been called by this button.
- //void onButtonPressed(Button& btn) {
- // if (buttonMode.isPressed()) {
- //
- // }
- //}
- void onButtonHeld(Button &btn, uint16_t duration, uint16_t repeatCount)
- {
- if (buttonPlus.isPressed())
- {
- plusButtonAction();
- }
- if (buttonMinus.isPressed())
- {
- minusButtonAction();
- }
- if (buttonMode.isPressed())
- {
- if (repeatCount <= 2)
- modeButtonHoldAction();
- else if (repeatCount == 4)
- modeButtonRebootPendingAction();
- else if (repeatCount > 4)
- modeButtonRebootAction();
- }
- }
- void onButtonHeldNoRepeat(Button &btn, uint16_t duration)
- {
- //if (buttonMode.isPressed()) {
- // modeButtonHoldAction();
- //}
- if (pirSensor.isPressed())
- {
- pirSensorOnAction();
- }
- }
- // duration reports back the total time that the button was held down
- void onButtonReleased(Button &btn, uint16_t duration)
- {
- if (btn.is(buttonPlus) && duration < 200)
- {
- plusButtonAction();
- }
- else if (btn.is(buttonMinus) && duration < 200)
- {
- minusButtonAction();
- }
- else if (btn.is(buttonMode) && duration < 200)
- {
- modeButtonAction();
- }
- else if (btn.is(pirSensor))
- {
- pirSensorOffAction();
- }
- }
- void plusButtonAction()
- {
- //Serial.println("Btn +");
- sendLog("DEV: Btn +", LOGLEVEL_INFO);
- if (!displayActive)
- {
- enableDisplay();
- }
- else
- {
- extendDisplayTimeout();
- if (heatingMode == 1 && preset != 0)
- setPresetTo(0);
- else
- setTempStepUp();
- }
- }
- void minusButtonAction()
- {
- //Serial.println("Btn -");
- sendLog("DEV: Btn -", LOGLEVEL_INFO);
- if (heatingMode == 1 && preset != 0)
- setPresetTo(0);
- if (!displayActive)
- {
- enableDisplay();
- }
- else
- {
- extendDisplayTimeout();
- if (heatingMode == 1 && preset != 0)
- setPresetTo(0);
- else
- setTempStepDown();
- }
- }
- void modeButtonAction()
- {
- //Serial.println("Btn mode");
- sendLog("DEV: Btn MODE", LOGLEVEL_INFO);
- if (!displayActive)
- {
- enableDisplay();
- //displayShowLine2OverlayMessage(currentPresetName);
- }
- else
- {
- extendDisplayTimeout();
- if (pendingRestart)
- {
- doRestart = true;
- updateDisplay();
- }
- else
- {
- if (heatingMode > 0)
- {
- if (pendingPresetToggle)
- {
- togglePreset();
- }
- else
- {
- pendingPresetToggle = true;
- displayShowLine2OverlayMessage(currentPresetName);
- }
- }
- }
- }
- }
- void modeButtonHoldAction()
- {
- //Serial.println("Btn mode held - toggle on/off");
- sendLog("DEV: Btn MODE HOLD", LOGLEVEL_INFO);
- extendDisplayTimeout();
- if (pendingRestart)
- {
- doRestart = true;
- updateDisplay();
- }
- else
- {
- toggleOnOff();
- }
- }
- void modeButtonRebootPendingAction()
- {
- extendDisplayTimeout();
- pendingRestart = true;
- pendingRestart_lastMillis = millis();
- updateDisplay();
- }
- void modeButtonRebootAction()
- {
- extendDisplayTimeout();
- doRestart = true;
- updateDisplay();
- }
- void pirSensorOnAction()
- {
- PIRSensorOn = true;
- //Serial.println("PIR sensor ON");
- //sendLog("SENS: PIR=ON", LOGLEVEL_INFO);
- publishCurrentPIRValue();
- if (confBas.PIR_enablesDisplay)
- {
- if (confBas.PIR_enablesDisplay_preset0only && preset == 0)
- enableDisplay();
- else if (!confBas.PIR_enablesDisplay_preset0only)
- enableDisplay();
- }
- }
- void pirSensorOffAction()
- {
- PIRSensorOn = false;
- //Serial.println("PIR sensor OFF");
- //sendLog("SENS: PIR=OFF", LOGLEVEL_INFO);
- publishCurrentPIRValue();
- }
|