Skip to content

Commit

Permalink
add timeout settings for button
Browse files Browse the repository at this point in the history
Long press time and Multi Click time could be adjusted
  • Loading branch information
vortigont committed Jan 23, 2024
1 parent f8bc517 commit bbb7f07
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 14 deletions.
Binary file modified data/js/ui_lamp.json.gz
Binary file not shown.
32 changes: 28 additions & 4 deletions resources/html/js/ui_lamp.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type":"interface",
"version":4,
"version":5,
"descr":"FireLamp UI objects",
"settings":{
"hub75":{
Expand Down Expand Up @@ -627,7 +627,7 @@
"section": "set_button_gpio",
"block": [
{
"section": "enagpio",
"section": "btngpio",
"line": true,
"block": [
{
Expand All @@ -638,7 +638,7 @@
},
{
"id": "gpio",
"html": "input",
"html":"input",
"value": -1,
"type": "number",
"label": "GPIO pin",
Expand All @@ -648,7 +648,7 @@
]
},
{
"section": "enagpio",
"section": "btndebnc",
"line": true,
"block": [
{
Expand All @@ -665,6 +665,30 @@
}
]
},
{
"section": "btntimes",
"line": true,
"block": [
{
"id":"lpresst",
"html":"input",
"value": 750,
"type": "number",
"label": "Long press time, ms",
"min": 250,
"step": 50
},
{
"id":"mclickt",
"html":"input",
"value": 350,
"type": "number",
"label": "Multi Click time, ms",
"min": 100,
"step": 50
}
]
},
{
"id": "set_button_gpio",
"html": "button",
Expand Down
5 changes: 0 additions & 5 deletions src/bencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ void ButtonEventHandler::load(JsonVariantConst cfg){

}

void ButtonEventHandler::save(){

}





1 change: 0 additions & 1 deletion src/bencoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class ButtonEventHandler {

void load(JsonVariantConst cfg);

void save();
};


2 changes: 2 additions & 0 deletions src/char_const.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ static constexpr const char* T_btn_events = "btn_events";
static constexpr const char* T_debounce = "debounce";
static constexpr const char* T_lamp_event = "lamp_event";
static constexpr const char* T_lamppwr = "lamppwr";
static constexpr const char* T_lpresst = "lpresst";
static constexpr const char* T_mclickt = "mclickt";

// Other
static constexpr const char* T_Active = "Active";
Expand Down
8 changes: 6 additions & 2 deletions src/devices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,16 @@ void button_configure_gpio(JsonVariantConst btn_cfg){
button = new GPIOButton<ESPEventPolicy> (static_cast<gpio_num_t>(gpio), btn_cfg[T_logicL]);
if (!button) return;
button->setDebounce(debn);
button->timeouts.setLongPress(btn_cfg[T_lpresst]);
button->timeouts.setMultiClick(btn_cfg[T_mclickt]);
} else {
if ( gpio != button->getGPIO() ){
button->setGPIO(static_cast<gpio_num_t>(gpio), btn_cfg[T_logicL]);
button->setDebounce(debn);
}
button->setDebounce(debn);
button->timeouts.setLongPress(btn_cfg[T_lpresst]);
button->timeouts.setMultiClick(btn_cfg[T_mclickt]);

// button obj already exist, so no need to configure it further
return;
}
Expand All @@ -149,7 +154,6 @@ void button_configure_gpio(JsonVariantConst btn_cfg){
ESPButton::set_event_loop_hndlr(evt::get_hndlr());

button->enable();
Serial.print("Button enabled\n");
}

void button_configure_events(JsonVariantConst btn_cfg){
Expand Down
2 changes: 1 addition & 1 deletion src/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ JeeUI2 lib used under MIT License Copyright (c) 2019 Marsel Akhkamov
#include "evtloop.h"

// версия ресурсов в стороннем джейсон файле
#define UIDATA_VERSION 4
#define UIDATA_VERSION 5

// placeholder for effect list rebuilder task
Task *delayedOptionTask = nullptr;
Expand Down
7 changes: 6 additions & 1 deletion src/lamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ void Lamp::power(bool flag) // флаг включения/выключения
/*
temporary disable
void Lamp::playEffect(bool isPlayName, EFFSWITCH action){
if(mp3!=nullptr && mp3->isOn() && effwrkr.getCurrent()>0 && (flags.playEffect || ((isLampOn() || millis()>5000) && flags.playMP3 && action!=EFFSWITCH::SW_NEXT_DEMO && action!=EFFSWITCH::SW_RND))){
if( mp3!=nullptr && mp3->isOn() &&
effwrkr.getCurrent()>0 &&
(flags.playEffect ||
((isLampOn() || millis()>5000) && flags.playMP3 && action!=EFFSWITCH::SW_NEXT_DEMO && action!=EFFSWITCH::SW_RND)
)
){
LOG(printf_P, PSTR("playEffect soundfile:%s, effect:%d, delayed:%d\n"), effwrkr.getSoundfile().c_str(), effwrkr.getCurrent(), (flags.playName && !flags.playMP3));
if(!flags.playMP3 || (flags.playEffect && action!=EFFSWITCH::SW_NEXT_DEMO && action!=EFFSWITCH::SW_RND)) // для mp3-плеера есть отдельное управление
mp3->playEffect(effwrkr.getCurrent(), effwrkr.getSoundfile(), (isPlayName && mp3!=nullptr && mp3->isOn() && !flags.playMP3)); // влияние на отложенное воспроизведение, но не для MP3-плеера
Expand Down

0 comments on commit bbb7f07

Please sign in to comment.