diff --git a/README.md b/README.md index 40f19c6..8d3fb91 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/assets/js/ChartManager.js b/assets/js/ChartManager.js index 1acdb88..dcffb22 100644 --- a/assets/js/ChartManager.js +++ b/assets/js/ChartManager.js @@ -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); } }); } diff --git a/assets/js/OpenEarable.js b/assets/js/OpenEarable.js index 106fa74..390f724 100644 --- a/assets/js/OpenEarable.js +++ b/assets/js/OpenEarable.js @@ -64,6 +64,9 @@ const SERVICES = { }, DEVICE_GENERATION_CHARACTERISTIC: { UUID: '45622512-6468-465a-b141-0b9b0f96b468' + }, + HARDWARE_GENERATION_CHARACTERISTIC: { + UUID: '45622513-6468-465a-b141-0b9b0f96b468' } } }, @@ -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( @@ -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) {