Compare commits

..

No commits in common. "8ff2763580a831a2c641626c4c7bcd7df9e960ff" and "53bd1f8ccedd8e06454b4795ad88c62ecd881901" have entirely different histories.

7 changed files with 21 additions and 148 deletions

@ -32,7 +32,7 @@ use tank::*;
const TIME_ZONE: Tz = Berlin;
const MOIST_SENSOR_MAX_FREQUENCY: u32 = 5500; // 60kHz (500Hz margin)
const MOIST_SENSOR_MAX_FREQUENCY: u32 = 5000; // 60kHz (500Hz margin)
const MOIST_SENSOR_MIN_FREQUENCY: u32 = 150; // this is really really dry, think like cactus levels
const FROM: (f32, f32) = (

@ -188,14 +188,7 @@ fn backup_info(
};
serde_json::to_string(&wbh)?
}
Err(_) => {
//TODO make better
let wbh = WebBackupHeader {
timestamp: "no backup".to_owned(),
size: 0,
};
serde_json::to_string(&wbh)?
}
Err(_) => "{\"error\":\"Header could not be parsed\"".to_owned(),
};
anyhow::Ok(Some(json))
}

@ -1,21 +1,3 @@
interface LogArray extends Array<LogEntry>{}
interface LogEntry {
timestamp: string,
message_id: number,
a: number,
b: number,
txt_short: string,
txt_long: string
}
interface LogLocalisation extends Array<LogLocalisationEntry>{}
interface LogLocalisationEntry {
msg_type: string,
message: string
}
interface BackupHeader {
timestamp: string,
size: number

@ -1,7 +0,0 @@
<style>
</style>
<button id="loadLog">Load Logs</button>
<div id="logpanel">
</div>

@ -1,47 +0,0 @@
import { Controller } from "./main";
export class LogView {
private readonly logpanel: HTMLElement;
private readonly loadLog: HTMLButtonElement;
loglocale: LogLocalisation | undefined;
constructor(controller: Controller) {
(document.getElementById("logview") as HTMLElement).innerHTML = require('./log.html') as string;
this.logpanel = document.getElementById("logpanel") as HTMLElement
this.loadLog = document.getElementById("loadLog") as HTMLButtonElement
controller.loadLogLocaleConfig();
this.loadLog.onclick = () => {
controller.loadLog();
}
}
setLogLocalisation(loglocale: LogLocalisation) {
this.loglocale = loglocale;
}
setLog(logs: LogArray) {
this.logpanel.textContent = ""
logs.forEach(entry => {
let message = this.loglocale!![entry.message_id];
let template = message.message
template = template.replace("${number_a}", entry.a.toString());
template = template.replace("${number_b}", entry.b.toString());
template = template.replace("${txt_short}", entry.txt_short.toString());
template = template.replace("${txt_long}", entry.txt_long.toString());
let ts = new Date(entry.timestamp);
let div = document.createElement("div")
let timestampDiv = document.createElement("div")
let messageDiv = document.createElement("div")
timestampDiv.innerText = ts.toISOString();
messageDiv.innerText = template;
div.appendChild(timestampDiv)
div.appendChild(messageDiv)
this.logpanel.appendChild(div)
}
)
}
}

@ -171,10 +171,6 @@
<button id="exit">Exit</button>
<button id="reboot">Reboot</button>
<div class="flexcontainer">
<div id="logview" class="subcontainercontainer"></div>
</div>
<script src="bundle.js"></script>
</div>

@ -17,33 +17,10 @@ import { ProgressView } from "./progress";
import { OTAView } from "./ota";
import { BatteryView } from "./batteryview";
import { FileView } from './fileview';
import { LogView } from './log';
export class Controller {
loadLogLocaleConfig() {
return fetch(PUBLIC_URL + "/log_localization")
.then(response => response.json())
.then(json => json as LogLocalisation)
.then(loglocale => {
controller.logView.setLogLocalisation(loglocale)
})
.catch(error => {
console.log(error);
});
}
loadLog() {
return fetch(PUBLIC_URL + "/log")
.then(response => response.json())
.then(json => json as LogArray)
.then(logs => {
controller.logView.setLog(logs)
})
.catch(error => {
console.log(error);
});
}
getBackupInfo() : Promise<void> {
return fetch(PUBLIC_URL + "/backup_info")
getBackupInfo() {
fetch(PUBLIC_URL + "/backup_info")
.then(response => response.json())
.then(json => json as BackupHeader)
.then(header => {
@ -53,8 +30,8 @@ export class Controller {
console.log(error);
});
}
updateFileList() : Promise<void> {
return fetch(PUBLIC_URL + "/files")
updateFileList() {
fetch(PUBLIC_URL + "/files")
.then(response => response.json())
.then(json => json as FileList)
.then(filelist => {
@ -113,8 +90,8 @@ export class Controller {
controller.updateFileList()
}
updateRTCData() : Promise<void> {
return fetch(PUBLIC_URL + "/time")
updateRTCData() {
fetch(PUBLIC_URL + "/time")
.then(response => response.json())
.then(json => json as GetTime)
.then(time => {
@ -125,8 +102,8 @@ export class Controller {
console.log(error);
});
}
updateBatteryData(): Promise<void> {
return fetch(PUBLIC_URL + "/battery")
updateBatteryData() {
fetch(PUBLIC_URL + "/battery")
.then(response => response.json())
.then(json => json as BatteryState)
.then(battery => {
@ -135,7 +112,7 @@ export class Controller {
.catch(error => {
controller.batteryView.update(null)
console.log(error);
})
});
}
uploadNewFirmware(file: File) {
var current = 0;
@ -162,9 +139,9 @@ export class Controller {
ajax.open("POST", PUBLIC_URL + "/ota");
ajax.send(file);
}
version() : Promise<void> {
version() {
controller.progressview.addIndeterminate("version", "Getting buildVersion")
return fetch(PUBLIC_URL + "/version")
fetch(PUBLIC_URL + "/version")
.then(response => response.json())
.then(json => json as VersionInfo)
.then(versionInfo => {
@ -183,9 +160,9 @@ export class Controller {
})
}
downloadConfig() :Promise<void> {
downloadConfig() {
controller.progressview.addIndeterminate("get_config", "Downloading Config")
return fetch(PUBLIC_URL + "/get_config")
fetch(PUBLIC_URL + "/get_config")
.then(response => response.json())
.then(loaded => {
var currentConfig = loaded as PlantControllerConfig;
@ -422,7 +399,6 @@ export class Controller {
readonly progressview: ProgressView;
readonly batteryView: BatteryView;
readonly fileview: FileView;
readonly logView: LogView
constructor() {
this.timeView = new TimeView(this)
this.plantViews = new PlantViews(this)
@ -434,7 +410,6 @@ export class Controller {
this.firmWareView = new OTAView(this)
this.progressview = new ProgressView(this)
this.fileview = new FileView(this)
this.logView = new LogView(this)
this.rebootBtn = document.getElementById("reboot") as HTMLButtonElement
this.rebootBtn.onclick = () => {
controller.reboot();
@ -446,31 +421,12 @@ export class Controller {
}
}
const controller = new Controller();
controller.progressview.removeProgress("rebooting");
controller.progressview.addProgress("initial", 0, "read rtc");
controller.updateRTCData().then(_ => {
controller.progressview.addProgress("initial", 20, "read battery");
controller.updateBatteryData().then(_ => {
controller.progressview.addProgress("initial", 40, "read config");
controller.downloadConfig().then(_ => {
controller.progressview.addProgress("initial", 50, "read version");
controller.version().then(_ => {
controller.progressview.addProgress("initial", 70, "read filelist");
controller.updateFileList().then(_ => {
controller.progressview.addProgress("initial", 90, "read backupinfo");
controller.getBackupInfo().then(_ => {
controller.progressview.removeProgress("initial");
})
})
})
});
})
})
;
controller.updateRTCData();
controller.updateBatteryData();
controller.downloadConfig();
//controller.measure_moisture();
controller.version();
controller.updateFileList();
controller.getBackupInfo();
controller.progressview.removeProgress("rebooting");