Add error to coffee display when there is a connection problem
Resolves #87
This commit is contained in:
@@ -36,12 +36,29 @@ function onConnect() {
|
|||||||
// data update and parse functions
|
// data update and parse functions
|
||||||
function parseCups(ev){
|
function parseCups(ev){
|
||||||
var cups = parseFloat(ev.detail).toFixed(1)
|
var cups = parseFloat(ev.detail).toFixed(1)
|
||||||
var cupsEvent = new CustomEvent("cupsChanged", {'detail': cups});
|
if (String(cups) !== '-1.0') {
|
||||||
window.dispatchEvent(cupsEvent);
|
var cupsEvent = new CustomEvent("cupsChanged", {'detail': cups});
|
||||||
|
window.dispatchEvent(cupsEvent);
|
||||||
|
} else {
|
||||||
|
var cupsEvent = new CustomEvent("cupsError", {'detail': 'Error: unable to fetch cups :('});
|
||||||
|
window.dispatchEvent(cupsEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
function updateCups(ev){
|
function updateCups(ev){
|
||||||
$("#text").text(ev.detail);
|
$("#text").text(ev.detail);
|
||||||
}
|
}
|
||||||
|
function showCupsError(ev) {
|
||||||
|
$('#text').text(ev.detail);
|
||||||
|
$('#text').css({
|
||||||
|
'font-size': '7vh',
|
||||||
|
'left': '0',
|
||||||
|
'top': '40%',
|
||||||
|
'width': '100%',
|
||||||
|
'text-align': 'center',
|
||||||
|
'color': 'red',
|
||||||
|
});
|
||||||
|
$('#lower').css({'background-image': 'none'});
|
||||||
|
}
|
||||||
function updateScale(ev){
|
function updateScale(ev){
|
||||||
$("#scale2").css({width: Math.min(ev.detail/9*100,100) + '%'});
|
$("#scale2").css({width: Math.min(ev.detail/9*100,100) + '%'});
|
||||||
}
|
}
|
||||||
@@ -72,7 +89,6 @@ function brewAnimStart(){
|
|||||||
$(".text").addClass("brewing");
|
$(".text").addClass("brewing");
|
||||||
$(".layerone").hide();
|
$(".layerone").hide();
|
||||||
$(".layertwo").show();
|
$(".layertwo").show();
|
||||||
|
|
||||||
}
|
}
|
||||||
function brewAnimEnd(){
|
function brewAnimEnd(){
|
||||||
$(".text").removeClass("brewing");
|
$(".text").removeClass("brewing");
|
||||||
@@ -145,6 +161,11 @@ $(document).ready(function(){
|
|||||||
window.addEventListener("cupsChanged", coffeeLowEffect);
|
window.addEventListener("cupsChanged", coffeeLowEffect);
|
||||||
window.addEventListener("cupsChanged", updateScale);
|
window.addEventListener("cupsChanged", updateScale);
|
||||||
window.addEventListener("cupsChanged", resize);
|
window.addEventListener("cupsChanged", resize);
|
||||||
|
|
||||||
|
window.addEventListener("cupsError", showCupsError);
|
||||||
|
window.addEventListener("cupsError", coffeeLowEffect);
|
||||||
|
window.addEventListener("cupsError", updateScale);
|
||||||
|
|
||||||
window.addEventListener("brewStart", brewAnimStart);
|
window.addEventListener("brewStart", brewAnimStart);
|
||||||
window.addEventListener("brewEnd", brewAnimEnd);
|
window.addEventListener("brewEnd", brewAnimEnd);
|
||||||
window.addEventListener("brewEnd", coffeeReadyEffect);
|
window.addEventListener("brewEnd", coffeeReadyEffect);
|
||||||
|
|||||||
Reference in New Issue
Block a user