Move psState to the Window for global access

This commit is contained in:
Skylar Grant 2024-12-07 14:51:54 -05:00
parent 26f89e52b8
commit 1117af20e9

View File

@ -37,8 +37,8 @@ const config = {
}; };
// Create a new state and communicator // Create a new state and communicator
const psState = new State(config); window.psState = new State(config);
const comms = new Communicator(psState); const comms = new Communicator(window.psState);
// Grab elements from the DOM // Grab elements from the DOM
const setFeedRateButton = document.getElementById("set-feed-rate"); const setFeedRateButton = document.getElementById("set-feed-rate");
@ -81,8 +81,8 @@ export function refreshState(doc, state) {
} }
export function togglePower(element) { export function togglePower(element) {
psState[element].power(comms); window.psState[element].power(comms);
refreshState(window.document, psState); refreshState(window.document, window.psState);
} }
export function startup() { export function startup() {
@ -95,13 +95,13 @@ export function shutdown() {
// Run stuff once the page loads // Run stuff once the page loads
window.onload = function() { window.onload = function() {
comms.init(psState, config); comms.init(window.psState, config);
refreshState(window.document, psState); refreshState(window.document, window.psState);
}; };
setFeedRateButton.addEventListener("click", function() { setFeedRateButton.addEventListener("click", function() {
const feedRate = document.getElementById("feed-rate").value; const feedRate = document.getElementById("feed-rate").value;
psState.auger.feedRate = feedRate; window.psState.auger.feedRate = feedRate;
comms.send(config.mqtt.topics.auger, JSON.stringify(psState.auger)); comms.send(config.mqtt.topics.auger, JSON.stringify(window.psState.auger));
refreshState(window.document, psState); refreshState(window.document, window.psState);
}); });