v4 board impl
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
interface LogArray extends Array<LogEntry>{}
|
||||
export interface LogArray extends Array<LogEntry>{}
|
||||
|
||||
interface LogEntry {
|
||||
export interface LogEntry {
|
||||
timestamp: string,
|
||||
message_id: number,
|
||||
a: number,
|
||||
@@ -9,27 +9,28 @@ interface LogEntry {
|
||||
txt_long: string
|
||||
}
|
||||
|
||||
interface LogLocalisation extends Array<LogLocalisationEntry>{}
|
||||
export interface LogLocalisation extends Array<LogLocalisationEntry>{}
|
||||
|
||||
interface LogLocalisationEntry {
|
||||
export interface LogLocalisationEntry {
|
||||
msg_type: string,
|
||||
message: string
|
||||
}
|
||||
|
||||
interface BackupHeader {
|
||||
export interface BackupHeader {
|
||||
timestamp: string,
|
||||
size: number
|
||||
}
|
||||
|
||||
interface NetworkConfig {
|
||||
export interface NetworkConfig {
|
||||
ap_ssid: string,
|
||||
ssid: string,
|
||||
password: string,
|
||||
mqtt_url: string,
|
||||
base_topic: string
|
||||
base_topic: string,
|
||||
max_wait: number
|
||||
}
|
||||
|
||||
interface FileList {
|
||||
export interface FileList {
|
||||
total: number,
|
||||
used: number,
|
||||
files: FileInfo[],
|
||||
@@ -37,12 +38,12 @@ interface FileList {
|
||||
iter_error: string,
|
||||
}
|
||||
|
||||
interface FileInfo{
|
||||
export interface FileInfo{
|
||||
filename: string,
|
||||
size: number,
|
||||
}
|
||||
|
||||
interface NightLampConfig {
|
||||
export interface NightLampConfig {
|
||||
enabled: boolean,
|
||||
night_lamp_hour_start: number,
|
||||
night_lamp_hour_end: number,
|
||||
@@ -51,11 +52,11 @@ interface NightLampConfig {
|
||||
low_soc_restore: number
|
||||
}
|
||||
|
||||
interface NightLampCommand {
|
||||
export interface NightLampCommand {
|
||||
active: boolean
|
||||
}
|
||||
|
||||
interface TankConfig {
|
||||
export interface TankConfig {
|
||||
tank_sensor_enabled: boolean,
|
||||
tank_allow_pumping_if_sensor_error: boolean,
|
||||
tank_useable_ml: number,
|
||||
@@ -64,7 +65,26 @@ interface TankConfig {
|
||||
tank_full_percent: number,
|
||||
}
|
||||
|
||||
interface PlantControllerConfig {
|
||||
|
||||
export enum BatteryBoardVersion {
|
||||
Disabled = "Disabled",
|
||||
BQ34Z100G1 = "BQ34Z100G1",
|
||||
WchI2cSlave = "WchI2cSlave"
|
||||
}
|
||||
export enum BoardVersion{
|
||||
INITIAL = "INITIAL",
|
||||
V3 = "V3",
|
||||
V4 = "V4"
|
||||
}
|
||||
|
||||
export interface BoardHardware {
|
||||
board: BoardVersion,
|
||||
battery: BatteryBoardVersion,
|
||||
}
|
||||
|
||||
export interface PlantControllerConfig {
|
||||
hardware: BoardHardware,
|
||||
|
||||
network: NetworkConfig,
|
||||
tank: TankConfig,
|
||||
night_lamp: NightLampConfig,
|
||||
@@ -72,7 +92,7 @@ interface PlantControllerConfig {
|
||||
timezone?: string,
|
||||
}
|
||||
|
||||
interface PlantConfig {
|
||||
export interface PlantConfig {
|
||||
mode: string,
|
||||
target_moisture: number,
|
||||
pump_time_s: number,
|
||||
@@ -88,35 +108,35 @@ interface PlantConfig {
|
||||
}
|
||||
|
||||
|
||||
interface SSIDList {
|
||||
export interface SSIDList {
|
||||
ssids: [string]
|
||||
}
|
||||
|
||||
interface TestPump {
|
||||
export interface TestPump {
|
||||
pump: number
|
||||
}
|
||||
|
||||
interface SetTime {
|
||||
export interface SetTime {
|
||||
time: string
|
||||
}
|
||||
|
||||
interface GetTime {
|
||||
export interface GetTime {
|
||||
rtc: string,
|
||||
native: string
|
||||
}
|
||||
|
||||
interface Moistures {
|
||||
export interface Moistures {
|
||||
moisture_a: [string],
|
||||
moisture_b: [string],
|
||||
}
|
||||
|
||||
interface VersionInfo {
|
||||
export interface VersionInfo {
|
||||
git_hash: string,
|
||||
build_time: string,
|
||||
partition: string
|
||||
}
|
||||
|
||||
interface BatteryState {
|
||||
export interface BatteryState {
|
||||
temperature: string
|
||||
voltage_milli_volt: string,
|
||||
current_milli_ampere: string,
|
||||
@@ -127,7 +147,7 @@ interface BatteryState {
|
||||
state_of_health: string
|
||||
}
|
||||
|
||||
interface TankInfo {
|
||||
export interface TankInfo {
|
||||
/// is there enough water in the tank
|
||||
enough_water: boolean,
|
||||
/// warning that water needs to be refilled soon
|
||||
@@ -145,4 +165,4 @@ interface TankInfo {
|
||||
/// water temperature
|
||||
water_temp: number | null,
|
||||
temp_sensor_error: string | null
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import { Controller } from "./main";
|
||||
import {BatteryState} from "./api";
|
||||
|
||||
export class BatteryView{
|
||||
voltage_milli_volt: HTMLSpanElement;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import {Controller} from "./main";
|
||||
|
||||
import {FileInfo, FileList} from "./api";
|
||||
const regex = /[^a-zA-Z0-9_.]/g;
|
||||
|
||||
function sanitize(str:string){
|
||||
|
20
rust/src_webpack/src/hardware.html
Normal file
20
rust/src_webpack/src/hardware.html
Normal file
@@ -0,0 +1,20 @@
|
||||
<style>
|
||||
.boardkey{
|
||||
min-width: 200px;
|
||||
}
|
||||
.boardvalue{
|
||||
flex-grow: 1;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="subtitle">Hardware:</div>
|
||||
<div class="flexcontainer">
|
||||
<div class="boardkey">BoardRevision</div>
|
||||
<select class="boardvalue" id="hardware_board_value">
|
||||
</select>
|
||||
</div>
|
||||
<div class="flexcontainer" style="text-decoration-line: line-through;">
|
||||
<div class="boardkey">BatteryMonitor</div>
|
||||
<select class="boardvalue" id="hardware_battery_value">
|
||||
</select>
|
||||
</div>
|
45
rust/src_webpack/src/hardware.ts
Normal file
45
rust/src_webpack/src/hardware.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
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],
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
import { Controller } from "./main";
|
||||
import {LogArray, LogLocalisation} from "./api";
|
||||
|
||||
export class LogView {
|
||||
private readonly logpanel: HTMLElement;
|
||||
|
@@ -138,6 +138,10 @@
|
||||
|
||||
|
||||
<div class="container-xl">
|
||||
<div style="display:flex; flex-wrap: wrap;">
|
||||
<div id="hardwareview" class="subcontainer"></div>
|
||||
</div>
|
||||
|
||||
<div style="display:flex; flex-wrap: wrap;">
|
||||
<div id="firmwareview" class="subcontainer">
|
||||
</div>
|
||||
|
@@ -17,6 +17,19 @@ import { OTAView } from "./ota";
|
||||
import { BatteryView } from "./batteryview";
|
||||
import { FileView } from './fileview';
|
||||
import { LogView } from './log';
|
||||
import {HardwareConfigView} from "./hardware";
|
||||
import {
|
||||
BackupHeader,
|
||||
BatteryState,
|
||||
GetTime, LogArray, LogLocalisation,
|
||||
Moistures,
|
||||
NightLampCommand,
|
||||
PlantControllerConfig,
|
||||
SetTime, SSIDList, TankInfo,
|
||||
TestPump,
|
||||
VersionInfo,
|
||||
FileList
|
||||
} from "./api";
|
||||
|
||||
export class Controller {
|
||||
loadTankInfo() : Promise<void> {
|
||||
@@ -66,7 +79,7 @@ export class Controller {
|
||||
}
|
||||
|
||||
populateTimezones(): Promise<void> {
|
||||
return fetch('/timezones')
|
||||
return fetch(PUBLIC_URL+'/timezones')
|
||||
.then(response => response.json())
|
||||
.then(json => json as string[])
|
||||
.then(timezones => {
|
||||
@@ -268,6 +281,12 @@ export class Controller {
|
||||
}
|
||||
}
|
||||
|
||||
selfTest(){
|
||||
fetch(PUBLIC_URL + "/boardtest", {
|
||||
method: "POST"
|
||||
})
|
||||
}
|
||||
|
||||
testNightLamp(active: boolean){
|
||||
var body: NightLampCommand = {
|
||||
active: active
|
||||
@@ -313,6 +332,7 @@ export class Controller {
|
||||
|
||||
getConfig(): PlantControllerConfig {
|
||||
return {
|
||||
hardware: controller.hardwareView.getConfig(),
|
||||
network: controller.networkView.getConfig(),
|
||||
tank: controller.tankView.getConfig(),
|
||||
night_lamp: controller.nightLampView.getConfig(),
|
||||
@@ -360,6 +380,7 @@ export class Controller {
|
||||
this.nightLampView.setConfig(current.night_lamp);
|
||||
this.plantViews.setConfig(current.plants);
|
||||
this.timeView.setTimeZone(current.timezone);
|
||||
this.hardwareView.setConfig(current.hardware);
|
||||
}
|
||||
|
||||
measure_moisture() {
|
||||
@@ -437,6 +458,7 @@ export class Controller {
|
||||
readonly timeView: TimeView;
|
||||
readonly plantViews: PlantViews;
|
||||
readonly networkView: NetworkConfigView;
|
||||
readonly hardwareView: HardwareConfigView;
|
||||
readonly tankView: TankConfigView;
|
||||
readonly nightLampView: NightLampView;
|
||||
readonly submitView: SubmitView;
|
||||
@@ -457,6 +479,7 @@ export class Controller {
|
||||
this.progressview = new ProgressView(this)
|
||||
this.fileview = new FileView(this)
|
||||
this.logView = new LogView(this)
|
||||
this.hardwareView = new HardwareConfigView(this)
|
||||
this.rebootBtn = document.getElementById("reboot") as HTMLButtonElement
|
||||
this.rebootBtn.onclick = () => {
|
||||
controller.reboot();
|
||||
@@ -466,6 +489,10 @@ export class Controller {
|
||||
controller.exit();
|
||||
}
|
||||
}
|
||||
|
||||
selftest() {
|
||||
|
||||
}
|
||||
}
|
||||
const controller = new Controller();
|
||||
controller.progressview.removeProgress("rebooting");
|
||||
@@ -505,9 +532,6 @@ executeTasksSequentially().then(r => {
|
||||
controller.progressview.removeProgress("initial")
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
controller.progressview.removeProgress("rebooting");
|
||||
|
||||
window.addEventListener("beforeunload", (event) => {
|
||||
|
@@ -42,6 +42,11 @@
|
||||
</datalist>
|
||||
<input class="basicnetworkkeyssid2" type="button" id="scan" value="Scan">
|
||||
</div>
|
||||
|
||||
<div class="flexcontainer">
|
||||
<label class="basicnetworkkey" for="max_wait">Max wait:</label>
|
||||
<input class="basicnetworkvalue" type="number" id="max_wait">
|
||||
</div>
|
||||
|
||||
<div class="flexcontainer">
|
||||
<label class="basicnetworkkey" for="ssid">Password:</label>
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import { Controller } from "./main";
|
||||
import {NetworkConfig, SSIDList} from "./api";
|
||||
|
||||
export class NetworkConfigView {
|
||||
setScanResult(ssidList: SSIDList) {
|
||||
@@ -14,6 +15,7 @@ export class NetworkConfigView {
|
||||
private readonly password: HTMLInputElement;
|
||||
private readonly mqtt_url: HTMLInputElement;
|
||||
private readonly base_topic: HTMLInputElement;
|
||||
private readonly max_wait: HTMLInputElement;
|
||||
private readonly ssidlist: HTMLElement;
|
||||
|
||||
constructor(controller: Controller, publicIp: string) {
|
||||
@@ -28,6 +30,9 @@ export class NetworkConfigView {
|
||||
this.ssid.onchange = controller.configChanged
|
||||
this.password = (document.getElementById("password") as HTMLInputElement);
|
||||
this.password.onchange = controller.configChanged
|
||||
this.max_wait = (document.getElementById("max_wait") as HTMLInputElement);
|
||||
this.max_wait.onchange = controller.configChanged
|
||||
|
||||
this.mqtt_url = document.getElementById("mqtt_url") as HTMLInputElement;
|
||||
this.mqtt_url.onchange = controller.configChanged
|
||||
this.base_topic = document.getElementById("base_topic") as HTMLInputElement;
|
||||
@@ -47,10 +52,12 @@ export class NetworkConfigView {
|
||||
this.password.value = network.password;
|
||||
this.mqtt_url.value = network.mqtt_url;
|
||||
this.base_topic.value = network.base_topic;
|
||||
this.max_wait.value = network.max_wait.toString();
|
||||
}
|
||||
|
||||
getConfig(): NetworkConfig {
|
||||
return {
|
||||
max_wait: +this.max_wait.value,
|
||||
ap_ssid: this.ap_ssid.value,
|
||||
ssid: this.ssid.value ?? null,
|
||||
password: this.password.value ?? null,
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import { Controller } from "./main";
|
||||
import {NightLampConfig} from "./api";
|
||||
|
||||
export class NightLampView {
|
||||
private readonly night_lamp_only_when_dark: HTMLInputElement;
|
||||
|
@@ -37,5 +37,5 @@
|
||||
</form>
|
||||
</div>
|
||||
<div class="display:flex">
|
||||
<input style="margin-left: 16px; margin-top: 8px;" class="col-6" type="button" id="test" value="Self-Test">
|
||||
<button style="margin-left: 16px; margin-top: 8px;" class="col-6" type="button" id="test">Self-Test</button>
|
||||
</div>
|
@@ -1,4 +1,5 @@
|
||||
import { Controller } from "./main";
|
||||
import {VersionInfo} from "./api";
|
||||
|
||||
export class OTAView {
|
||||
readonly file1Upload: HTMLInputElement;
|
||||
@@ -9,6 +10,8 @@ export class OTAView {
|
||||
constructor(controller: Controller) {
|
||||
(document.getElementById("firmwareview") as HTMLElement).innerHTML = require("./ota.html")
|
||||
|
||||
let test = document.getElementById("test") as HTMLButtonElement;
|
||||
|
||||
this.firmware_buildtime = document.getElementById("firmware_buildtime") as HTMLDivElement;
|
||||
this.firmware_githash = document.getElementById("firmware_githash") as HTMLDivElement;
|
||||
this.firmware_partition = document.getElementById("firmware_partition") as HTMLDivElement;
|
||||
@@ -24,6 +27,10 @@ export class OTAView {
|
||||
}
|
||||
controller.uploadNewFirmware(selectedFile);
|
||||
};
|
||||
|
||||
test.onclick = () => {
|
||||
controller.selftest();
|
||||
}
|
||||
}
|
||||
|
||||
setVersion(versionInfo: VersionInfo) {
|
||||
|
@@ -1,3 +1,5 @@
|
||||
import {PlantConfig} from "./api";
|
||||
|
||||
const PLANT_COUNT = 8;
|
||||
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import { Controller } from "./main";
|
||||
import {BackupHeader} from "./api";
|
||||
|
||||
export class SubmitView {
|
||||
json: HTMLDivElement;
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import { Controller } from "./main";
|
||||
import {TankConfig, TankInfo} from "./api";
|
||||
|
||||
export class TankConfigView {
|
||||
private readonly tank_useable_ml: HTMLInputElement;
|
||||
|
@@ -9,7 +9,7 @@ console.log("Dev server is " + isDevServer);
|
||||
var host;
|
||||
if (isDevServer){
|
||||
//ensure no trailing /
|
||||
host = 'http://192.168.251.37';
|
||||
host = 'http://192.168.71.1';
|
||||
} else {
|
||||
host = '';
|
||||
}
|
||||
|
Reference in New Issue
Block a user