- slightly decrease msFadeDecel by 100ms - different approach in button.cpp for case last button press was long e.g. reworked commands: - 1x long press = restart - 1x short press = center stick, freeze - 1x short 1x long = run new auto commands - 2x short = toggle idle - change default minOnMs / minOffMs for evaulated switch class -> fix button presses sometimes not recognized
		
			
				
	
	
		
			60 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
#pragma once
 | 
						|
 | 
						|
#include <stdio.h>
 | 
						|
 | 
						|
extern "C"
 | 
						|
{
 | 
						|
#include "freertos/FreeRTOS.h"
 | 
						|
#include "freertos/task.h"
 | 
						|
#include "driver/gpio.h"
 | 
						|
#include "esp_log.h"
 | 
						|
}
 | 
						|
 | 
						|
//constructor examples:
 | 
						|
//switch to gnd and us internal pullup:
 | 
						|
//gpio_evaluatedSwitch s3(GPIO_NUM_14);
 | 
						|
//switch to gnd dont use internal pullup:
 | 
						|
//gpio_evaluatedSwitch s3(GPIO_NUM_14 false);
 | 
						|
//switch to VCC (inverted) and dont use internal pullup:
 | 
						|
//gpio_evaluatedSwitch s3(GPIO_NUM_14 false, true);
 | 
						|
 | 
						|
 | 
						|
class gpio_evaluatedSwitch {
 | 
						|
    public:
 | 
						|
        //--- input ---
 | 
						|
        uint32_t minOnMs = 30;
 | 
						|
        uint32_t minOffMs = 30;
 | 
						|
        gpio_evaluatedSwitch( //constructor minimal (default parameters pullup=true, inverted=false)
 | 
						|
                gpio_num_t gpio_num_declare
 | 
						|
                );
 | 
						|
        gpio_evaluatedSwitch( //constructor with optional parameters
 | 
						|
                gpio_num_t gpio_num_declare,
 | 
						|
                bool pullup_declare,
 | 
						|
                bool inverted_declare=false
 | 
						|
                );
 | 
						|
 | 
						|
        //--- output ---         TODO make readonly? (e.g. public section: const int& x = m_x;)
 | 
						|
        bool state = false;
 | 
						|
        bool risingEdge = false;
 | 
						|
        bool fallingEdge = false;
 | 
						|
        uint32_t msPressed = 0;
 | 
						|
        uint32_t msReleased = 0;
 | 
						|
 | 
						|
        //--- functions ---
 | 
						|
        void handle();  //Statemachine for debouncing and edge detection
 | 
						|
 | 
						|
    private:
 | 
						|
        gpio_num_t gpio_num;
 | 
						|
        bool pullup;
 | 
						|
        bool inverted;
 | 
						|
 | 
						|
        enum class switchState {TRUE, FALSE, LOW, HIGH};
 | 
						|
        switchState p_state = switchState::FALSE;
 | 
						|
        uint32_t timestampLow = 0;
 | 
						|
        uint32_t timestampHigh = 0;
 | 
						|
        void init();
 | 
						|
 | 
						|
};
 | 
						|
 | 
						|
 |