i2c working, rtc working, eeprom working

This commit is contained in:
2025-09-22 23:44:33 +02:00
parent 1791f463b7
commit 5b0e2b6797
9 changed files with 523 additions and 407 deletions

View File

@@ -69,45 +69,44 @@ export class Controller {
});
}
getBackupInfo(): Promise<void> {
return fetch(PUBLIC_URL + "/backup_info")
.then(response => response.json())
.then(json => json as BackupHeader)
.then(header => {
controller.submitView.setBackupInfo(header)
})
.catch(error => {
console.log(error);
});
async getBackupInfo(): Promise<void> {
try {
const response = await fetch(PUBLIC_URL + "/backup_info");
const json = await response.json();
const header = json as BackupHeader;
controller.submitView.setBackupInfo(header);
} catch (error) {
console.log(error);
}
}
populateTimezones(): Promise<void> {
return fetch(PUBLIC_URL + '/timezones')
.then(response => response.json())
.then(json => json as string[])
.then(timezones => {
controller.timeView.timezones(timezones)
})
.catch(error => console.error('Error fetching timezones:', error));
async populateTimezones(): Promise<void> {
try {
const response = await fetch(PUBLIC_URL + '/timezones');
const json = await response.json();
const timezones = json as string[];
controller.timeView.timezones(timezones);
} catch (error) {
return console.error('Error fetching timezones:', error);
}
}
updateFileList(): Promise<void> {
return fetch(PUBLIC_URL + "/files")
.then(response => response.json())
.then(json => json as FileList)
.then(filelist => {
controller.fileview.setFileList(filelist, PUBLIC_URL)
})
.catch(error => {
console.log(error);
});
async updateFileList(): Promise<void> {
try {
const response = await fetch(PUBLIC_URL + "/files");
const json = await response.json();
const filelist = json as FileList;
controller.fileview.setFileList(filelist, PUBLIC_URL);
} catch (error) {
console.log(error);
}
}
uploadFile(file: File, name: string) {
var current = 0;
var max = 100;
let current = 0;
let max = 100;
controller.progressview.addProgress("file_upload", (current / max) * 100, "Uploading File " + name + "(" + current + "/" + max + ")")
var ajax = new XMLHttpRequest();
const ajax = new XMLHttpRequest();
ajax.upload.addEventListener("progress", event => {
current = event.loaded / 1000;
max = event.total / 1000;
@@ -133,7 +132,7 @@ export class Controller {
deleteFile(name: string) {
controller.progressview.addIndeterminate("file_delete", "Deleting " + name);
var ajax = new XMLHttpRequest();
const ajax = new XMLHttpRequest();
ajax.open("DELETE", PUBLIC_URL + "/file?filename=" + name);
ajax.send();
ajax.addEventListener("error", () => {
@@ -153,50 +152,47 @@ export class Controller {
controller.updateFileList()
}
updateRTCData(): Promise<void> {
return fetch(PUBLIC_URL + "/time")
.then(response => response.json())
.then(json => json as GetTime)
.then(time => {
controller.timeView.update(time.native, time.rtc)
})
.catch(error => {
controller.timeView.update("n/a", "n/a")
console.log(error);
});
async updateRTCData(): Promise<void> {
try {
const response = await fetch(PUBLIC_URL + "/time");
const json = await response.json();
const time = json as GetTime;
controller.timeView.update(time.native, time.rtc);
} catch (error) {
controller.timeView.update("n/a", "n/a");
console.log(error);
}
}
updateBatteryData(): Promise<void> {
return fetch(PUBLIC_URL + "/battery")
.then(response => response.json())
.then(json => json as BatteryState)
.then(battery => {
controller.batteryView.update(battery)
})
.catch(error => {
controller.batteryView.update(null)
console.log(error);
})
async updateBatteryData(): Promise<void> {
try {
const response = await fetch(PUBLIC_URL + "/battery");
const json = await response.json();
const battery = json as BatteryState;
controller.batteryView.update(battery);
} catch (error) {
controller.batteryView.update(null);
console.log(error);
}
}
updateSolarData(): Promise<void> {
return fetch(PUBLIC_URL + "/solar")
.then(response => response.json())
.then(json => json as SolarState)
.then(solar => {
controller.solarView.update(solar)
})
.catch(error => {
controller.solarView.update(null)
console.log(error);
})
async updateSolarData(): Promise<void> {
try {
const response = await fetch(PUBLIC_URL + "/solar");
const json = await response.json();
const solar = json as SolarState;
controller.solarView.update(solar);
} catch (error) {
controller.solarView.update(null);
console.log(error);
}
}
uploadNewFirmware(file: File) {
var current = 0;
var max = 100;
let current = 0;
let max = 100;
controller.progressview.addProgress("ota_upload", (current / max) * 100, "Uploading firmeware (" + current + "/" + max + ")")
var ajax = new XMLHttpRequest();
const ajax = new XMLHttpRequest();
ajax.upload.addEventListener("progress", event => {
current = event.loaded / 1000;
max = event.total / 1000;
@@ -218,15 +214,13 @@ export class Controller {
ajax.send(file);
}
version(): Promise<void> {
async version(): Promise<void> {
controller.progressview.addIndeterminate("version", "Getting buildVersion")
return fetch(PUBLIC_URL + "/version")
.then(response => response.json())
.then(json => json as VersionInfo)
.then(versionInfo => {
controller.progressview.removeProgress("version")
controller.firmWareView.setVersion(versionInfo);
})
const response = await fetch(PUBLIC_URL + "/version");
const json = await response.json();
const versionInfo = json as VersionInfo;
controller.progressview.removeProgress("version");
controller.firmWareView.setVersion(versionInfo);
}
getBackupConfig() {
@@ -243,7 +237,7 @@ export class Controller {
controller.progressview.addIndeterminate("get_config", "Downloading Config")
const response = await fetch(PUBLIC_URL + "/get_config");
const loaded = await response.json();
var currentConfig = loaded as PlantControllerConfig;
const currentConfig = loaded as PlantControllerConfig;
controller.setInitialConfig(currentConfig);
controller.setConfig(currentConfig);
//sync json view initially
@@ -268,12 +262,12 @@ export class Controller {
controller.downloadConfig()
}
backupConfig(json: string): Promise<string> {
return fetch(PUBLIC_URL + "/backup_config", {
async backupConfig(json: string): Promise<string> {
const response = await fetch(PUBLIC_URL + "/backup_config", {
method: "POST",
body: json,
})
.then(response => response.text());
});
return await response.text();
}
syncRTCFromBrowser() {
@@ -310,9 +304,9 @@ export class Controller {
}
testNightLamp(active: boolean) {
var body: NightLampCommand = {
const body: NightLampCommand = {
active: active
}
};
var pretty = JSON.stringify(body, undefined, 1);
fetch(PUBLIC_URL + "/lamptest", {
method: "POST",