mirror of
https://github.com/aljazceru/meshcore-web.git
synced 2025-12-17 16:24:18 +01:00
show battery level
This commit is contained in:
@@ -60,6 +60,7 @@ class Connection {
|
||||
|
||||
// clear previous connection state
|
||||
GlobalState.contacts = [];
|
||||
GlobalState.batteryPercentage = null;
|
||||
|
||||
// update connection and listen for events
|
||||
GlobalState.connection = connection;
|
||||
@@ -144,14 +145,20 @@ class Connection {
|
||||
// initial setup without needing database
|
||||
await this.loadSelfInfo();
|
||||
await this.syncDeviceTime();
|
||||
await this.updateBatteryPercentage();
|
||||
|
||||
// wait for database to be ready
|
||||
await databaseToBeReady;
|
||||
|
||||
// sync messages
|
||||
// fetch data after database is ready
|
||||
await this.loadContacts();
|
||||
await this.syncMessages();
|
||||
|
||||
// auto update battery percentage once per minute
|
||||
setInterval(async () => {
|
||||
await this.updateBatteryPercentage();
|
||||
}, 60000);
|
||||
|
||||
}
|
||||
|
||||
static async onDisconnected() {
|
||||
@@ -166,6 +173,17 @@ class Connection {
|
||||
GlobalState.contacts = await GlobalState.connection.getContacts();
|
||||
}
|
||||
|
||||
static async updateBatteryPercentage() {
|
||||
if(GlobalState.connection){
|
||||
try {
|
||||
const response = await GlobalState.connection.getBatteryVoltage();
|
||||
GlobalState.batteryPercentage = Utils.getBatteryPercentage(response.batteryMilliVolts);
|
||||
} catch(e) {
|
||||
// ignore error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static async setAdvertName(name) {
|
||||
await GlobalState.connection.setAdvertName(name);
|
||||
}
|
||||
@@ -270,6 +288,10 @@ class Connection {
|
||||
await GlobalState.connection.reboot();
|
||||
}
|
||||
|
||||
static async getBatteryVoltage() {
|
||||
return await GlobalState.connection.getBatteryVoltage();
|
||||
}
|
||||
|
||||
static async onContactMessageReceived(message) {
|
||||
|
||||
console.log("onContactMessageReceived", message);
|
||||
|
||||
Reference in New Issue
Block a user