X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=raspberry-kiosk%2Fkiosk.js;h=0c90e4ed720ce0981dd838402519896e7c87f32b;hb=7867988775a7b6ec1604a863b665e46ac91e70ac;hp=15fe505420c3688d5a5c67f7c596ba308cdd2918;hpb=6e8fff305273eb943f7f4d905524dee40625941e;p=svn42.git diff --git a/raspberry-kiosk/kiosk.js b/raspberry-kiosk/kiosk.js index 15fe505..0c90e4e 100644 --- a/raspberry-kiosk/kiosk.js +++ b/raspberry-kiosk/kiosk.js @@ -1,3 +1,111 @@ +function min(a,b) +{ + if (a > b) + return b; + else + return a; +} + +function writeGooglePlusEvents(data, elem) +{ + var ghtml = ""; + //var gplusimgwidth = parseInt($('').css("width")); + var gplusimgwidth = 495; + var minimgwidth=78; + for (var i=0; i< data.items.length; i++) + { + var item = data.items[i]; + var noteobj = item.object; + var attach = noteobj.attachments; + var notetxt = noteobj.content; + var noteimgs = new Array(); + if (attach) + { + for (var a=0; a
"+notetxt; + } + } + } + ghtml += '
' + ghtml += '

'+item.updated.substring(0,16).replace("T"," ")+'

'; + ghtml += '

'+notetxt+'

'; + if (noteimgs.length>0) + { + var bigimglimit; + ghtml += '
'; + if (noteimgs.length > 3) + { + var gplusimgmaxwidth = gplusimgwidth - (minimgwidth * ((noteimgs.length -1) / 3)); + bigimglimit = "max-height:"+(minimgwidth*3)+"px; max-width:"+gplusimgmaxwidth+"px;" + ghtml += ''; + for (var ni=1; ni
'; + } + ghtml += ''; + } + } + else + { + var gplusimgmaxwidth = gplusimgwidth / noteimgs.length; + bigimglimit = "max-width:"+gplusimgmaxwidth+"px;" + for (var ni=0; ni'; + } + } + ghtml += '
'; + } + ghtml += ''; + } + elem.innerHTML=ghtml; +} + + +function loadGooglePlusEvents() +{ + var gpak = "AIzaSyD9xBFM-KWwSYBgZ8VzftJ5wYYvurOxEHg"; + var gplusuri = "https://www.googleapis.com/plus/v1/people/113737596421797426873/activities/public?maxResults=4&key="+gpak; + var gpluscontainer=document.getElementById("gplusevents"); + $.getJSON(gplusuri, function(data){ + writeGooglePlusEvents(data, gpluscontainer); + }); +} + +function weekday2str(dow) +{ + var weekday=new Array(7); + weekday[0]="So"; + weekday[1]="Mo"; + weekday[2]="Di"; + weekday[3]="Mi"; + weekday[4]="Do"; + weekday[5]="Fr"; + weekday[6]="Sa"; + weekday[7]="So"; + if (dow >=0 && dow <=7) + return weekday[dow]; + else + return ""; +} function writeCalendar(data, elem) { @@ -12,14 +120,22 @@ function writeCalendar(data, elem) } else { + var weekday = weekday2str((new Date(dt)).getDay()); var stime = data[s].starttime; + var month = data[s].start.substring(5,7); + if (month[0] == '0') + month = month[1]; + var dayofmonth = data[s].start.substring(8,10); + if (dayofmonth[0] == '0') + dayofmonth = dayofmonth[1]; while (stime.substring(stime.length-3,stime.length) == ":00") { stime=stime.substring(0,stime.length-3); } - when = data[s].start +", "+stime+" Uhr"; + if (stime.length <= 2) { stime+="h"; } + when = weekday + " " + dayofmonth+"."+month +", "+stime; } - calhtml += '
  • '+when+' - '+data[s].title+'
  • '+"\n"; + calhtml += '
  • '+when+' - '+data[s].title+'
  • '+"\n"; } elem.innerHTML=''; } @@ -27,7 +143,6 @@ function loadCalendar() { //old URI: //grical.realraum.at/s/?query=!realraum&limit=9&view=json var calcontainer=document.getElementById("grical_upcoming"); - calcontainer.innerHTML="Calendar loading ...
    please wait a second or two"; $.getJSON('/shmcache/grical_realraum.json', function(data){ writeCalendar(data, calcontainer); }); @@ -53,20 +168,47 @@ function writeAnwesenheitStatus(data) if (data.sensors) { - for (var s=0; s
    '+swhere+': '+svalue+''; - }); + $.each( data.sensors.temperature, function(s, sensorobj) { + sensorstd+='Temperatur
    '+sensorobj.location+': '+sensorobj.value.toFixed(2)+sensorobj.unit+''; }); } - } - if (sensorstd != "") - { - sensorshtml=''+sensorstd+'
    '; - document.getElementById('sensor_status').innerHTML=sensorshtml; - } + if (data.sensors.ext_illumination) + { + $.each( data.sensors.ext_illumination, function(s, sensorobj) { + sensorstd+='Licht
    '+sensorobj.location+': '+sensorobj.value+''; + }); + } + if (data.sensors.door_locked) + { + $.each( data.sensors.door_locked, function(s, sensorobj) { + var lockstatus="Unlocked"; + if (sensorobj.value) { lockstatus = "Locked"; } + sensorstd+='Türschloß
    '+sensorobj.location+': '+lockstatus+''; + }); + } + if (data.sensors.ext_door_ajar) + { + $.each( data.sensors.ext_door_ajar, function(s, sensorobj) { + var lockstatus="Shut"; + if (sensorobj.value) { lockstatus = "Ajar"; } + sensorstd+='Türkontakt
    '+sensorobj.location+': '+lockstatus+''; + }); + } + if (data.sensors.ext_dust) + { + $.each( data.sensors.ext_dust, function(s, sensorobj) { + sensorstd+='Staub
    '+sensorobj.location+': '+sensorobj.value+sensorobj.unit+''; + }); + + } + if (sensorstd != "") + { + sensorshtml=''+sensorstd+'
    '; + document.getElementById('sensor_status').innerHTML=sensorshtml; + } + } } function updateAnwesenheitStatus() @@ -79,18 +221,6 @@ function updateAnwesenheitStatus() //req.send(null); var jqxhr = $.getJSON(url, writeAnwesenheitStatus); } -var anwesenheit_timer = window.setInterval("updateAnwesenheitStatus()", 10000); - -function updateSensors() -{ - //reloadImg(document.getElementById("tempsensor")); - reloadImg(document.getElementById("movementsensor")); - reloadImg(document.getElementById("lightsensor")); -} - -var timer; -var seconds = 0; -var schedule = Array() $(document).ready(function() { @@ -98,9 +228,11 @@ $(document).ready(function() setInterval("clock()", 500); updateAnwesenheitStatus(); loadCalendar(); - setInterval("updateAnwesenheitStatus()", 10000); - setInterval("loadCalendar()", 100000); - setInterval("updateSensors()", 50000); + loadGooglePlusEvents(); + setInterval("updateAnwesenheitStatus()", 10*1000); + setInterval("loadCalendar()", 123*1000); + setInterval("updateSensors()",145*1000); + setInterval("loadGooglePlusEvents()", 1207*1000); }); function updateDateClock(now) @@ -128,7 +260,7 @@ function highlightEntry(idx, color, value) } } - +var seconds = 0; function clock(now) { var now = new Date(new Date().valueOf() + 300); @@ -139,25 +271,56 @@ function clock(now) } } -//function updateSchedule() -//{ -// $.ajax({type: "GET", url: "/export/schedules.php", data: "days=3&start=-1", dataType: "xml", error: showError, success: parseXml}); -//} - function showError(XMLHttpRequest, textStatus, errorThrown) { alert("Error: " + textStatus); } -function reloadImg(element) +function updateSensors() { - //var image = document.getElementById("theText"); - if(element.complete) { - var new_image = new Image(); - //set up the new image - new_image.id = element.id; - new_image.src = element.src; + reloadImg(document.getElementById("tempsensor")); + reloadImg(document.getElementById("movementsensor")); + reloadImg(document.getElementById("lightsensor")); +} + +function IsImageOk(img) { + if (!img.complete) + { + return false; + } + if (typeof img.naturalWidth == "undefined" || (typeof img.naturalWidth == "number" && img.naturalWidth == 0)) + { + return false; + } + return true; +} + +var img_orig_src = {}; +function reloadImgAlt(element) +{ + if(element.complete) + { + var new_image = new Image(); + //set up the new image + new_image.id = element.id; + new_image.className = element.className; + if (! img_orig_src[element.id]) + { + img_orig_src[element.id] = element.src; + } + new_image.src = img_orig_src[element.id] + "?dt="+Math.floor(new Date().getTime() / 1000).toString(); + if (IsImageOk(new_image)) + { element.parentNode.insertBefore(new_image,element); element.parentNode.removeChild(element); + } + } +} +function reloadImg(element) +{ + if (! img_orig_src[element.id]) + { + img_orig_src[element.id] = element.src; } + element.src = img_orig_src[element.id] + "?dt="+Math.floor(new Date().getTime() / 1000).toString(); }