From 3d82e2a200a113598387777974528c28a38b7e3d Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Wed, 16 Nov 2016 00:00:47 +0100 Subject: [PATCH] Use Reprog button as setup button on long press --- WifiControlSensor/WifiControlSensor.ino | 15 +++++++++++++++ WifiControlSensor/config_device.h | 3 +++ 2 files changed, 18 insertions(+) diff --git a/WifiControlSensor/WifiControlSensor.ino b/WifiControlSensor/WifiControlSensor.ino index df6f395..bef0d9c 100644 --- a/WifiControlSensor/WifiControlSensor.ino +++ b/WifiControlSensor/WifiControlSensor.ino @@ -36,6 +36,7 @@ #include #include #include +#include #include "config.h" #include "utils.h" @@ -79,6 +80,17 @@ void WebHandleNotFound(); void WebSetupServer(int bootmode); +#ifdef CONFIG_SETUP_BUTTON +void onLongButtonPressed(uint8_t pin){ + if(pin == CONFIG_SETUP_BUTTON && mode == BOOTMODE_NORMAL){ + SKETCH_DEBUG_PRINTLN("Putting device in setup mode"); + mode = BOOTMODE_SETUP; + WiFi.disconnect(); + WiFi.softAP(ssid); + } +} +#endif + void WifiSetup(int bootmode, char *confSsid, char *confPassword, char *confHost, int ip_config, uint32_t ip, uint32_t gw, uint32_t mask, uint32_t dns, uint32_t dns2) { IPAddress myIP; if (bootmode == BOOTMODE_SETUP) { @@ -246,6 +258,9 @@ void setup() { #ifdef CONFIG_ENABLE_POWER_SAVE wifi_set_sleep_type(LIGHT_SLEEP_T); #endif +#ifdef CONFIG_SETUP_BUTTON + new HIB(CONFIG_SETUP_BUTTON, HIGH, NULL, NULL, onLongButtonPressed); +#endif } uint nbCycle = CONFIG_SAMPLING_PERIODE_MS / CONFIG_WEB_DELAY_MS; diff --git a/WifiControlSensor/config_device.h b/WifiControlSensor/config_device.h index 491635b..71e44aa 100644 --- a/WifiControlSensor/config_device.h +++ b/WifiControlSensor/config_device.h @@ -37,6 +37,9 @@ // GPIO used in PWM #define CONFIG_CONTROLLED_PWM {} +// Long press on this button will put device in setup mode at runtime +#define CONFIG_SETUP_BUTTON 0 + /* DEFAULT VALUE ALSO DEFINED IN CONFIG.H */ //If this GPIO is LOW at boot, device will enter setup mode