93 lines
1.9 KiB
C++
93 lines
1.9 KiB
C++
#include "my_buttons.h"
|
|
#include "my_board.h"
|
|
#include "global.h"
|
|
#include "led_strip.h"
|
|
#include "my_buzzer.h"
|
|
|
|
static const char* tag = "button";
|
|
|
|
OneButton *btn[3];
|
|
|
|
void Init_ButtonEvents(void)
|
|
{
|
|
btn[0] = new OneButton(btn1Pin, true, true);
|
|
btn[1] = new OneButton(btn2Pin, true, true);
|
|
btn[2] = new OneButton(btn3Pin, true, true);
|
|
|
|
if(btn[0] != NULL){
|
|
btn[0]->setDebounceTicks(DEBOUCE_TIME); // just below the update period to guarantee 1 sample delay
|
|
btn[0]->attachClick(btn1_click);
|
|
btn[0]->attachDoubleClick(btn1_doubleClick);
|
|
}
|
|
else {
|
|
ESP_LOGW(tag, "Button1 Not Initialized");
|
|
}
|
|
|
|
if(btn[1] != NULL){
|
|
btn[1]->setDebounceTicks(DEBOUCE_TIME);
|
|
btn[1]->attachClick(btn2_click);
|
|
btn[1]->attachDoubleClick(btn2_doubleClick);
|
|
btn[1]->attachLongPressStart(btn2_LongPressStart);
|
|
}
|
|
else {
|
|
ESP_LOGW(tag, "Button2 Not Initialized");
|
|
}
|
|
|
|
if(btn[2] != NULL){
|
|
btn[2]->setDebounceTicks(DEBOUCE_TIME);
|
|
btn[2]->attachClick(btn3_click);
|
|
btn[2]->attachDoubleClick(btn3_doubleClick);
|
|
btn[2]->attachLongPressStart(btn3_LongPressStart);
|
|
btn[2]->attachLongPressStop(btn3_LongPressStop);
|
|
}
|
|
else {
|
|
ESP_LOGW(tag, "Button3 Not Initialized");
|
|
}
|
|
|
|
ESP_LOGV(tag, "Initialized Buttons Events...\n");
|
|
}
|
|
|
|
void btn1_click() {
|
|
IncrementEventIndex();
|
|
Pulse_LED_Status(150);
|
|
ESP_LOGD(tag, "btn1 1x");
|
|
}
|
|
|
|
void btn1_doubleClick() {
|
|
ESP_LOGD(tag, "btn1 2x");
|
|
}
|
|
|
|
void btn2_click() {
|
|
Pulse_LED_Status(150);
|
|
Buzzer_Beep(150);
|
|
// send packet
|
|
ESP_LOGD(tag, "btn2 1x");
|
|
}
|
|
|
|
void btn2_doubleClick() {
|
|
ESP_LOGD(tag, "btn2 2x");
|
|
}
|
|
|
|
void btn2_LongPressStart(){
|
|
// scan for devices
|
|
}
|
|
|
|
void btn3_click() {
|
|
Pulse_LED_Status(150);
|
|
ESP_LOGD(tag, "btn3 1x");
|
|
}
|
|
|
|
void btn3_doubleClick() {
|
|
ESP_LOGD(tag, "btn3 2x");
|
|
}
|
|
|
|
//bool IncFwd = true;
|
|
void btn3_LongPressStart(){
|
|
ESP_LOGD(tag, "btn3 long press");
|
|
}
|
|
|
|
void btn3_LongPressStop(){
|
|
//IncFwd = !IncFwd; // switch increment direction
|
|
}
|
|
|