Skip to content
Snippets Groups Projects
Commit 0ba7e125 authored by Karl-Luca's avatar Karl-Luca Committed by laurakutter
Browse files

textcontent in refresh()

parent f7cb054c
No related branches found
No related tags found
1 merge request!28Raspberry webinterface
No preview for this file type
...@@ -22,89 +22,54 @@ function sendState(state) { ...@@ -22,89 +22,54 @@ function sendState(state) {
Http.setRequestHeader('Content-Type', 'application/json'); Http.setRequestHeader('Content-Type', 'application/json');
Http.send(JSON.stringify(uiState)); Http.send(JSON.stringify(uiState));
} }
/*
// activate water pump
function setStateWaterPump() {
const Http = new XMLHttpRequest();
Http.open('POST', '././setState');
Http.setRequestHeader('Content-Type', 'application/json');
const state = { message: 'start water-pump'};
Http.send(JSON.stringify(state));
}
//activiate nutrition pump
function setStateNutritionPump() {
const Http = new XMLHttpRequest();
Http.open('POST', '././setState');
Http.setRequestHeader('Content-Type', 'application/json');
const state = { message: 'start nutrition-pump'};
Http.send(JSON.stringify(state));
}
// activate light
function setStateLightOn() {
const Http = new XMLHttpRequest();
Http.open('POST', '././setState');
Http.setRequestHeader('Content-Type', 'application/json');
const state = { message: 'activate light'};
Http.send(JSON.stringify(state));
}
//deactivate light
function setStateLightOff() {
const Http = new XMLHttpRequest();
Http.open('POST', '././setState');
Http.setRequestHeader('Content-Type', 'application/json');
const state = { message: 'deactivate light'};
Http.send(JSON.stringify(state));
}
*/
// updates elements to current state // updates elements to current state
function refresh() { function refresh() {
getState();
btn1.textContent = uiState.light_status ? 'Licht an' : 'Licht aus'; btn1.textContent = uiState.light_status ? 'Licht an' : 'Licht aus';
// btn2.textContent = btn2.textContent = uiState.water_pump_status ? 'Wasserpumpe an' : 'Wasserpumpe aus';
btn3.textContent = uiState.nutrition_pump_status ? 'Nährstoffpumpe an' : 'Nährstoffpumpe aus';
toggleSwitch.checked = uiState.light_auto_mode ? true : false; toggleSwitch.checked = uiState.light_auto_mode ? true : false;
timeSelector.style.display = uiState.light_auto_mode ? 'block' : 'none'; timeSelector.style.display = uiState.light_auto_mode ? 'block' : 'none';
} }
// event listener for buttons and interative gui elements // event listener for buttons and interative gui elements
//event listener for light // light manual
btn1.addEventListener('click', function handleClick() { btn1.addEventListener('click', function handleClick() {
const initialText = 'Licht an'; const initialText = 'Licht an';
if (btn1.textContent.toLowerCase().includes(initialText.toLowerCase())) { if (btn1.textContent.toLowerCase().includes(initialText.toLowerCase())) {
btn1.textContent = 'Licht aus'; btn1.textContent = 'Licht aus';
//setStateLightOff();
uiState.light_status = 0; uiState.light_status = 0;
} else { } else {
btn1.textContent = initialText; btn1.textContent = initialText;
//setStateLightOn();
uiState.light_status = 1; uiState.light_status = 1;
} }
sendState(uiState); sendState(uiState);
}); });
//event listener for water pump // water pump
btn2.addEventListener('click', function handleClick() { btn2.addEventListener('click', function handleClick() {
const initialText = 'Wasserpumpe an'; const initialText = 'Wasserpumpe an';
if (btn2.textContent.toLowerCase().includes(initialText.toLowerCase())) { if (btn2.textContent.toLowerCase().includes(initialText.toLowerCase())) {
btn2.textContent = 'Wasserpumpe aus'; btn2.textContent = 'Wasserpumpe aus';
} else { } else {
btn2.textContent = initialText; btn2.textContent = initialText;
//setStateWaterPump();
uiState.water_pump_status = 1; uiState.water_pump_status = 1;
} }
sendState(uiState); sendState(uiState);
}); });
//event listener for nutrition pump //nutrition pump
btn3.addEventListener('click', function handleClick() { btn3.addEventListener('click', function handleClick() {
const initialText = 'Nährstoffpumpe an'; const initialText = 'Nährstoffpumpe an';
if (btn3.textContent.toLowerCase().includes(initialText.toLowerCase())) { if (btn3.textContent.toLowerCase().includes(initialText.toLowerCase())) {
btn3.textContent = 'Nährstoffpumpe aus'; btn3.textContent = 'Nährstoffpumpe aus';
} else { } else {
btn3.textContent = initialText; btn3.textContent = initialText;
//setStateNutritionPump();
uiState.nutrition_pump_status = 1; uiState.nutrition_pump_status = 1;
} }
sendState(uiState); sendState(uiState);
}); });
// light automatic
toggleSwitch.addEventListener('change', function() { toggleSwitch.addEventListener('change', function() {
if (this.checked) { if (this.checked) {
timeSelector.style.display = 'block'; timeSelector.style.display = 'block';
...@@ -117,7 +82,6 @@ toggleSwitch.addEventListener('change', function() { ...@@ -117,7 +82,6 @@ toggleSwitch.addEventListener('change', function() {
}); });
// get current status of growbot and refresh gui // get current status of growbot and refresh gui
getState(uiState); getState(uiState);
setTimeout(() => { refresh(); }, 50); setTimeout(() => { refresh(); }, 50);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment