add EEPROM stuff, save last relay state in EEPROM
This commit is contained in:
22
hardware.cpp
22
hardware.cpp
@ -8,26 +8,41 @@
|
||||
#include <Arduino.h>
|
||||
#include "hardware.h"
|
||||
#include <Streaming.h>
|
||||
#include "config.h"
|
||||
|
||||
|
||||
|
||||
Switch::Switch() : m_state(false), m_feedbackState(false), m_stateConflict(false),
|
||||
m_lastButtonState(false), m_buttonEngineState(0), m_buttonTimestamp(0),
|
||||
m_ledEngineState(0), m_ledState(false), m_ledTimestamp(0)
|
||||
m_ledEngineState(0), m_ledState(false), m_ledTimestamp(0),
|
||||
m_index(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Switch::begin(const uint8_t feedbackPin, const uint8_t buttonPin, const uint8_t relayPin, const uint8_t ledPin) {
|
||||
void Switch::begin(const uint8_t feedbackPin, const uint8_t buttonPin, const uint8_t relayPin, const uint8_t ledPin,
|
||||
uint8_t index) {
|
||||
m_feedbackPin = feedbackPin;
|
||||
m_buttonPin = buttonPin;
|
||||
m_relayPin = relayPin;
|
||||
m_ledPin = ledPin;
|
||||
m_index = index;
|
||||
|
||||
if (! configIsValid()) {
|
||||
Serial << "Initializing config" << endl;
|
||||
bool initValue = false;
|
||||
configWrite(CONFIG_STATES_BEGIN + m_index, 1, (char*)&initValue);
|
||||
}
|
||||
|
||||
pinMode(m_feedbackPin, INPUT_PULLUP);
|
||||
pinMode(m_buttonPin, INPUT_PULLUP);
|
||||
pinMode(m_relayPin, OUTPUT);
|
||||
digitalWrite(m_relayPin, true);
|
||||
pinMode(m_ledPin, OUTPUT);
|
||||
|
||||
configRead(CONFIG_STATES_BEGIN + m_index, 1, (char*)&m_state);
|
||||
action();
|
||||
}
|
||||
|
||||
void Switch::toggle() {
|
||||
@ -46,7 +61,8 @@ void Switch::off() {
|
||||
}
|
||||
|
||||
void Switch::action() {
|
||||
digitalWrite(m_relayPin, m_state);
|
||||
configWrite(CONFIG_STATES_BEGIN + m_index, 1, (char*)&m_state);
|
||||
digitalWrite(m_relayPin, ! m_state);
|
||||
}
|
||||
|
||||
void Switch::exec() {
|
||||
|
Reference in New Issue
Block a user