File tree Expand file tree Collapse file tree 3 files changed +48
-6
lines changed
examples/Nano33BLESenseFirmware Expand file tree Collapse file tree 3 files changed +48
-6
lines changed Original file line number Diff line number Diff line change
1
+ #include " Arduino.h"
2
+ #include " ArduinoBLE.h"
3
+ #include " LowPower.h"
4
+
5
+ #include " nrf_power.h"
6
+ #include " nrf_uarte.h"
7
+ #include " nrf_uart.h"
8
+
9
+ void lowPower ()
10
+ {
11
+ // Disable UARTE0 which is initially enabled by the bootloader
12
+ nrf_uarte_task_trigger (NRF_UARTE0, NRF_UARTE_TASK_STOPRX);
13
+ while (!nrf_uarte_event_check (NRF_UARTE0, NRF_UARTE_EVENT_RXTO)) ;
14
+ NRF_UARTE0->ENABLE = 0 ;
15
+ NRF_UART0->ENABLE = 0 ;
16
+
17
+ // Enable DCDC
18
+ nrf_power_dcdcen_set (true );
19
+
20
+ // Turn off LED_BUILTIN
21
+ digitalWrite (LED_BUILTIN, LOW);
22
+ }
23
+
24
+ void lowPowerWait (unsigned long time)
25
+ {
26
+ rtos::ThisThread::sleep_for (time);
27
+ }
28
+
29
+ void lowPowerBleWait (unsigned long time)
30
+ {
31
+ unsigned long timeRef = millis ();
32
+ while (millis () - timeRef < time) {
33
+ BLE.poll (time - (millis () - timeRef));
34
+ }
35
+ }
Original file line number Diff line number Diff line change
1
+ #ifndef _LOWPOWER_H_
2
+ #define _LOWPOWER_H_
3
+
4
+ void lowPower ();
5
+ void lowPowerWait (unsigned long time );
6
+ void lowPowerBleWait (unsigned long time );
7
+
8
+ #endif //_LOWPOWER_H_
Original file line number Diff line number Diff line change
1
+ #include " LowPower.h"
1
2
#include < arm_math.h>
2
3
3
4
#include < Arduino_APDS9960.h>
@@ -148,16 +149,14 @@ void setup() {
148
149
BLE.addService (service);
149
150
BLE.advertise ();
150
151
151
- digitalWrite (LED_BUILTIN, HIGH );
152
+ lowPower ( );
152
153
}
153
154
154
155
void loop () {
156
+ BLE.poll (1000 );
155
157
while (BLE.connected ()) {
156
- unsigned long now = millis ();
157
- if (abs ((long ) now - (long ) lastNotify) >= 100 ) {
158
- updateSubscribedCharacteristics ();
159
- lastNotify = now;
160
- }
158
+ lowPowerBleWait (100 );
159
+ updateSubscribedCharacteristics ();
161
160
}
162
161
}
163
162
You can’t perform that action at this time.
0 commit comments