diff --git a/Cargo.lock b/Cargo.lock
index c7dbdd4..423c60e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2633,7 +2633,7 @@ dependencies = [
[[package]]
name = "tesla-charge-controller"
-version = "1.0.29"
+version = "1.0.30"
dependencies = [
"chrono",
"clap 4.4.11",
diff --git a/Cargo.toml b/Cargo.toml
index 6645351..21cc1e3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "tesla-charge-controller"
-version = "1.0.29"
+version = "1.0.30"
edition = "2021"
license = "MITNFA"
description = "Controls Tesla charge rate based on solar charge data"
diff --git a/src/server/mod.rs b/src/server/mod.rs
index 34b8e94..e8dfaad 100644
--- a/src/server/mod.rs
+++ b/src/server/mod.rs
@@ -62,6 +62,9 @@ fn rocket(state: ServerState) -> rocket::Rocket
diff --git a/webapp/script.js b/webapp/script.js index e431f4a..14da470 100644 --- a/webapp/script.js +++ b/webapp/script.js @@ -40,6 +40,15 @@ function init_pid() { }); } +function init_shutoff() { + refresh_shutoff(); + document.addEventListener("visibilitychange", () => { + if (!document.hidden) { + refresh_shutoff(); + } + }); +} + function init_info() { refresh_interval = register(refresh_info); @@ -138,6 +147,34 @@ function set_derivative() { } } +function set_shutoff_voltage() { + var set_button = document.getElementById("set-shutoff-voltage"); + var number_input = document.getElementById("shutoff-voltage"); + if (!isNaN(number_input.value)) { + set_button.disabled = true; + number_input.disabled = true; + fetch(api_url + "/shutoff/voltage/" + number_input.value, { method: "POST" }) + .then(async (response) => { + let delayres = await delay(100); + refresh_shutoff(); + }); + } +} + +function set_shutoff_time() { + var set_button = document.getElementById("set-shutoff-time"); + var number_input = document.getElementById("shutoff-time"); + if (!isNaN(number_input.value)) { + set_button.disabled = true; + number_input.disabled = true; + fetch(api_url + "/shutoff/time/" + number_input.value, { method: "POST" }) + .then(async (response) => { + let delayres = await delay(100); + refresh_shutoff(); + }); + } +} + function set_load_divisor() { var set_button = document.getElementById("set-load-divisor"); var number_input = document.getElementById("load-divisor"); @@ -159,7 +196,7 @@ function disable_automatic_control() { fetch(api_url + "/disable-control", { method: "POST" }) .then(async (response) => { - let delayres = await delay(1000); + let delayres = await delay(100); refresh_buttons(); }); } @@ -171,7 +208,7 @@ function enable_automatic_control() { document.body.classList.add("loading"); fetch(api_url + "/enable-control", { method: "POST" }) .then(async (response) => { - let delayres = await delay(1000); + let delayres = await delay(100); refresh_buttons(); }); } @@ -242,6 +279,25 @@ function update_gains(data) { load_divisor_input.value = data.load_divisor; } +function refresh_shutoff() { + fetch(api_url + "/shutoff/status") + .then((response) => response.json()) + .then((json) => update_shutoff(json)); +} + +function update_shutoff(data) { + var voltage_set_button = document.getElementById("set-shutoff-voltage"); + var voltage_number_input = document.getElementById("shutoff-voltage"); + voltage_set_button.disabled = false; + voltage_number_input.disabled = false; + voltage_number_input.value = data.voltage; + var time_set_button = document.getElementById("set-shutoff-time"); + var time_number_input = document.getElementById("shutoff-time"); + time_set_button.disabled = false; + time_number_input.disabled = false; + time_number_input.value = data.time; +} + function refresh_buttons() { fetch(api_url + "/control-state") .then((response) => response.json()) diff --git a/webapp/shutoff/index.html b/webapp/shutoff/index.html new file mode 100644 index 0000000..cb17d1c --- /dev/null +++ b/webapp/shutoff/index.html @@ -0,0 +1,29 @@ + + + +
+ +
+ + + + + +
+ +