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){ |
|
||||
button.innerText = state = 1 ? "Eteindre" : "Allumer"; |
|
||||
} |
|
||||
|
|
||||
async function getTemp(){ |
|
||||
return await axios.get("/api/temp.php"); |
|
||||
} |
|
||||
|
|
||||
async function getLightState(light){ |
|
||||
return await axios.get("/api/light_state.php?l="+light) |
|
||||
} |
|
||||
|
|
||||
async function setLightState(light){ |
|
||||
const pins = [7, 0, 2, 3, 12, 13, 14, 6]; |
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) |
|
||||
} |
|
||||
|
|
||||
window.setLightState = setLightState |
//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"; |
||||
|
}; |
||||
|
|
||||
/*getLightState(0).then((data) => { |
//Change le texte des bouttons selon l'état actuel des lumières au chargement de la page
|
||||
const button = document.getElementById("button-radiateur") |
for(let light in [0, 1, 2]){ |
||||
buttonSwitch(data.data, button) |
axios.get("/api/get_light.php?l="+pins[light]).then((res) => { |
||||
})*/ |
document.getElementById("btn-"+light).innerText = res.data == 1 ? "Eteindre" : "Allumer"; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
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; |
document.getElementById("temp").innerHTML = data.data; |
||||
}) |
}); |
Loading…
Reference in new issue