Skip to content

Commit

Permalink
device hardware is not hard coded anymore and fixed bug when clearing…
Browse files Browse the repository at this point in the history
… charts
  • Loading branch information
o-bagge committed Jan 5, 2024
1 parent 7a6c69a commit 4149779
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const openEarable = new OpenEarable();
// Read device information once connected
openEarable.bleManager.subscribeOnConnected(async () => {
const deviceId = await openEarable.readDeviceIdentifier();
const firmwareVersion = await openEarable.readHardwareVersion();
const hardwareVersion = await openEarable.readFirmwareVersion();
const firmwareVersion = await openEarable.readFirmwareVersion();
const hardwareVersion = await openEarable.readHardwareVersion();
});

// Connect to OpenEarable
Expand Down
14 changes: 7 additions & 7 deletions assets/js/ChartManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,13 @@ function onClearGraphs() {
chartIds.forEach((chartId) => {
const chart = charts.find(chart => chart.id === chartId);
if (chart) {
chart.data.labels = [];
if (chart.data.datasets) {
chart.data.datasets.forEach((dataset) => {
dataset.data = [];
});
}
chart.update();
chart.data.labels.length = 0;
chart.data.datasets.forEach((dataset) => {
dataset.data.length = 0;
});
chart.options.scales.x.min = 0;
chart.options.scales.x.max = 149;
setTimeout(() => chart.update(), 0);
}
});
}
16 changes: 12 additions & 4 deletions assets/js/OpenEarable.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ const SERVICES = {
},
DEVICE_GENERATION_CHARACTERISTIC: {
UUID: '45622512-6468-465a-b141-0b9b0f96b468'
},
HARDWARE_GENERATION_CHARACTERISTIC: {
UUID: '45622513-6468-465a-b141-0b9b0f96b468'
}
}
},
Expand Down Expand Up @@ -151,10 +154,6 @@ class OpenEarable {
return new TextDecoder().decode(value);
}

async readHardwareVersion() {
return "1.3.0";
}

async readFirmwareVersion() {
this.bleManager.ensureConnected();
const value = await this.bleManager.readCharacteristic(
Expand All @@ -163,6 +162,15 @@ class OpenEarable {
);
return new TextDecoder().decode(value);
}

async readHardwareVersion() {
this.bleManager.ensureConnected();
const value = await this.bleManager.readCharacteristic(
SERVICES.DEVICE_INFO_SERVICE.UUID,
SERVICES.DEVICE_INFO_SERVICE.CHARACTERISTICS.HARDWARE_GENERATION_CHARACTERISTIC.UUID
);
return new TextDecoder().decode(value);
}


subscribeBatteryLevelChanged(callback) {
Expand Down

0 comments on commit 4149779

Please sign in to comment.