123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- // 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);
- }
- // 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 onButtonHeld(Button& btn, uint16_t duration, uint16_t repeatCount) {
- if (buttonPlus.isPressed()) {
- plusButtonAction();
- }
- if (buttonMinus.isPressed()) {
- minusButtonAction();
- }
- }
- 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)) {
- plusButtonAction();
- }
- else if (btn.is(buttonMinus)) {
- minusButtonAction();
- }
- else if (btn.is(buttonMode)) {
- modeButtonAction();
- }
- else if (btn.is(pirSensor)) {
- pirSensorOffAction();
- }
- }
- void plusButtonAction() {
- Serial.println("Btn +");
- if (!displayActive) {
- enableDisplay();
- }
- else {
- setTempStepUp();
- extendDisplayTimeout();
- }
- }
- void minusButtonAction() {
- Serial.println("Btn -");
- if (!displayActive) {
- enableDisplay();
- }
- else {
- setTempStepDown();
- extendDisplayTimeout();
- }
- }
- void modeButtonAction() {
- Serial.println("Btn mode");
- if (!displayActive) {
- enableDisplay();
- }
- else {
- toggleHeatingMode();
- extendDisplayTimeout();
- }
- }
- void modeButtonHoldAction() {
- Serial.println("Btn mode held - toggle on/off");
- extendDisplayTimeout();
- toggleThermostatOnOff();
- }
- void pirSensorOnAction() {
- PIRSensorOn = true;
- Serial.println("PIR sensor ON");
- publishCurrentPIRValue();
- sendToDomoticz_PIR();
- if(PIR_enablesDisplay) enableDisplay();
- }
- void pirSensorOffAction() {
- PIRSensorOn = false;
- Serial.println("PIR sensor OFF");
- publishCurrentPIRValue();
- sendToDomoticz_PIR();
- }
|