Browse Source

Use Reprog button as setup button on long press

gpiosensors
Mathieu Maret 5 years ago
parent
commit
3d82e2a200
  1. 15
      WifiControlSensor/WifiControlSensor.ino
  2. 3
      WifiControlSensor/config_device.h

15
WifiControlSensor/WifiControlSensor.ino

@ -36,6 +36,7 @@
#include <EEPROM.h>
#include <ArduinoOTA.h>
#include <errno.h>
#include <HIB.h>
#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;

3
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

Loading…
Cancel
Save