2
2
#include < Main.h>
3
3
4
4
#define CLASS " Main"
5
- // #define TICKS_PERIOD_TIMER1 300000
6
- #define SLEEP_DELAY_US 1000 * 1000 * 10
5
+ #define TICKS_PERIOD_TIMER1 300000
6
+ #define SLEEP_DELAY_US 1000 * 1000 * 5
7
+ #define FPM_SLEEP_MAX_TIME 0xFFFFFFF
8
+ #ifndef WIFI_SSID
9
+ #error "Must provide WIFI_SSID"
10
+ #endif
11
+ #ifndef WIFI_PASSWORD
12
+ #error "Must provide WIFI_PASSWORD"
13
+ #endif
14
+
15
+
16
+ extern " C" {
17
+ #include " user_interface.h"
18
+ }
7
19
8
- // volatile char nroInterruptsQueued = 0; // counter to keep track of amount of timing
20
+ volatile char nroInterruptsQueued = 0 ; // counter to keep track of amount of timing
9
21
// interrupts queued
10
22
11
23
enum ButtonPressed {
@@ -20,9 +32,10 @@ Module m;
20
32
/* * INTERRUPTS ***/
21
33
/* ****************/
22
34
23
- // ICACHE_RAM_ATTR void timingInterrupt(void) {
24
- // nroInterruptsQueued++;
25
- // }
35
+ ICACHE_RAM_ATTR void timingInterrupt (void ) {
36
+ nroInterruptsQueued++;
37
+ }
38
+
26
39
27
40
/* *****************/
28
41
/* ** CALLBACKS ***/
@@ -47,17 +60,17 @@ void setupPins() {
47
60
pinMode (LED0_PIN, OUTPUT);
48
61
pinMode (LED1_PIN, OUTPUT);
49
62
pinMode (LCD_BACKLIGHT_PIN, OUTPUT);
50
- pinMode (BUZZER0_PIN, OUTPUT);
63
+ // pinMode(BUZZER0_PIN, OUTPUT); // will break serial communication
51
64
log (CLASS, Info, " PINS READY" );
52
65
}
53
66
54
67
// void setupInterrupts() {
55
- // timer1_disable();
56
- // timer1_isr_init();
57
- // timer1_attachInterrupt(timingInterrupt);
58
- // timer1_enable(TIM_DIV265, TIM_EDGE, TIM_LOOP);
59
- // timer1_write(TICKS_PERIOD_TIMER1);
60
- // log(CLASS, Info, "INT READY");
68
+ // timer1_disable();
69
+ // timer1_isr_init();
70
+ // timer1_attachInterrupt(timingInterrupt);
71
+ // timer1_enable(TIM_DIV265, TIM_EDGE, TIM_LOOP);
72
+ // timer1_write(TICKS_PERIOD_TIMER1);
73
+ // log(CLASS, Info, "INT READY");
61
74
// }
62
75
63
76
void setup () {
@@ -88,25 +101,57 @@ ButtonPressed readButtons() {
88
101
}
89
102
}
90
103
104
+ void doDelays ();
105
+ void initWifi ();
106
+
107
+ const char * ssid = " ssid" ;
108
+ const char * password = " pass" ;
109
+
91
110
void loop () {
92
- // bool wdtInterrupt = nroInterruptsQueued > 0;
93
111
94
- // if (wdtInterrupt) {
95
- ButtonPressed button = readButtons ();
96
- // nroInterruptsQueued--;
97
- log (CLASS, Info, " INT" );
98
- m.loop (button == ButtonModeWasPressed, button == ButtonSetWasPressed, 1 /* wdtInterrupt*/ );
99
- // m.getClock()->setNroInterruptsQueued(nroInterruptsQueued);
100
- // }
112
+ initWifi ();
101
113
102
- // if (nroInterruptsQueued <= 0) { // no interrupts queued
103
- // nroInterruptsQueued = 0 ;
104
- // }
114
+ Serial. println ( " Light sleep & delays: " );
115
+ wifi_set_sleep_type (LIGHT_SLEEP_T) ;
116
+ doDelays ();
105
117
106
- // ESP.deepSleep(SLEEP_DELAY_US, WAKE_RF_DEFAULT);
118
+ Serial.println (" Run module:" );
119
+ ButtonPressed button = readButtons ();
120
+ log (CLASS, Info, " INT" );
121
+ m.loop (button == ButtonModeWasPressed, button == ButtonSetWasPressed, true );
107
122
108
- log (CLASS, Info, " WOKE UP" );
123
+ Serial.println (" None sleep & delays:" );
124
+ wifi_set_sleep_type (NONE_SLEEP_T);
125
+ doDelays ();
109
126
127
+ WiFi.disconnect ();
128
+ Serial.print (" WiFi disconnected, IP address: " ); Serial.println (WiFi.localIP ());
129
+ Serial.println (" Light sleep & delays:" );
130
+ wifi_set_sleep_type (LIGHT_SLEEP_T);
131
+ doDelays ();
132
+
133
+ }
134
+
135
+ void doDelays () {
136
+ Serial.println (" Yield for 1 sec" );
137
+ long endMs = millis () + 1000 ;
138
+ while (millis () < endMs) {
139
+ yield ();
140
+ }
141
+
142
+ Serial.println (" Delay for 1 sec" );
143
+ delay (1000 );
144
+ }
145
+
146
+ void initWifi () {
147
+ WiFi.mode (WIFI_STA);
148
+ WiFi.begin (WIFI_SSID, WIFI_PASSWORD);
149
+ while ((WiFi.status () != WL_CONNECTED)) {
150
+ delay (500 );
151
+ Serial.print (" ." );
152
+ }
153
+ Serial.println (" " );
154
+ Serial.print (" WiFi connected, IP address: " ); Serial.println (WiFi.localIP ());
110
155
}
111
156
112
157
#endif // UNIT_TEST
0 commit comments