Skip to content

Commit c90eeb3

Browse files
committed
Update ble sender
1 parent 427bc01 commit c90eeb3

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

src/ble_gravitymon.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,14 @@ void BleSender::sendTiltData(String& color, float tempF, float gravSG,
148148
_advertising->stop();
149149
}
150150

151-
void BleSender::sendRaptV1Data(float battery, float tempC, float gravSG,
151+
void BleSender::sendRaptV1Data(float batteryPercentage, float tempC, float gravSG,
152152
float angle) {
153153
Log.info(F("Starting rapt v1 beacon data transmission" CR));
154154

155155
_advertising->stop();
156156

157157
uint16_t t = isnan(tempC) ? 0xffff : (tempC + 273.15) * 128.0;
158-
uint16_t b = isnan(battery) ? 0xffff : battery * 256;
158+
uint16_t b = isnan(batteryPercentage) ? 0xffff : batteryPercentage * 256;
159159
uint16_t a = isnan(angle) ? 0xffff : angle * 16;
160160
uint32_t chipId = 0;
161161

@@ -197,7 +197,7 @@ void BleSender::sendRaptV1Data(float battery, float tempC, float gravSG,
197197
mf += static_cast<char>((t >> 8)); // Temperature
198198
mf += static_cast<char>((t & 0xFF));
199199

200-
floatUnion.f = gravSG * 1000; // Gravity
200+
floatUnion.f = gravSG; // Gravity
201201
mf += static_cast<char>(floatUnion.b[3]);
202202
mf += static_cast<char>(floatUnion.b[2]);
203203
mf += static_cast<char>(floatUnion.b[1]);
@@ -228,9 +228,8 @@ void BleSender::sendRaptV1Data(float battery, float tempC, float gravSG,
228228
_advertising->stop();
229229
}
230230

231-
void BleSender::sendRaptV2Data(float battery, float tempC, float gravSG,
232-
float angle, float velocity,
233-
bool velocityValid) {
231+
void BleSender::sendRaptV2Data(float batteryPercentage, float tempC, float gravSG,
232+
float angle, float velocity) {
234233
Log.info(F("Starting rapt v2 beacon data transmission" CR));
235234

236235
_advertising->stop();
@@ -241,7 +240,7 @@ void BleSender::sendRaptV2Data(float battery, float tempC, float gravSG,
241240
} floatUnion;
242241

243242
uint16_t t = isnan(tempC) ? 0xffff : (tempC + 273.15) * 128.0;
244-
uint16_t b = isnan(battery) ? 0xffff : battery * 256;
243+
uint16_t b = isnan(batteryPercentage) ? 0xffff : batteryPercentage * 256;
245244
uint16_t a = isnan(angle) ? 0xffff : angle * 16;
246245

247246
std::string mf = "";
@@ -268,9 +267,9 @@ void BleSender::sendRaptV2Data(float battery, float tempC, float gravSG,
268267
mf += static_cast<char>(0x02); // Rapt v2
269268
mf += static_cast<char>(0x00); // Padding
270269

271-
mf += static_cast<char>(velocityValid ? 0x01 : 0x00); // Valocity valid
270+
mf += static_cast<char>(isnan(velocity) ? 0x00 : 0x01); // Velocity valid
272271

273-
floatUnion.f = velocity; // Velocity
272+
floatUnion.f = velocity; // Velocity
274273
mf += static_cast<char>(floatUnion.b[3]);
275274
mf += static_cast<char>(floatUnion.b[2]);
276275
mf += static_cast<char>(floatUnion.b[1]);
@@ -279,7 +278,7 @@ void BleSender::sendRaptV2Data(float battery, float tempC, float gravSG,
279278
mf += static_cast<char>((t >> 8)); // Temperature
280279
mf += static_cast<char>((t & 0xFF));
281280

282-
floatUnion.f = gravSG * 1000; // Gravity
281+
floatUnion.f = gravSG; // Gravity
283282
mf += static_cast<char>(floatUnion.b[3]);
284283
mf += static_cast<char>(floatUnion.b[2]);
285284
mf += static_cast<char>(floatUnion.b[1]);
@@ -292,7 +291,7 @@ void BleSender::sendRaptV2Data(float battery, float tempC, float gravSG,
292291
mf += static_cast<char>(0x00); // Z
293292
mf += static_cast<char>(0x00);
294293

295-
mf += static_cast<char>((b >> 8)); // Battery (batt_v*1000)
294+
mf += static_cast<char>((b >> 8)); // Battery (batt_v)
296295
mf += static_cast<char>((b & 0xFF));
297296

298297
#if LOG_LEVEL == 6

src/ble_gravitymon.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ class BleSender {
4848

4949
// Beacons
5050
void sendTiltData(String& color, float tempF, float gravSG, bool tiltPro);
51-
void sendRaptV1Data(float battery, float tempC, float gravSG, float angle);
52-
void sendRaptV2Data(float battery, float tempC, float gravSG, float angle,
53-
float velocity, bool velocityValid);
51+
void sendRaptV1Data(float batteryPercentage, float tempC, float gravSG, float angle);
52+
void sendRaptV2Data(float batteryPercentage, float tempC, float gravSG, float angle,
53+
float velocity); // If velocity = NAN velocity valid flag is false
5454
void sendEddystoneData(float battery, float tempC, float gravSG, float angle);
5555
void sendCustomBeaconData(float battery, float tempC, float gravSG,
5656
float angle);

src/main_gravitymon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ bool loopReadGravity() {
375375
myBleSender.sendRaptV2Data(
376376
getBatteryPercentage(myBatteryVoltage.getVoltage(),
377377
BatteryType::LithiumIon),
378-
tempC, gravitySG, angle, velocity, gv.isVelocityValid());
378+
tempC, gravitySG, angle, gv.isVelocityValid() ? velocity : NAN);
379379
} break;
380380
}
381381
}

src_docs/source/releases.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ v2.4.0
77
======
88

99
* Update dependencies to latest version
10+
* (Bug) Fixed bug in RAPT v2 format not sending the correct gravity value.
1011

1112
New features
1213
++++++++++++

0 commit comments

Comments
 (0)