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