set gpio output depending on lock state
This commit is contained in:
28
Gpio.h
28
Gpio.h
@@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "NukiWrapper.h"
|
||||
#include <functional>
|
||||
#include <Preferences.h>
|
||||
#include <vector>
|
||||
|
||||
enum class PinRole
|
||||
{
|
||||
@@ -13,6 +14,13 @@ enum class PinRole
|
||||
OutputHighUnlocked,
|
||||
};
|
||||
|
||||
enum class GpioAction
|
||||
{
|
||||
Lock,
|
||||
Unlock,
|
||||
Unlatch
|
||||
};
|
||||
|
||||
struct PinEntry
|
||||
{
|
||||
uint8_t pin = 0;
|
||||
@@ -22,8 +30,10 @@ struct PinEntry
|
||||
class Gpio
|
||||
{
|
||||
public:
|
||||
Gpio(Preferences* preferences, NukiWrapper* nuki);
|
||||
static void init(NukiWrapper* nuki);
|
||||
Gpio(Preferences* preferences);
|
||||
static void init();
|
||||
|
||||
void addCallback(std::function<void(const GpioAction&)> callback);
|
||||
|
||||
void loadPinConfiguration();
|
||||
void savePinConfiguration(const std::vector<PinEntry>& pinConfiguration);
|
||||
@@ -31,12 +41,17 @@ public:
|
||||
const std::vector<uint8_t>& availablePins() const;
|
||||
const std::vector<PinEntry>& pinConfiguration() const;
|
||||
|
||||
PinRole getPinRole(uint8_t pin);
|
||||
String getRoleDescription(PinRole role) const;
|
||||
void getConfigurationText(String& text, const std::vector<PinEntry>& pinConfiguration) const;
|
||||
|
||||
const std::vector<PinRole>& getAllRoles() const;
|
||||
|
||||
void setPinOutput(const uint8_t& pin, const uint8_t& state);
|
||||
|
||||
private:
|
||||
void notify(const GpioAction& action);
|
||||
|
||||
const std::vector<uint8_t> _availablePins = { 2, 4, 5, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 32, 33 };
|
||||
const std::vector<PinRole> _allRoles =
|
||||
{
|
||||
@@ -55,9 +70,10 @@ private:
|
||||
static void IRAM_ATTR isrUnlock();
|
||||
static void IRAM_ATTR isrUnlatch();
|
||||
|
||||
std::vector<std::function<void(const GpioAction&)>> _callbacks;
|
||||
|
||||
static Gpio* _inst;
|
||||
static NukiWrapper* _nuki;
|
||||
static unsigned long _lockedTs;
|
||||
static unsigned long _debounceTs;
|
||||
|
||||
Preferences* _preferences = nullptr;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user