Move psState to the Window for global access
This commit is contained in:
parent
26f89e52b8
commit
1117af20e9
@ -37,8 +37,8 @@ const config = {
|
||||
};
|
||||
|
||||
// Create a new state and communicator
|
||||
const psState = new State(config);
|
||||
const comms = new Communicator(psState);
|
||||
window.psState = new State(config);
|
||||
const comms = new Communicator(window.psState);
|
||||
|
||||
// Grab elements from the DOM
|
||||
const setFeedRateButton = document.getElementById("set-feed-rate");
|
||||
@ -81,8 +81,8 @@ export function refreshState(doc, state) {
|
||||
}
|
||||
|
||||
export function togglePower(element) {
|
||||
psState[element].power(comms);
|
||||
refreshState(window.document, psState);
|
||||
window.psState[element].power(comms);
|
||||
refreshState(window.document, window.psState);
|
||||
}
|
||||
|
||||
export function startup() {
|
||||
@ -95,13 +95,13 @@ export function shutdown() {
|
||||
|
||||
// Run stuff once the page loads
|
||||
window.onload = function() {
|
||||
comms.init(psState, config);
|
||||
refreshState(window.document, psState);
|
||||
comms.init(window.psState, config);
|
||||
refreshState(window.document, window.psState);
|
||||
};
|
||||
|
||||
setFeedRateButton.addEventListener("click", function() {
|
||||
const feedRate = document.getElementById("feed-rate").value;
|
||||
psState.auger.feedRate = feedRate;
|
||||
comms.send(config.mqtt.topics.auger, JSON.stringify(psState.auger));
|
||||
refreshState(window.document, psState);
|
||||
window.psState.auger.feedRate = feedRate;
|
||||
comms.send(config.mqtt.topics.auger, JSON.stringify(window.psState.auger));
|
||||
refreshState(window.document, window.psState);
|
||||
});
|
Loading…
Reference in New Issue
Block a user