Added SimpleInput handler
This commit is contained in:
parent
5b15863ff0
commit
74805e6a11
3 changed files with 94 additions and 8 deletions
|
@ -238,6 +238,7 @@ void setup() {
|
||||||
// system_update_cpu_freq(160);
|
// system_update_cpu_freq(160);
|
||||||
|
|
||||||
DBG_OUTPUT_PORT.begin(115200);
|
DBG_OUTPUT_PORT.begin(115200);
|
||||||
|
DBG_OUTPUT_PORT.println("Starting LEDs");
|
||||||
EEPROM.begin(512);
|
EEPROM.begin(512);
|
||||||
|
|
||||||
// set builtin led pin as output
|
// set builtin led pin as output
|
||||||
|
@ -245,6 +246,9 @@ void setup() {
|
||||||
// button pin setup
|
// button pin setup
|
||||||
#ifdef ENABLE_BUTTON
|
#ifdef ENABLE_BUTTON
|
||||||
pinMode(BUTTON,INPUT_PULLUP);
|
pinMode(BUTTON,INPUT_PULLUP);
|
||||||
|
#endif
|
||||||
|
#ifdef ENABLE_SIMPLEINPUT
|
||||||
|
pinMode(SIMPLEINPUT,INPUT);
|
||||||
#endif
|
#endif
|
||||||
// start ticker with 0.5 because we start in AP mode and try to connect
|
// start ticker with 0.5 because we start in AP mode and try to connect
|
||||||
ticker.attach(0.5, tick);
|
ticker.attach(0.5, tick);
|
||||||
|
@ -546,6 +550,11 @@ void setup() {
|
||||||
#else
|
#else
|
||||||
json["button_mode"] = "OFF";
|
json["button_mode"] = "OFF";
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ENABLE_SIMPLEINPUT
|
||||||
|
json["simpleinput_mode"] = "ON";
|
||||||
|
#else
|
||||||
|
json["simpleinput_mode"] = "OFF";
|
||||||
|
#endif
|
||||||
#ifdef ENABLE_AMQTT
|
#ifdef ENABLE_AMQTT
|
||||||
json["amqtt"] = "ON";
|
json["amqtt"] = "ON";
|
||||||
#endif
|
#endif
|
||||||
|
@ -954,6 +963,9 @@ void loop() {
|
||||||
#ifdef ENABLE_BUTTON
|
#ifdef ENABLE_BUTTON
|
||||||
button();
|
button();
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ENABLE_SIMPLEINPUT
|
||||||
|
simpleinput();
|
||||||
|
#endif
|
||||||
server.handleClient();
|
server.handleClient();
|
||||||
webSocket.loop();
|
webSocket.loop();
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,23 @@
|
||||||
//#define USE_WS2812FX_DMA // Uses PIN is ignored & set to RX/GPIO3 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX
|
#define USE_WS2812FX_DMA // Uses PIN is ignored & set to RX/GPIO3 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX
|
||||||
//#define USE_WS2812FX_UART1 // Uses PIN is ignored & set to D4/GPIO2 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX
|
//#define USE_WS2812FX_UART1 // Uses PIN is ignored & set to D4/GPIO2 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX
|
||||||
//#define USE_WS2812FX_UART2 // Uses PIN is ignored & set to TX/GPIO1 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX
|
//#define USE_WS2812FX_UART2 // Uses PIN is ignored & set to TX/GPIO1 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX
|
||||||
|
|
||||||
// Neopixel
|
// Neopixel
|
||||||
#define PIN 14 // PIN (14 / D5) where neopixel / WS2811 strip is attached
|
#define PIN 3 // PIN (14 / D5) where neopixel / WS2811 strip is attached
|
||||||
#define NUMLEDS 24 // Number of leds in the strip
|
#define NUMLEDS 30 // Number of leds in the strip
|
||||||
#define BUILTIN_LED 2 // ESP-12F has the built in LED on GPIO2, see https://github.com/esp8266/Arduino/issues/2192
|
#define BUILTIN_LED 2 // ESP-12F has the built in LED on GPIO2, see https://github.com/esp8266/Arduino/issues/2192
|
||||||
#define BUTTON 4 // Input pin (4 / D2) for switching the LED strip on / off, connect this PIN to ground to trigger button.
|
//#define BUTTON 4 // Input pin (4 / D2) for switching the LED strip on / off, connect this PIN to ground to trigger button.
|
||||||
|
#define SIMPLEINPUT 5
|
||||||
|
|
||||||
const char HOSTNAME[] = "McLighting01"; // Friedly hostname
|
const char HOSTNAME[] = "motion1"; // Friedly hostname
|
||||||
|
|
||||||
#define HTTP_OTA // If defined, enable ESP8266HTTPUpdateServer OTA code.
|
#define HTTP_OTA // If defined, enable ESP8266HTTPUpdateServer OTA code.
|
||||||
//#define ENABLE_OTA // If defined, enable Arduino OTA code.
|
//#define ENABLE_OTA // If defined, enable Arduino OTA code.
|
||||||
#define ENABLE_AMQTT // If defined, enable Async MQTT code, see: https://github.com/marvinroger/async-mqtt-client
|
#define ENABLE_AMQTT // If defined, enable Async MQTT code, see: https://github.com/marvinroger/async-mqtt-client
|
||||||
//#define ENABLE_MQTT // If defined, enable MQTT client code, see: https://github.com/toblum/McLighting/wiki/MQTT-API
|
//#define ENABLE_MQTT // If defined, enable MQTT client code, see: https://github.com/toblum/McLighting/wiki/MQTT-API
|
||||||
#define ENABLE_HOMEASSISTANT // If defined, enable Homeassistant integration, ENABLE_MQTT or ENABLE_AMQTT must be active
|
#define ENABLE_HOMEASSISTANT // If defined, enable Homeassistant integration, ENABLE_MQTT or ENABLE_AMQTT must be active
|
||||||
#define ENABLE_BUTTON // If defined, enable button handling code, see: https://github.com/toblum/McLighting/wiki/Button-control
|
//#define ENABLE_BUTTON // If defined, enable button handling code, see: https://github.com/toblum/McLighting/wiki/Button-control
|
||||||
|
#define ENABLE_SIMPLEINPUT // If defined, enable a simple low/high input handler
|
||||||
//#define MQTT_HOME_ASSISTANT_SUPPORT // If defined, use AMQTT and select Tools -> IwIP Variant -> Higher Bandwidth
|
//#define MQTT_HOME_ASSISTANT_SUPPORT // If defined, use AMQTT and select Tools -> IwIP Variant -> Higher Bandwidth
|
||||||
#define ENABLE_LEGACY_ANIMATIONS // Dont disbale this for now
|
#define ENABLE_LEGACY_ANIMATIONS // Dont disbale this for now
|
||||||
#define ENABLE_E131 // E1.31 implementation
|
#define ENABLE_E131 // E1.31 implementation
|
||||||
|
@ -29,8 +31,8 @@ const char HOSTNAME[] = "McLighting01"; // Friedly hostname
|
||||||
//#define WIFIMGR_SET_MANUAL_IP
|
//#define WIFIMGR_SET_MANUAL_IP
|
||||||
|
|
||||||
#ifdef WIFIMGR_SET_MANUAL_IP
|
#ifdef WIFIMGR_SET_MANUAL_IP
|
||||||
uint8_t _ip[4] = {192,168,0,128};
|
uint8_t _ip[4] = {192,168,178,128};
|
||||||
uint8_t _gw[4] = {192,168,0,1};
|
uint8_t _gw[4] = {192,168,178,1};
|
||||||
uint8_t _sn[4] = {255,255,255,0};
|
uint8_t _sn[4] = {255,255,255,0};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -170,3 +172,12 @@ LEDState main_color = { 255, 0, 0 }; // Store the "main color" of the strip use
|
||||||
byte prevKeyState = HIGH; // button is active low
|
byte prevKeyState = HIGH; // button is active low
|
||||||
boolean buttonState = false;
|
boolean buttonState = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef ENABLE_SIMPLEINPUT
|
||||||
|
//#define SIMPLEINPUT_MODE_HIGH "STA| 1| 0|245|196|255|255|255"
|
||||||
|
//#define SIMPLEINPUT_MODE_HIGH "STA| 1| 0|245|196|0|0|0"
|
||||||
|
|
||||||
|
const unsigned long inputSampleIntervalMs = 25;
|
||||||
|
byte prevInputState = LOW;
|
||||||
|
unsigned long inputPrevMillis = 0;
|
||||||
|
#endif
|
||||||
|
|
|
@ -1264,6 +1264,69 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// ***************************************************************************
|
||||||
|
// Simple Input management
|
||||||
|
// ***************************************************************************
|
||||||
|
#ifdef ENABLE_SIMPLEINPUT
|
||||||
|
|
||||||
|
|
||||||
|
// called when button is kept pressed for less than 2 seconds
|
||||||
|
void inputHandleHigh() {
|
||||||
|
DBG_OUTPUT_PORT.printf("Input changed to high\n");
|
||||||
|
#ifdef SIMPLEINPUT_MODE_HIGH
|
||||||
|
setModeByStateString(SIMPLEINPUT_MODE_HIGH);
|
||||||
|
#endif
|
||||||
|
#ifdef ENABLE_MQTT
|
||||||
|
mqtt_client.publish(mqtt_outtopic, String("OK >1").c_str());
|
||||||
|
#endif
|
||||||
|
#ifdef ENABLE_AMQTT
|
||||||
|
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK >1").c_str());
|
||||||
|
#endif
|
||||||
|
// #ifdef ENABLE_HOMEASSISTANT
|
||||||
|
// stateOn = true;
|
||||||
|
// if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
||||||
|
// #endif
|
||||||
|
// #ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||||
|
// if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
void inputHandleLow() {
|
||||||
|
DBG_OUTPUT_PORT.printf("Input changed to low\n");
|
||||||
|
#ifdef SIMPLEINPUT_MODE_HIGH
|
||||||
|
setModeByStateString(SIMPLEINPUT_MODE_LOW);
|
||||||
|
#endif
|
||||||
|
#ifdef ENABLE_MQTT
|
||||||
|
mqtt_client.publish(mqtt_outtopic, String("OK >0").c_str());
|
||||||
|
#endif
|
||||||
|
#ifdef ENABLE_AMQTT
|
||||||
|
amqttClient.publish(mqtt_outtopic.c_str(), qospub, false, String("OK >0").c_str());
|
||||||
|
#endif
|
||||||
|
// #ifdef ENABLE_HOMEASSISTANT
|
||||||
|
// stateOn = false;
|
||||||
|
// if(!ha_send_data.active()) ha_send_data.once(5, tickerSendState);
|
||||||
|
// #endif
|
||||||
|
// #ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||||
|
// if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void simpleinput() {
|
||||||
|
if (millis() - inputPrevMillis >= inputSampleIntervalMs) {
|
||||||
|
inputPrevMillis = millis();
|
||||||
|
|
||||||
|
byte currInputState = digitalRead(SIMPLEINPUT);
|
||||||
|
|
||||||
|
if ((prevInputState == HIGH) && (currInputState == LOW)) {
|
||||||
|
inputHandleLow();
|
||||||
|
}
|
||||||
|
else if ((prevInputState == LOW) && (currInputState == HIGH)) {
|
||||||
|
inputHandleHigh();
|
||||||
|
}
|
||||||
|
prevInputState = currInputState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||||
bool updateFS = false;
|
bool updateFS = false;
|
||||||
#if defined(ENABLE_MQTT) or defined(ENABLE_AMQTT)
|
#if defined(ENABLE_MQTT) or defined(ENABLE_AMQTT)
|
||||||
|
|
Loading…
Reference in a new issue