Skip to content

Commit 3d50f95

Browse files
committed
fix: improvements after content testing (calibration, uuid, minor)
1 parent a1122aa commit 3d50f95

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

examples/ScienceJournal/ScienceJournal.ino

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ 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;
@@ -43,11 +44,17 @@ void setup(){
4344
while(1);
4445
}
4546

47+
//BLE.setConnectionInterval(6, 12);
48+
4649
String address = BLE.address();
4750

4851
address.toUpperCase();
49-
50-
name = "ScienceKit R3 - ";
52+
#ifdef ARDUINO_NANO_RP2040_CONNECT
53+
name = "ScienceKit R3 - ";
54+
#endif
55+
#ifdef ESP32
56+
name = "ScienceKit - ";
57+
#endif
5158
name += address[address.length() - 5];
5259
name += address[address.length() - 4];
5360
name += address[address.length() - 2];
@@ -121,6 +128,7 @@ void setup(){
121128
#endif
122129
#ifdef ESP32
123130
xTaskCreatePinnedToCore(&freeRTOSUpdate, "update_base", 10000, NULL, 1, &update_base, 1); // starts the update sensors thread on core 1 (user)
131+
xTaskCreatePinnedToCore(&freeRTOSble, "update_ble", 10000, NULL, 1, &update_ble, 0); // starts the ble thread on core 0 (internal)
124132
#endif
125133
}
126134

@@ -136,10 +144,16 @@ void update(void){
136144
static void freeRTOSUpdate(void * pvParameters){
137145
update();
138146
}
139-
#endif
140147

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

142-
void loop(){
156+
void updateBle(){
143157
BLEDevice central = BLE.central();
144158
if (central) {
145159
ble_is_connected = true;
@@ -151,6 +165,9 @@ void loop(){
151165
if (millis()-lastNotify>10){
152166
updateSubscribedCharacteristics();
153167
lastNotify=millis();
168+
#ifdef ESP32
169+
delay(1);
170+
#endif
154171
}
155172
}
156173
}
@@ -163,6 +180,13 @@ void loop(){
163180
}
164181
}
165182

183+
184+
void loop(){
185+
#ifdef ARDUINO_NANO_RP2040_CONNECT
186+
updateBle();
187+
#endif
188+
}
189+
166190
void updateSubscribedCharacteristics(){
167191
/* ________________________________________________________________CURRENT */
168192
if(currentCharacteristic.subscribed()){

examples/ScienceJournal/ble_config.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@ const int VERSION = 0x00000002;
5353
#define BLE_CH____PING "1020"
5454
#define BLE_CH_FUNGEN2 "1021"
5555

56-
56+
#ifdef ARDUINO_NANO_RP2040_CONNECT
5757
#define SCIENCE_KIT_UUID(val) ("555a0003-" val "-467a-9538-01f0652c74e8")
58+
#endif
59+
#ifdef ESP32
60+
#define SCIENCE_KIT_UUID(val) ("555a0004-" val "-467a-9538-01f0652c74e8")
61+
#endif
62+
5863

5964
/*
6065
* SERVICE, VERSION

src/Arduino_ScienceKitCarrier.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ int ScienceKitCarrier::getInputB(){
276276

277277

278278
/********************************************************************/
279-
/* APDS9960 */
279+
/* APDS99xx */
280280
/********************************************************************/
281281

282282
int ScienceKitCarrier::beginAPDS(){
@@ -291,7 +291,7 @@ int ScienceKitCarrier::beginAPDS(){
291291
else{
292292
apds9999->enableColorSensor();
293293
apds9999->enableProximitySensor();
294-
apds9999->setGain(APDS9999_GAIN_1X);
294+
apds9999->setGain(APDS9999_GAIN_3X);
295295
apds9999->setLSResolution(APDS9999_LS_RES_16B);
296296
apds9999->setLSRate(APDS9999_LS_RATE_25MS);
297297
color_sensor_used = APDS9999_VERSION;
@@ -813,7 +813,7 @@ void ScienceKitCarrier::retriveUltrasonicUpdate(){
813813
}
814814

815815
float ScienceKitCarrier::getDistance(){
816-
return distance;
816+
return distance/1000.0;
817817
}
818818

819819
float ScienceKitCarrier::getTravelTime(){

0 commit comments

Comments
 (0)