Kalyax
2 years ago
2 changed files with 18 additions and 29 deletions
@ -1,31 +1,23 @@ |
|||||
import './style.css'; |
import './style.css'; |
||||
import axios from 'axios'; |
import axios from 'axios'; |
||||
|
|
||||
function buttonSwitch(state, button){ |
const pins = [7, 0, 2, 3, 12, 13, 14, 6]; |
||||
button.innerText = state = 1 ? "Eteindre" : "Allumer"; |
|
||||
} |
|
||||
|
|
||||
async function getTemp(){ |
|
||||
return await axios.get("/api/temp.php"); |
|
||||
} |
|
||||
|
|
||||
async function getLightState(light){ |
//Fonction changeant l'état d'une lumière donnée (0-7)
|
||||
return await axios.get("/api/light_state.php?l="+light) |
//Ajoutée à window pour être utilisé dans un event de la page
|
||||
} |
window.setLightState = async (light) => { |
||||
|
const res = await axios.get("/api/set_light.php?light="+pins[light]); |
||||
|
document.getElementById("btn-"+light).innerText = res.data == 1 ? "Eteindre" : "Allumer"; |
||||
|
}; |
||||
|
|
||||
async function setLightState(light){ |
//Change le texte des bouttons selon l'état actuel des lumières au chargement de la page
|
||||
const pins = [7, 0, 2, 3, 12, 13, 14, 6]; |
for(let light in [0, 1, 2]){ |
||||
const req = await axios.post("/api/set_light.php", {light: pins[light]}) |
axios.get("/api/get_light.php?l="+pins[light]).then((res) => { |
||||
console.log(req.data) |
document.getElementById("btn-"+light).innerText = res.data == 1 ? "Eteindre" : "Allumer"; |
||||
|
}); |
||||
} |
} |
||||
|
|
||||
window.setLightState = setLightState |
//Récupère et affiche la temperature au chargement de la page
|
||||
|
axios.get("/api/get_temp.php").then((data) => { |
||||
/*getLightState(0).then((data) => { |
|
||||
const button = document.getElementById("button-radiateur") |
|
||||
buttonSwitch(data.data, button) |
|
||||
})*/ |
|
||||
|
|
||||
getTemp().then((data) => { |
|
||||
document.getElementById("temp").innerHTML = data.data; |
document.getElementById("temp").innerHTML = data.data; |
||||
}) |
}); |
Loading…
Reference in new issue