Bunch of hack to link diode with a button on a sonoff
This commit is contained in:
parent
abbfec48c9
commit
10df372293
@ -71,6 +71,9 @@ const int gpioControlled[] = CONFIG_CONTROLLED_GPIO;
|
|||||||
const int gpioObserved[] = CONFIG_OBSERVED_GPIO;
|
const int gpioObserved[] = CONFIG_OBSERVED_GPIO;
|
||||||
const int pwmControlled[] = CONFIG_CONTROLLED_PWM;
|
const int pwmControlled[] = CONFIG_CONTROLLED_PWM;
|
||||||
|
|
||||||
|
uint8_t shouldSwitch = 0;
|
||||||
|
uint8_t switchSide = 0;
|
||||||
|
|
||||||
/* Set these to your desired credentials. */
|
/* Set these to your desired credentials. */
|
||||||
const char *ssid = CONFIG_SSID_NAME;
|
const char *ssid = CONFIG_SSID_NAME;
|
||||||
|
|
||||||
@ -96,6 +99,15 @@ void onLongButtonPressed(uint8_t pin){
|
|||||||
WiFi.softAP(ssid);
|
WiFi.softAP(ssid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onShortButtonPressed(uint8_t pin, int state){
|
||||||
|
SKETCH_DEBUG_PRINTLN("OnShortButtonPressed");
|
||||||
|
if(pin == CONFIG_SETUP_BUTTON){
|
||||||
|
shouldSwitch = 1;
|
||||||
|
switchSide = digitalRead(12) ? 0 : 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void WifiSetup(productConfig conf) {
|
void WifiSetup(productConfig conf) {
|
||||||
@ -188,7 +200,7 @@ void OTASetup() {
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
#ifdef CONFIG_SETUP_BUTTON
|
#ifdef CONFIG_SETUP_BUTTON
|
||||||
new HIB(CONFIG_SETUP_BUTTON, HIGH, NULL, NULL, onLongButtonPressed);
|
new HIB(CONFIG_SETUP_BUTTON, HIGH, NULL, onShortButtonPressed, onLongButtonPressed, 5000, 100);
|
||||||
#endif
|
#endif
|
||||||
pinMode(3, OUTPUT);
|
pinMode(3, OUTPUT);
|
||||||
|
|
||||||
@ -250,6 +262,7 @@ 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
|
||||||
|
pinMode(13, OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint nbCycle = CONFIG_SAMPLING_PERIODE_MS / CONFIG_WEB_DELAY_MS;
|
uint nbCycle = CONFIG_SAMPLING_PERIODE_MS / CONFIG_WEB_DELAY_MS;
|
||||||
@ -264,6 +277,12 @@ void loop() {
|
|||||||
}
|
}
|
||||||
delay(CONFIG_WEB_DELAY_MS);
|
delay(CONFIG_WEB_DELAY_MS);
|
||||||
|
|
||||||
|
if (shouldSwitch) {
|
||||||
|
shouldSwitch = 0;
|
||||||
|
MqttChangeGpioValue(12, switchSide);
|
||||||
|
}
|
||||||
|
digitalWrite(13, digitalRead(12) ? 0 : 1);
|
||||||
|
|
||||||
nbCycle++;
|
nbCycle++;
|
||||||
if (nbCycle > CONFIG_SAMPLING_PERIODE_MS / CONFIG_WEB_DELAY_MS) {
|
if (nbCycle > CONFIG_SAMPLING_PERIODE_MS / CONFIG_WEB_DELAY_MS) {
|
||||||
if (!BMP180GetTempAndPressure(temp, pressure)) {
|
if (!BMP180GetTempAndPressure(temp, pressure)) {
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
|
|
||||||
// GPIO that can be set or get by mqtt and set via http
|
// GPIO that can be set or get by mqtt and set via http
|
||||||
// Should have less value than MAXSUBSCRIPTIONS
|
// Should have less value than MAXSUBSCRIPTIONS
|
||||||
//#define CONFIG_CONTROLLED_GPIO {12,13}
|
#define CONFIG_CONTROLLED_GPIO {12,13}
|
||||||
|
|
||||||
// GPIO that can be get by mqtt and http
|
// GPIO that can be get by mqtt and http
|
||||||
// Pin 6 to 11 and 16 can not be used for mqtt
|
// Pin 6 to 11 and 16 can not be used for mqtt
|
||||||
|
Loading…
Reference in New Issue
Block a user