4
4
#include " sensors/SensorManager.h"
5
5
6
6
Arduino_BHY2Host::Arduino_BHY2Host () :
7
- _passthrough(false )
7
+ _passthrough(false ),
8
+ _wiring(NICLA_VIA_ESLOV),
9
+ _debug(NULL )
8
10
{
9
11
}
10
12
@@ -15,6 +17,20 @@ Arduino_BHY2Host::~Arduino_BHY2Host()
15
17
bool Arduino_BHY2Host::begin (bool passthrough, NiclaWiring niclaConnection)
16
18
{
17
19
_passthrough = passthrough;
20
+ _wiring = niclaConnection;
21
+ if (niclaConnection == NICLA_VIA_BLE) {
22
+ #ifdef __BHY2_HOST_BLE_SUPPORTED__
23
+ if (_debug) {
24
+ _debug->println (" NICLA_VIA_BLE selected" );
25
+ }
26
+ return bleHandler.begin ();
27
+ #else
28
+ if (_debug) {
29
+ _debug->println (" Unsupported board!" );
30
+ }
31
+ return false ;
32
+ #endif
33
+ }
18
34
if (niclaConnection == NICLA_AS_SHIELD) {
19
35
eslovHandler.niclaAsShield ();
20
36
}
@@ -23,21 +39,38 @@ bool Arduino_BHY2Host::begin(bool passthrough, NiclaWiring niclaConnection)
23
39
24
40
void Arduino_BHY2Host::update ()
25
41
{
26
- if (_passthrough){
27
- eslovHandler.update ();
42
+ if (_wiring == NICLA_VIA_BLE) {
43
+ #ifdef __BHY2_HOST_BLE_SUPPORTED__
44
+ bleHandler.update ();
45
+ #endif
28
46
} else {
29
- while (availableSensorData () > 0 ) {
30
- SensorDataPacket data;
31
- readSensorData (data);
32
- sensorManager.process (data);
47
+ if (_passthrough){
48
+ eslovHandler.update ();
49
+ } else {
50
+ while (availableSensorData () > 0 ) {
51
+ SensorDataPacket data;
52
+ readSensorData (data);
53
+ sensorManager.process (data);
54
+ }
33
55
}
34
56
}
57
+ }
35
58
59
+ void Arduino_BHY2Host::update (unsigned long ms)
60
+ {
61
+ update ();
62
+ delay (ms);
36
63
}
37
64
38
65
void Arduino_BHY2Host::configureSensor (SensorConfigurationPacket& config)
39
66
{
40
- eslovHandler.writeConfigPacket (config);
67
+ if (_wiring == NICLA_VIA_BLE) {
68
+ #ifdef __BHY2_HOST_BLE_SUPPORTED__
69
+ bleHandler.writeConfigPacket (config);
70
+ #endif
71
+ } else {
72
+ eslovHandler.writeConfigPacket (config);
73
+ }
41
74
}
42
75
43
76
void Arduino_BHY2Host::configureSensor (uint8_t sensorId, float sampleRate, uint32_t latency)
@@ -46,7 +79,13 @@ void Arduino_BHY2Host::configureSensor(uint8_t sensorId, float sampleRate, uint3
46
79
config.sensorId = sensorId;
47
80
config.sampleRate = sampleRate;
48
81
config.latency = latency;
49
- eslovHandler.writeConfigPacket (config);
82
+ if (_wiring == NICLA_VIA_BLE) {
83
+ #ifdef __BHY2_HOST_BLE_SUPPORTED__
84
+ bleHandler.writeConfigPacket (config);
85
+ #endif
86
+ } else {
87
+ eslovHandler.writeConfigPacket (config);
88
+ }
50
89
}
51
90
52
91
uint8_t Arduino_BHY2Host::requestAck ()
@@ -79,9 +118,18 @@ void Arduino_BHY2Host::parse(SensorDataPacket& data, DataOrientation& vector, fl
79
118
DataParser::parseEuler (data, vector, scaleFactor);
80
119
}
81
120
121
+ NiclaWiring Arduino_BHY2Host::getNiclaConnection ()
122
+ {
123
+ return _wiring;
124
+ }
125
+
82
126
void Arduino_BHY2Host::debug (Stream &stream)
83
127
{
128
+ _debug = &stream;
84
129
eslovHandler.debug (stream);
130
+ #ifdef __BHY2_HOST_BLE_SUPPORTED__
131
+ bleHandler.debug (stream);
132
+ #endif
85
133
}
86
134
87
135
Arduino_BHY2Host BHY2Host;
0 commit comments