Use Reprog button as setup button on long press

This commit is contained in:
Mathieu Maret 2016-11-16 00:00:47 +01:00
parent d49e0a5fff
commit 3d82e2a200
2 changed files with 18 additions and 0 deletions

View File

@ -36,6 +36,7 @@
#include <EEPROM.h> #include <EEPROM.h>
#include <ArduinoOTA.h> #include <ArduinoOTA.h>
#include <errno.h> #include <errno.h>
#include <HIB.h>
#include "config.h" #include "config.h"
#include "utils.h" #include "utils.h"
@ -79,6 +80,17 @@ void WebHandleNotFound();
void WebSetupServer(int bootmode); 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) { 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; IPAddress myIP;
if (bootmode == BOOTMODE_SETUP) { if (bootmode == BOOTMODE_SETUP) {
@ -246,6 +258,9 @@ void setup() {
#ifdef CONFIG_ENABLE_POWER_SAVE #ifdef CONFIG_ENABLE_POWER_SAVE
wifi_set_sleep_type(LIGHT_SLEEP_T); wifi_set_sleep_type(LIGHT_SLEEP_T);
#endif #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; uint nbCycle = CONFIG_SAMPLING_PERIODE_MS / CONFIG_WEB_DELAY_MS;

View File

@ -37,6 +37,9 @@
// GPIO used in PWM // GPIO used in PWM
#define CONFIG_CONTROLLED_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 */ /* DEFAULT VALUE ALSO DEFINED IN CONFIG.H */
//If this GPIO is LOW at boot, device will enter setup mode //If this GPIO is LOW at boot, device will enter setup mode