Skip to content

Commit 50b1166

Browse files
committed
add: ble on core 0 and freertos thread
1 parent c3c857b commit 50b1166

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

examples/ScienceJournal/ScienceJournal.ino

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@ rtos::Thread thread_update_sensors;
3030

3131
#ifdef ESP32
3232
TaskHandle_t update_base;
33+
TaskHandle_t update_ble;
3334
#endif
3435

3536
bool ble_is_connected = false;
3637

3738

3839

3940
void setup(){
41+
pinMode(6,OUTPUT);
4042
science_kit.begin(NO_AUXILIARY_THREADS); // Doesn't start the BME688 and external temperature threads for the moment
4143

4244
if (!BLE.begin()){
4345
while(1);
4446
}
4547

46-
#ifdef ESP32
47-
BLE.setConnectionInterval(6, 12);
48-
#endif
48+
//BLE.setConnectionInterval(6, 12);
4949

5050
String address = BLE.address();
5151

@@ -125,13 +125,16 @@ void setup(){
125125
#endif
126126
#ifdef ESP32
127127
xTaskCreatePinnedToCore(&freeRTOSUpdate, "update_base", 10000, NULL, 1, &update_base, 1); // starts the update sensors thread on core 1 (user)
128+
xTaskCreatePinnedToCore(&freeRTOSble, "update_ble", 10000, NULL, 1, &update_ble, 0); // starts the ble thread on core 0 (internal)
128129
#endif
129130
}
130131

131132

132133
void update(void){
133134
while(1){
135+
digitalWrite(6,HIGH);
134136
science_kit.update(ROUND_ROBIN_ENABLED);
137+
digitalWrite(6,LOW);
135138
delay(25);
136139
}
137140
}
@@ -140,10 +143,16 @@ void update(void){
140143
static void freeRTOSUpdate(void * pvParameters){
141144
update();
142145
}
143-
#endif
144146

147+
static void freeRTOSble(void * pvParameters){
148+
while(1){
149+
updateBle();
150+
delay(1);
151+
}
152+
}
153+
#endif
145154

146-
void loop(){
155+
void updateBle(){
147156
BLEDevice central = BLE.central();
148157
if (central) {
149158
ble_is_connected = true;
@@ -155,6 +164,9 @@ void loop(){
155164
if (millis()-lastNotify>10){
156165
updateSubscribedCharacteristics();
157166
lastNotify=millis();
167+
#ifdef ESP32
168+
delay(1);
169+
#endif
158170
}
159171
}
160172
}
@@ -167,6 +179,13 @@ void loop(){
167179
}
168180
}
169181

182+
183+
void loop(){
184+
#ifdef ARDUINO_NANO_RP2040_CONNECT
185+
updateBle();
186+
#endif
187+
}
188+
170189
void updateSubscribedCharacteristics(){
171190
/* ________________________________________________________________CURRENT */
172191
if(currentCharacteristic.subscribed()){

0 commit comments

Comments
 (0)