Files
espurna/code/espurna/button.h
Maxim Prokhorov bd3a588977 hardware: lightfox fixes & buttonAdd
Should be buildable once again

Restore the behaviour from #1468, where button clicks were triggered
Inject relay provider using the relayAdd, add buttonAdd to provide input handling

Remove extra button handling code from the WebUI

Still assuming that DUAL code really needs a syncronized way to handle
input & output with relays, so we can't treat it as a real button.
Without the device it is only guessing, and various issues / comments
are not really clear on that part :/
2021-06-09 11:20:07 +03:00

109 lines
2.1 KiB
C++

/*
BUTTON MODULE
Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
*/
#pragma once
#include "espurna.h"
#include "libs/BasePin.h"
#include "libs/DebounceEvent.h"
#include <memory>
constexpr size_t ButtonsActionMax { 255ul };
constexpr size_t ButtonsPresetMax { 8ul };
constexpr size_t ButtonsMax { 32ul };
enum class ButtonProvider : int {
None,
Gpio,
Analog
};
enum class ButtonEvent {
None,
Pressed,
Released,
Click,
DoubleClick,
LongClick,
LongLongClick,
TripleClick
};
// button actions, limited to 8-bit number (0b11111111 / 0xff / 255)
enum class ButtonAction : uint8_t {
None,
Toggle,
On,
Off,
AccessPoint,
Reset,
Pulse,
FactoryReset,
Wps,
SmartConfig,
BrightnessIncrease,
BrightnessDecrease,
DisplayOn,
Custom,
FanLow,
FanMedium,
FanHigh
};
struct ButtonActions {
ButtonAction pressed;
ButtonAction released;
ButtonAction click;
ButtonAction dblclick;
ButtonAction lngclick;
ButtonAction lnglngclick;
ButtonAction trplclick;
};
struct ButtonEventDelays {
ButtonEventDelays();
ButtonEventDelays(unsigned long debounce, unsigned long repeat, unsigned long lngclick, unsigned long lnglngclick);
unsigned long debounce;
unsigned long repeat;
unsigned long lngclick;
unsigned long lnglngclick;
};
using ButtonEventEmitterPtr = std::unique_ptr<debounce_event::EventEmitter>;
struct button_t {
button_t(ButtonActions&& actions, ButtonEventDelays&& delays);
button_t(BasePinPtr&& pin, const debounce_event::types::Config& config,
ButtonActions&& actions, ButtonEventDelays&& delays);
bool state();
ButtonEvent loop();
ButtonEventEmitterPtr event_emitter;
ButtonActions actions;
ButtonEventDelays event_delays;
};
using ButtonEventHandler = void(*)(size_t id, ButtonEvent event);
void buttonSetCustomAction(ButtonEventHandler);
void buttonSetNotifyAction(ButtonEventHandler);
ButtonAction buttonAction(size_t id, const ButtonEvent event);
void buttonEvent(size_t id, ButtonEvent event);
bool buttonAdd();
size_t buttonCount();
void buttonSetup();