cable-length-cutter/components/gpio/gpio_evaluateSwitch.hpp
jonny_ji7 a3f3cb340c Add config, buzzer, evalSwitch, switch to c++
Add config.cpp/hpp
    - macros for all input and output pins
    - gloabl evaluated switch objects
    - buzzer object
    - display config
    - encoder config

Move main.c to main.cpp and adjust code to be c++ compatible

add custom library evaluated switch (copied from armchair project)
add buzzer object (copied from armchair project)

add control.cpp/hpp with control task (no function yet)
2022-08-17 10:29:11 +02:00

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();
};