Compare commits

..

3 commits

Author SHA1 Message Date
Patrick Moessler
fee53b3de0 Merge remote-tracking branch 'origin/master' into flurlampe 2019-03-23 22:08:56 +01:00
Patrick Moessler
74805e6a11 Added SimpleInput handler 2019-03-23 21:12:57 +01:00
Patrick Moessler
5b15863ff0 updated flash mode for esp12f 2019-03-23 21:12:35 +01:00
3 changed files with 94 additions and 8 deletions

View file

@ -314,6 +314,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
@ -321,6 +322,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);
@ -634,6 +638,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
@ -1160,6 +1169,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();

View file

@ -1,22 +1,24 @@
//#define USE_WS2812FX_DMA // LED_PIN is ignored & set to RX/GPIO3 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX #define USE_WS2812FX_DMA // LED_PIN is ignored & set to RX/GPIO3 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX
//#define USE_WS2812FX_UART1 // LED_PIN is ignored & set to D4/GPIO2 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX //#define USE_WS2812FX_UART1 // LED_PIN is ignored & set to D4/GPIO2 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX
//#define USE_WS2812FX_UART2 // LED_PIN is ignored & set to TX/GPIO1 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX //#define USE_WS2812FX_UART2 // LED_PIN is ignored & set to TX/GPIO1 Uses WS2812FX, see: https://github.com/kitesurfer1404/WS2812FX
// Neopixel // Neopixel
#define LED_PIN 14 // LED_PIN (14 / D5) where neopixel / WS2811 strip is attached #define LED_PIN 3 // LED_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 LED_TYPE_WS2811 // Uncomment if LED type uses 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) //#define LED_TYPE_WS2811 // Uncomment if LED type uses 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
#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
#define HOSTNAME "McLighting01" // Friedly hostname #define 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
@ -33,8 +35,8 @@
//#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
@ -176,3 +178,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

View file

@ -1290,6 +1290,69 @@ void checkForRequests() {
} }
#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)