Snippets
Created by
Anders Åslund
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | //TCH_CT1 //EVENT1 till tid
//TCH_CF1 //EVENT1 från tid
//TCH_DT1 //EVENT 1 till dagar
//TCH_DF1 //EVENT1 från dagar
//var nbrOnOff = 1;
//Läs in taggen med dagar
//var daytag1 = 31;
//var time1 = "830";
//var daytag1 = 31;
//var time2 = "1730";
//till / från
//var value = 0;
function read() {
var ondays = tagValue(prefix + "_DT1");
var offdays = tagValue(prefix + "_DF1");
var on = tagValue(prefix + "_CT1").Replace(":","");
var off = tagValue(prefix + "_CF1").Replace(":","");
for (var i=0; i<=6; i++) {
//Kolla om dagen aktiv
var offday = (offdays & 1<<i) > 0;
var onday = (ondays & 1<<i) > 0;
// Både till och från, Lägg till på samma dag. Om endast till
if(offday && onday) {
schedule.AddEvent("1", pad(on,4) + "-" + pad(off,4) + ":" + (i+1));
} else if(offday && !onday) {
schedule.AddEvent("1", "0000" + "-" + pad(off,4) + ":" + (i+1));
}else if(!offday && onday) {
schedule.AddEvent("1", pad(on,4) + "-" + "0000" + ":" + (i+1));
}
}
return true;
}
function write() {
//Loopa igenom alla schedule.Events
//Lägg alla med samma tilltid till en array?
var offdays = 0;
var ondays = 0;
var days = 0;
var day = 0;
var ontime = "0000"
var offtime = "0000"
if(schedule.Events.Count>0) {
ontime= schedule.Events[0].Time.Substring(0,4);
offtime = schedule.Events[0].Time.Substring(5,4);
day = schedule.Events[0].Time.Substring(10);
} else {
tagWrite(prefix + "_DT1",days.toString());
tagWrite(prefix + "_DF1",days.toString());
tagWrite(prefix + "_CT1",ontime.toString());
tagWrite(prefix + "_CF1",offtime.toString());
return true;
}
if (ontime == "0000" && offtime == "0000") {
offtime = "2400";
}
if(parseInt(offtime,10)>parseInt(ontime,10)) {
days += Math.pow(2,parseInt(day-1));
}
for (var i=1; i<schedule.Events.Count; i++) {
if (schedule.Events[i].Value != schedule.DefaultValue && schedule.Events[i].Time.Length == 11) {
day = schedule.Events[i].Time.Substring(10);
var on = schedule.Events[i].Time.Substring(0,4);
var off = schedule.Events[i].Time.Substring(5,4);
if (on == "0000" && off == "0000") {
off = "2400";
}
//Om aktiv för dagen, offtime > ontime
if(parseInt(off,10)>parseInt(on,10)) {
ontime = on;
offtime = off;
days += Math.pow(2,parseInt(day-1));
}
}
}
tagWrite(prefix + "_DT1",days.toString());
tagWrite(prefix + "_DF1",days.toString());
tagWrite(prefix + "_CT1",ontime.toString());
tagWrite(prefix + "_CF1",offtime.toString());
return true;
}
function pad(n, width) {
var result = '';
for (var i=n.length;i<width;i++) {
result += '0';
}
result += n;
return result;
}
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.