2025-06-14 00:40:47 +02:00

45 lines
1.9 KiB
TypeScript

import { Controller } from "./main";
import {BatteryBoardVersion, BoardHardware, BoardVersion} from "./api";
export class HardwareConfigView {
private readonly hardware_board_value: HTMLSelectElement;
private readonly hardware_battery_value: HTMLSelectElement;
constructor(controller:Controller){
(document.getElementById("hardwareview") as HTMLElement).innerHTML = require('./hardware.html') as string;
this.hardware_board_value = document.getElementById("hardware_board_value") as HTMLSelectElement;
this.hardware_board_value.onchange = controller.configChanged
Object.keys(BoardVersion).forEach(version => {
let option = document.createElement("option");
if (version == BoardVersion.INITIAL.toString()){
option.selected = true
}
option.innerText = version.toString();
this.hardware_board_value.appendChild(option);
})
this.hardware_battery_value = document.getElementById("hardware_battery_value") as HTMLSelectElement;
this.hardware_battery_value.onchange = controller.configChanged
Object.keys(BatteryBoardVersion).forEach(version => {
let option = document.createElement("option");
if (version == BatteryBoardVersion.Disabled.toString()){
option.selected = true
}
option.innerText = version.toString();
this.hardware_battery_value.appendChild(option);
})
}
setConfig(hardware: BoardHardware) {
this.hardware_board_value.value = hardware.board.toString()
this.hardware_battery_value.value = hardware.battery.toString()
}
getConfig(): BoardHardware {
return {
board : BoardVersion[this.hardware_board_value.value as keyof typeof BoardVersion],
battery : BatteryBoardVersion[this.hardware_battery_value.value as keyof typeof BatteryBoardVersion],
}
}
}