Skip to content

Commit fbbfd77

Browse files
author
Paolo Calao
authored
Merge pull request #13 from bcmi-labs/cleaning
Cleaning
2 parents c2c0a8d + 31abccf commit fbbfd77

File tree

42 files changed

+252
-11770
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+252
-11770
lines changed

ArduinoBLE_DFU/ArduinoBLE_DFU.ino

Lines changed: 0 additions & 165 deletions
This file was deleted.

Arduino_BHY2/examples/App/App.ino

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Use this sketch if you want to control unisense from
3+
* an external device acting as a host.
4+
* Here, unisense just reacts to external stimuli coming from
5+
* the eslov port or through BLE
6+
*/
7+
8+
#include "Arduino.h"
9+
#include "Arduino_BHY2.h"
10+
11+
// Set DEBUG to true in order to enable debug print
12+
#define DEBUG false
13+
14+
void setup()
15+
{
16+
#if DEBUG
17+
Serial.begin(115200);
18+
BHY2.debug(Serial);
19+
#endif
20+
21+
BHY2.begin();
22+
}
23+
24+
void loop()
25+
{
26+
BHY2.update();
27+
}
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/*
2+
* This sketch shows how unisense can be used in standalone mode.
3+
* Without the need for an host, unisense can run sketches that
4+
* are able to configure the bhi sensors and are able to read all
5+
* the bhi sensors data.
6+
*/
7+
18
#include "Arduino.h"
29
#include "Arduino_BHY2.h"
310

@@ -7,25 +14,16 @@ DataXYZ accValue;
714
#define GYRO_ID (13)
815
DataXYZ gyroValue;
916

10-
#define ORI_ID (43)
11-
DataOrientation orientation;
12-
1317
void configureSensors() {
1418
SensorConfigurationPacket config;
1519
config.sampleRate = 1;
1620
config.latency = 0;
1721

1822
config.sensorId = ACCEL_ID;
19-
BHY2.configureSensor(&config);
20-
21-
config.sensorId = ORI_ID;
22-
BHY2.configureSensor(&config);
23+
BHY2.configureSensor(config);
2324

2425
config.sensorId = GYRO_ID;
25-
BHY2.configureSensor(&config);
26-
27-
config.sensorId = 34;
28-
BHY2.configureSensor(&config);
26+
BHY2.configureSensor(config);
2927
}
3028

3129
void setup()
@@ -42,6 +40,10 @@ void loop()
4240
static auto printTime = millis();
4341
static auto sampleTime = millis();
4442

43+
// Update function should be continuously polled
44+
BHY2.update();
45+
46+
// Retrieve new data at each 10 ms
4547
if (millis() - sampleTime >= 10) {
4648
sampleTime = millis();
4749

@@ -50,29 +52,27 @@ void loop()
5052
BHY2.readSensorData(data);
5153

5254
if (data.sensorId == ACCEL_ID) {
53-
Serial.print("Received accel: ");
55+
Serial.println("Received accel");
5456
BHY2.parse(data, accValue);
5557

5658
} else if (data.sensorId == GYRO_ID) {
57-
Serial.print("Received gyro: ");
59+
Serial.println("Received gyro");
5860
BHY2.parse(data, gyroValue);
5961

60-
} else if (data.sensorId == ORI_ID) {
61-
Serial.println("orientation");
62-
BHY2.parse(data, orientation, 360.0f / 32768.0f);
63-
6462
}
6563
}
6664
}
6765

66+
// Print the last sensor data at each 200 ms
6867
if (millis() - printTime >= 200) {
6968
printTime = millis();
7069

71-
Serial.println(orientation.toString());
70+
Serial.print("Accelerometer values: ");
71+
Serial.println(accValue.toString());
72+
73+
Serial.print("Orientation values: ");
7274
Serial.println(gyroValue.toString());
7375
}
74-
75-
BHY2.update();
7676
}
7777

7878

Arduino_BHY2/examples/app/app.ino

Lines changed: 0 additions & 51 deletions
This file was deleted.

Arduino_BHY2/src/Arduino_BHY2.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,20 @@ void Arduino_BHY2::update()
2828
bleHandler.update();
2929
}
3030

31-
void Arduino_BHY2::configureSensor(SensorConfigurationPacket *config)
31+
void Arduino_BHY2::configureSensor(SensorConfigurationPacket& config)
3232
{
3333
sensortec.configureSensor(config);
3434
}
3535

36+
void Arduino_BHY2::configureSensor(uint8_t sensorId, float sampleRate, uint32_t latency)
37+
{
38+
SensorConfigurationPacket config;
39+
config.sensorId = sensorId;
40+
config.sampleRate = sampleRate;
41+
config.latency = latency;
42+
sensortec.configureSensor(config);
43+
}
44+
3645
void Arduino_BHY2::addSensorData(const SensorDataPacket &sensorData)
3746
{
3847
sensortec.addSensorData(sensorData);

Arduino_BHY2/src/Arduino_BHY2.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class Arduino_BHY2 {
1515
void update();
1616

1717
// API for using the bosch sensortec from sketch
18-
void configureSensor(SensorConfigurationPacket *config);
18+
void configureSensor(SensorConfigurationPacket& config);
19+
void configureSensor(uint8_t sensorId, float sampleRate, uint32_t latency);
1920
void addSensorData(const SensorDataPacket &sensorData);
2021
uint8_t availableSensorData();
2122
bool readSensorData(SensorDataPacket &data);

Arduino_BHY2/src/BLEHandler.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void BLEHandler::receivedSensorConfig(BLEDevice central, BLECharacteristic chara
7878
_debug->println(data.sampleRate);
7979
_debug->println(data.latency);
8080
}
81-
sensortec.configureSensor(&data);
81+
sensortec.configureSensor(data);
8282
}
8383

8484
void BLEHandler::begin()
@@ -114,7 +114,6 @@ void BLEHandler::update()
114114
if (sensorDataCharacteristic.subscribed()) {
115115

116116
// Simulate a request for reading new sensor data
117-
// Better: bypass SensorChannel
118117
uint8_t availableData = sensortec.availableSensorData();
119118
while (availableData) {
120119
SensorDataPacket data;

Arduino_BHY2/src/BoschSensortec.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ void BoschSensortec::begin()
5151
bhy2_update_virtual_sensor_list(&_bhy2);
5252
}
5353

54-
void BoschSensortec::configureSensor(SensorConfigurationPacket *config)
54+
void BoschSensortec::configureSensor(SensorConfigurationPacket& config)
5555
{
56-
auto ret = bhy2_set_virt_sensor_cfg(config->sensorId, config->sampleRate, config->latency, &_bhy2);
56+
auto ret = bhy2_set_virt_sensor_cfg(config.sensorId, config.sampleRate, config.latency, &_bhy2);
5757
if (_debug) _debug->println(get_api_error(ret));
5858
}
5959

0 commit comments

Comments
 (0)