Skip to content

Commit

Permalink
v1.7.1
Browse files Browse the repository at this point in the history
A quick hotfix
+ Fixes BT mag status sometimes always reporting unknown (because there's some extra "green" value? goes from 0-3, red, yellow, green, green 2?)
+ Clarify logs
  • Loading branch information
JovannMC committed Apr 17, 2024
1 parent d995840 commit 0b6bbe2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "haritorax-interpreter",
"version": "1.7.0",
"version": "1.7.1",
"homepage": "https://github.com/JovannMC/haritorax-interpreter",
"repository": "https://github.com/JovannMC/haritorax-interpreter",
"bugs": {
Expand Down
37 changes: 19 additions & 18 deletions src/devices/haritorax-wireless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,7 @@ export default class HaritoraXWireless extends EventEmitter {
"leftAnkle",
"leftElbow",
];
const TRACKERS_GROUP_TWO = [
"hip",
"chest",
"leftKnee",
"rightElbow",
];
const TRACKERS_GROUP_TWO = ["hip", "chest", "leftKnee", "rightElbow"];

log(gx.getTrackerAssignment().toString());

Expand All @@ -332,7 +327,6 @@ export default class HaritoraXWireless extends EventEmitter {
const sensorModeValue = new DataView(
sensorModeBuffer.buffer
).getInt8(0);
log(`Sending sensor mode to ${trackerName}: ${sensorModeValue}`);
await bluetooth.write(
trackerName,
settingsService,
Expand All @@ -342,7 +336,6 @@ export default class HaritoraXWireless extends EventEmitter {

const fpsModeBuffer = Buffer.from([fpsMode === 50 ? 1 : 2]);
const fpsModeValue = new DataView(fpsModeBuffer.buffer).getInt8(0);
log(`Sending FPS mode to ${trackerName}: ${fpsModeValue}`);
await bluetooth.write(
trackerName,
settingsService,
Expand All @@ -358,9 +351,6 @@ export default class HaritoraXWireless extends EventEmitter {
const correctionValue = new DataView(
correctionBuffer.buffer
).getInt8(0);
log(
`Sending sensor auto correction to ${trackerName}: ${correctionValue}`
);
await bluetooth.write(
trackerName,
settingsService,
Expand All @@ -370,9 +360,6 @@ export default class HaritoraXWireless extends EventEmitter {

const ankleBuffer = Buffer.from([ankleMotionDetection ? 1 : 0]);
const ankleValue = new DataView(ankleBuffer.buffer).getInt8(0);
log(
`Sending ankle motion detection to ${trackerName}: ${ankleValue}`
);
await bluetooth.write(
trackerName,
settingsService,
Expand All @@ -386,6 +373,12 @@ export default class HaritoraXWireless extends EventEmitter {
log(`Sensor auto correction: ${sensorAutoCorrection}`);
log(`Ankle motion detection: ${ankleMotionDetection}`);

log(`Raw hex data calculated to be sent:`);
log(`Sensor mode: ${sensorModeValue}`);
log(`FPS mode: ${fpsModeValue}`);
log(`Sensor auto correction: ${correctionValue}`);
log(`Ankle motion detection: ${ankleValue}`);

trackerSettings.set(trackerName, [
sensorMode,
fpsMode,
Expand Down Expand Up @@ -451,7 +444,9 @@ export default class HaritoraXWireless extends EventEmitter {
} else {
trackerSettingsRaw.set(trackerName, hexValue);
log(
`${trackerName} - Data written to serial port ${trackerPort}: ${trackerSettingsBuffer.toString().replace(/\r\n/g, ' ')}`
`${trackerName} - Data written to serial port ${trackerPort}: ${trackerSettingsBuffer
.toString()
.replace(/\r\n/g, " ")}`
);
}
});
Expand Down Expand Up @@ -556,7 +551,9 @@ export default class HaritoraXWireless extends EventEmitter {
} else {
trackerSettingsRaw.set(trackerName, hexValue);
log(
`${trackerName} - Data written to serial port ${trackerPort}: ${trackerSettingsBuffer.toString().replace(/\r\n/g, ' ')}`
`${trackerName} - Data written to serial port ${trackerPort}: ${trackerSettingsBuffer
.toString()
.replace(/\r\n/g, " ")}`
);
}
});
Expand Down Expand Up @@ -1406,19 +1403,22 @@ function processTrackerData(data: string, trackerName: string) {
* @fires haritora#mag
**/
function processMagData(data: string, trackerName: string) {
const GREEN_2 = 3;
const GREEN = 2;
const YELLOW = 1;
const RED = 0;

let magStatus;

const buffer = Buffer.from(data, "base64");
const magData = buffer.readUInt8(0);

switch (magData) {
// sometimes 3 is being reported, so we'll just treat it as green
case GREEN:
magStatus = "green";
break;
case GREEN_2:
magStatus = "green";
break;
case YELLOW:
magStatus = "yellow";
break;
Expand All @@ -1427,6 +1427,7 @@ function processMagData(data: string, trackerName: string) {
break;
default:
magStatus = "unknown";
log(`Unknown mag data for ${trackerName}: ${magData}`);
break;
}

Expand Down
6 changes: 4 additions & 2 deletions src/mode/bluetooth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ export default class Bluetooth extends EventEmitter {
characteristicInstance.read((err: any, data: any) => {
const characteristicName = characteristics.get(characteristic);
if (err) {
error(`Error reading characteristic ${characteristicName}: ${err}`);
error(
`Error reading characteristic ${characteristicName}: ${err}`
);
reject(err);
return;
}
Expand All @@ -292,7 +294,7 @@ export default class Bluetooth extends EventEmitter {
}

log(
`Writing to characteristic ${characteristic} of service ${service}`
`Writing to characteristic ${characteristic} of service ${service} for device ${localName}`
);
const device = this.getDeviceInfo(localName);
if (!device) {
Expand Down

0 comments on commit 0b6bbe2

Please sign in to comment.