Skip to content

Commit

Permalink
Merge pull request #9 from OpenEarable/1.3.0
Browse files Browse the repository at this point in the history
1.3.0
  • Loading branch information
TobiasRoeddiger authored Oct 2, 2023
2 parents fbc1c1c + 1ab43ab commit 2372e4a
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 87 deletions.
45 changes: 36 additions & 9 deletions assets/js/ConnectionManager.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
var openEarable = new OpenEarable();

openEarable.bleManager.subscribeOnConnected(async () => {
$('#connectDeviceButton').hide()
$('#disconnectDeviceButton').show()
$(".is-connect-enabled").prop('disabled', false);

// Get device identifier and generation after connected
const firmwareVersion = await openEarable.readFirmwareVersion();
const hardwareVersion = await openEarable.readHardwareVersion();

$('#disconnectDeviceButton').prop('disabled', false);

// Update the DOM with the obtained values
$('#fwVersion').text(firmwareVersion);
$('#deviceVersion').text(hardwareVersion);
Expand All @@ -21,29 +20,57 @@ openEarable.bleManager.subscribeOnConnected(async () => {
openEarable.bleManager.subscribeOnDisconnected(() => {
$('#disconnectDeviceButton').hide()
$('#connectDeviceButton').show()
$(".is-connect-enabled").prop('disabled', true);
$('#batteryLevel').hide();
$("#connectDeviceButton").prop('disabled', false);
$('#batteryLevel').text("XX")
$('#batteryChargingIndicator').hide();
$('#batteryChargedIndicator').hide();

log("OpenEarable disconnected.", type = "WARNING")

// Reset the values to default when disconnected
$('#connectedDevice').text("OpenEarable not connected");
$('#connectedDevice').text("OpenEarable-XXXX");
$('#fwVersion').text("X.X.X");
$('#deviceVersion').text("X.X.X");
});


openEarable.subscribeBatteryLevelChanged((batteryLevel) => {
$('#batteryLevel').text(' (' + batteryLevel + '%)');
$('#connectDeviceButton').hide()
$('#disconnectDeviceButton').show()
$(".is-connect-enabled").prop('disabled', false);

$('#batteryLevel').text(batteryLevel);
$('#batteryLevel').show();
})

$('#connectDeviceButton').click(() => {
openEarable.subscribeBatteryStateChanged((batteryState) => {
if (batteryState === 1) {
$('#batteryChargingIndicator').show();
$('#batteryChargedIndicator').hide();
} else if (batteryState === 2) {
$('#batteryChargedIndicator').show();
$('#batteryChargingIndicator').hide();
} else {
$('#batteryChargingIndicator').hide();
$('#batteryChargedIndicator').hide();
}

})

$('#connectDeviceButton').click(async () => {
$('#connectDeviceButton').prop('disabled', true);
log("Scanning for OpenEarables. Please select.", type = "MESSAGE")
openEarable.bleManager.connect();
try {
await openEarable.bleManager.connect();
} catch (e) {
$('#connectDeviceButton').prop('disabled', false);
}

});

$('#disconnectDeviceButton').click(() => {
$(".is-connect-enabled").prop('disabled', true);
$('#disconnectDeviceButton').prop('disabled', true);
log("Disconnecting OpenEarable.", type = "MESSAGE")
openEarable.bleManager.disconnect();
});
2 changes: 1 addition & 1 deletion assets/js/LEDManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function startRainbowMode() {

h += increment;
if (h > 1) h = 0; // Reset hue value
}, 100); // Adjust interval for speed as well, e.g., 100ms
}, 300); // Adjust interval for speed as well, e.g., 100ms
}

function stopRainbowMode() {
Expand Down
Loading

0 comments on commit 2372e4a

Please sign in to comment.