sensor sweep tester
This commit is contained in:
@@ -173,6 +173,15 @@ export interface BatteryState {
|
||||
state_of_health: string
|
||||
}
|
||||
|
||||
export interface DetectionPlant {
|
||||
a: boolean,
|
||||
b: boolean
|
||||
}
|
||||
|
||||
export interface DetectionResult {
|
||||
plants: DetectionPlant[]
|
||||
}
|
||||
|
||||
export interface TankInfo {
|
||||
/// is there enough water in the tank
|
||||
enough_water: boolean,
|
||||
|
@@ -163,6 +163,7 @@
|
||||
|
||||
<h3>Plants:</h3>
|
||||
<button id="measure_moisture">Measure Moisture</button>
|
||||
<button id="detect_sensors" style="display:none">Detect/Test Sensors</button>
|
||||
<div id="plants" class="plantlist"></div>
|
||||
|
||||
<div class="flexcontainer-rev">
|
||||
|
@@ -358,6 +358,36 @@ export class Controller {
|
||||
)
|
||||
}
|
||||
|
||||
async detectSensors() {
|
||||
let counter = 0
|
||||
let limit = 5
|
||||
controller.progressview.addProgress("detect_sensors", counter / limit * 100, "Detecting sensors " + (limit - counter) + "s")
|
||||
|
||||
let timerId: string | number | NodeJS.Timeout | undefined
|
||||
|
||||
function updateProgress() {
|
||||
counter++;
|
||||
controller.progressview.addProgress("detect_sensors", counter / limit * 100, "Detecting sensors " + (limit - counter) + "s")
|
||||
timerId = setTimeout(updateProgress, 1000);
|
||||
}
|
||||
|
||||
timerId = setTimeout(updateProgress, 1000);
|
||||
|
||||
fetch(PUBLIC_URL + "/detect_sensors", { method: "POST" })
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
clearTimeout(timerId);
|
||||
controller.progressview.removeProgress("detect_sensors");
|
||||
const pretty = JSON.stringify(json);
|
||||
toast.info("Detection result: " + pretty);
|
||||
})
|
||||
.catch(error => {
|
||||
clearTimeout(timerId);
|
||||
controller.progressview.removeProgress("detect_sensors");
|
||||
toast.error("Autodetect failed: " + error);
|
||||
});
|
||||
}
|
||||
|
||||
getConfig(): PlantControllerConfig {
|
||||
return {
|
||||
hardware: controller.hardwareView.getConfig(),
|
||||
@@ -405,6 +435,12 @@ export class Controller {
|
||||
}
|
||||
|
||||
setConfig(current: PlantControllerConfig) {
|
||||
// Show Detect/Test button only for V4 HAL
|
||||
if (current.hardware && (current.hardware as any).board === "V4") {
|
||||
this.detectBtn.style.display = "inline-block";
|
||||
} else {
|
||||
this.detectBtn.style.display = "none";
|
||||
}
|
||||
this.tankView.setConfig(current.tank);
|
||||
this.networkView.setConfig(current.network);
|
||||
this.nightLampView.setConfig(current.night_lamp);
|
||||
@@ -500,6 +536,7 @@ export class Controller {
|
||||
readonly solarView: SolarView;
|
||||
readonly fileview: FileView;
|
||||
readonly logView: LogView
|
||||
readonly detectBtn: HTMLButtonElement
|
||||
|
||||
constructor() {
|
||||
this.timeView = new TimeView(this)
|
||||
@@ -515,6 +552,8 @@ export class Controller {
|
||||
this.fileview = new FileView(this)
|
||||
this.logView = new LogView(this)
|
||||
this.hardwareView = new HardwareConfigView(this)
|
||||
this.detectBtn = document.getElementById("detect_sensors") as HTMLButtonElement
|
||||
this.detectBtn.onclick = () => { controller.detectSensors(); }
|
||||
this.rebootBtn = document.getElementById("reboot") as HTMLButtonElement
|
||||
this.rebootBtn.onclick = () => {
|
||||
controller.reboot();
|
||||
|
Reference in New Issue
Block a user