2024-10-20 03:27:14 +03:00
|
|
|
import { getScene, SCENE_AOD } from '@zos/app'
|
2024-10-20 02:54:13 +03:00
|
|
|
import * as hmSensor from '@zos/sensor'
|
|
|
|
import * as hmUI from '@zos/ui'
|
|
|
|
import fontArray from '../fontData/secondaryFont'
|
|
|
|
|
|
|
|
let batteryWg;
|
2024-10-20 03:08:32 +03:00
|
|
|
const moduleX = 310
|
|
|
|
const moduleY = 10
|
2024-10-20 03:27:14 +03:00
|
|
|
export default function () {
|
|
|
|
console.log("[modules]: battery module init")
|
|
|
|
let battery = new hmSensor.Battery()
|
|
|
|
updateBatteryWidget(battery.getCurrent())
|
|
|
|
battery.onChange(() => updateBatteryWidget(battery.getCurrent()))
|
|
|
|
if (getScene() != SCENE_AOD)
|
2024-10-20 02:54:13 +03:00
|
|
|
hmUI.createWidget(hmUI.widget.IMG, {
|
2024-10-20 03:27:14 +03:00
|
|
|
x: moduleX,
|
|
|
|
y: moduleY,
|
|
|
|
src: 'date/perc.PNG'
|
|
|
|
})
|
2024-10-20 02:54:13 +03:00
|
|
|
}
|
2024-10-20 03:27:14 +03:00
|
|
|
function updateBatteryWidget(batteryPercentage) {
|
|
|
|
if (batteryWg)
|
|
|
|
hmUI.deleteWidget(batteryWg)
|
|
|
|
|
|
|
|
if (getScene() != SCENE_AOD) {
|
|
|
|
batteryWg = hmUI.createWidget(hmUI.widget.TEXT_IMG, {
|
|
|
|
x: moduleX - 85,
|
|
|
|
y: moduleY,
|
|
|
|
type: hmUI.data_type.BATTERY,
|
|
|
|
font_array: fontArray,
|
|
|
|
h_space: 1,
|
|
|
|
align_h: hmUI.align.RIGHT,
|
|
|
|
text: batteryPercentage
|
|
|
|
})
|
|
|
|
}
|
2024-10-20 02:54:13 +03:00
|
|
|
}
|