-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainRGBWSensor.cpp
More file actions
78 lines (67 loc) · 2.16 KB
/
Copy pathmainRGBWSensor.cpp
File metadata and controls
78 lines (67 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// RGBW colour / ambient-light sensor (VEML6040) exposed over WiFi (web + REST)
// and BLE. Battery-aware: the wake button on GPIO0 disables deep sleep and
// doubles as the config-mode tap gesture.
//
#include <Arduino.h>
#include "iotsa.h"
#include "iotsaWifi.h"
#include "iotsaOta.h"
#include "iotsaBattery.h"
#include "iotsaInput.h"
#include "iotsaBLEServer.h"
#include "iotsaRGBWSensorMod.h"
// Low signal on this pin disables deep sleep; it is also the config-mode
// tap button (see button0Pressed() below).
#define PIN_DISABLE_SLEEP 0
IotsaApplication application("Iotsa RGBWSensor Server");
IotsaWifiMod wifiMod(application);
IotsaOtaMod otaMod(application);
IotsaBatteryMod batteryMod(application);
Button buttonWake(PIN_DISABLE_SLEEP, true, false, true);
Input *inputs[] = {
&buttonWake
};
IotsaInputMod inputMod(application, inputs, 1);
IotsaRGBWSensorMod rgbwMod(application);
IotsaBLEServerMod bleserverMod(application);
//
// Keep track of button presses, so we can switch mode or reboot with quick presses.
//
bool button0Pressed() {
const int TAP_COUNT_MODE_CHANGE=3;
const int TAP_COUNT_REBOOT=6;
const uint32_t TAP_DURATION=1000;
IFDEBUG IotsaSerial.println("button0 pressed");
iotsaController.extendCurrentMode();
static uint32_t lastButtonTapMillis = 0;
static int buttonTapCount = 0;
uint32_t now = millis();
if (lastButtonTapMillis > 0 && now < lastButtonTapMillis + TAP_DURATION) {
// A button change that was quick enough for a tap
lastButtonTapMillis = now;
buttonTapCount++;
if (buttonTapCount == TAP_COUNT_MODE_CHANGE) {
IFDEBUG IotsaSerial.println("tap mode change");
iotsaController.allowRequestedConfigurationMode();
}
if (buttonTapCount == TAP_COUNT_REBOOT) {
IFDEBUG IotsaSerial.println("tap mode reboot");
iotsaController.requestReboot(1000);
}
} else {
// Either the first change, or too late. Reset.
lastButtonTapMillis = millis();
buttonTapCount = 0;
}
return true;
}
void setup(void){
application.setup();
application.lateSetup();
batteryMod.setPinDisableSleep(PIN_DISABLE_SLEEP);
buttonWake.setCallback(button0Pressed);
}
void loop(void){
application.loop();
}