Rev 1899 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1767 | linlun | 1 | |
| 2 | |||
| 2300 | linlun | 3 | function TouchPanel(aliasnameRGBLED_red,aliasnameRGBLED_green, aliasnameRGBLED_blue, aliasnameTouch, aliasnameDimmer1, aliasnameDimmer2, aliasnameDimmer3, aliasnameDimmer4, aliasnameDimmer5, aliasnameDimmer6,aliasnameDimmer7, aliasnameIR ) |
| 1767 | linlun | 4 | { |
| 5 | |||
| 6 | /* Declaration of instance variables, for static variables remove prototype */ |
||
| 7 | |||
| 8 | /* We must always call the parent constructor, initialization |
||
| 9 | of variables could be done here, but initialize is a better place */ |
||
| 10 | var self = this; |
||
| 11 | this.myTouch = aliasnameTouch; |
||
| 12 | this.myRGBLED_red = aliasnameRGBLED_red; |
||
| 13 | this.myRGBLED_blue = aliasnameRGBLED_blue; |
||
| 14 | this.myRGBLED_green = aliasnameRGBLED_green; |
||
| 15 | this.myDimmer1 = aliasnameDimmer1; |
||
| 16 | this.myDimmer2 = aliasnameDimmer2; |
||
| 17 | this.myDimmer3 = aliasnameDimmer3; |
||
| 1899 | linlun | 18 | this.myDimmer4 = aliasnameDimmer4; |
| 19 | this.myDimmer5 = aliasnameDimmer5; |
||
| 20 | this.myDimmer6 = aliasnameDimmer6; |
||
| 2300 | linlun | 21 | this.myDimmer7 = aliasnameDimmer7; |
| 22 | this.myIR = aliasnameIR; |
||
| 1767 | linlun | 23 | this.myTouchMode = "Gesture"; |
| 24 | this.myTouchRawX = 0; |
||
| 25 | this.myTouchRawY = 0; |
||
| 26 | this.myTouchRawYlast = 0; |
||
| 27 | Module_RegisterToOnMessage(aliasnameTouch, function(alias_name, command, variables) { self.touchOnMessage(alias_name, command, variables) }); |
||
| 28 | |||
| 29 | /* Start interval timer for sending timestamp to network. Arguments are the callback function and time in milliseconds |
||
| 30 | used to make sure an eth-node gets its init packet (600s) */ |
||
| 31 | this.myTimer = Timer_SetTimer(function(timer) {self.timerUpdate(timer)}, 5000, true); |
||
| 32 | Log("\033[33mTouchpanel created.\033[0m"); |
||
| 33 | |||
| 34 | } |
||
| 35 | |||
| 36 | /* Declaration of instance variables, for static variables remove prototype */ |
||
| 37 | TouchPanel.prototype.myDimmer1 = null; |
||
| 38 | TouchPanel.prototype.myDimmer2 = null; |
||
| 39 | TouchPanel.prototype.myDimmer3 = null; |
||
| 1899 | linlun | 40 | TouchPanel.prototype.myDimmer4 = null; |
| 41 | TouchPanel.prototype.myDimmer5 = null; |
||
| 42 | TouchPanel.prototype.myDimmer6 = null; |
||
| 2300 | linlun | 43 | TouchPanel.prototype.myDimmer7 = null; |
| 1767 | linlun | 44 | TouchPanel.prototype.myTouch = null; |
| 45 | TouchPanel.prototype.myRGBLED_red = null; |
||
| 46 | TouchPanel.prototype.myRGBLED_green = null; |
||
| 47 | TouchPanel.prototype.myRGBLED_blue = null; |
||
| 48 | //TouchPanel.prototype.outputStatus = "Low"; |
||
| 49 | TouchPanel.prototype.myInterval = null; |
||
| 50 | //TouchPanel.prototype.oldPwmValue = 0; |
||
| 51 | //TouchPanel.prototype.turnOffCnt = 0; |
||
| 52 | |||
| 53 | TouchPanel.prototype.myTouchMode = null; |
||
| 54 | TouchPanel.prototype.myTouchRawX = null; |
||
| 55 | TouchPanel.prototype.myTouchRawY = null; |
||
| 56 | TouchPanel.prototype.myTouchRawYlast = null; |
||
| 57 | |||
| 58 | const XMIN = 40; |
||
| 59 | const XMAX = 215; |
||
| 60 | //const XLIMIT1 = XMIN + (XMAX-XMIN)/3; |
||
| 61 | //const XLIMIT2 = XMIN*2 + (XMAX-XMIN)/3; |
||
| 62 | const XLIMIT1 = 100; |
||
| 63 | const XLIMIT2 = 155; |
||
| 64 | |||
| 65 | |||
| 66 | |||
| 67 | TouchPanel.prototype.touchOnMessage = function(alias_name, command, variables) |
||
| 68 | { |
||
| 69 | //Log("\033[33mMessage.\033[0m\n"); |
||
| 70 | switch (command) |
||
| 71 | { |
||
| 72 | case "Gesture": |
||
| 73 | var gesture = null; |
||
| 74 | gesture = Touch_lookupGesture(variables["f1"],variables["f2"],variables["f3"],variables["f4"],variables["f5"],variables["f6"],variables["f7"],variables["f8"],variables["f9"]); |
||
| 75 | if (this.myTouchMode == "Gesture") |
||
| 76 | { |
||
| 77 | var self = this; |
||
| 78 | Log("New gesture: "+gesture); |
||
| 79 | if (gesture == "INSERT") |
||
| 80 | { |
||
| 81 | ////getDimmerService('Badrum').absFade(2,132, 255); |
||
| 82 | //getDimmerService('TakHall').absFade(0,132, 255); |
||
| 83 | //getDimmerService('TakSovrum').absFade(0,132, 255); |
||
| 84 | //Dimmer_AbsoluteFade(this.myDimmer1, 132, 255); |
||
| 85 | Dimmer_AbsoluteFade(this.myDimmer2, 132, 255); |
||
| 86 | Dimmer_AbsoluteFade(this.myDimmer3, 132, 255); |
||
| 1899 | linlun | 87 | Dimmer_AbsoluteFade(this.myDimmer4, 132, 255); |
| 88 | Dimmer_AbsoluteFade(this.myDimmer5, 132, 255); |
||
| 89 | Dimmer_AbsoluteFade(this.myDimmer6, 132, 255); |
||
| 1767 | linlun | 90 | this.setLED(0,255,0); |
| 91 | Timer_Cancel(this.myInterval); |
||
| 92 | this.myInterval = Timer_SetTimer(function(timer) {self.timerUpdate(timer)}, 5000, true); |
||
| 2300 | linlun | 93 | |
| 94 | |||
| 95 | /* Check if it is time to turn on ljusstake i sovrummet */ |
||
| 96 | |||
| 97 | if (get_time() > TouchGetTsFromTime("7:00") && get_time() < TouchGetTsFromTime("9:30")) |
||
| 98 | { |
||
| 99 | TouchstartSend("rf", "NexaRemote", "Dosa_3_On", 4); |
||
| 100 | } |
||
| 101 | if (get_time() > TouchGetTsFromTime("16:00") && get_time() < TouchGetTsFromTime("22:00")) |
||
| 102 | { |
||
| 103 | TouchstartSend("rf", "NexaRemote", "Dosa_3_On", 4); |
||
| 104 | } |
||
| 105 | |||
| 106 | |||
| 1767 | linlun | 107 | } |
| 108 | else if (gesture == "JOIN") |
||
| 109 | { |
||
| 110 | //getDimmerService('Badrum').absFade(2,132, 0); |
||
| 111 | //getDimmerService('TakHall').absFade(0,132, 0); |
||
| 112 | //getDimmerService('TakSovrum').absFade(0,132, 0); |
||
| 113 | Dimmer_AbsoluteFade(this.myDimmer1, 132, 0); |
||
| 114 | Dimmer_AbsoluteFade(this.myDimmer2, 132, 0); |
||
| 2300 | linlun | 115 | var shorttime = new Date().getTimeShortFormated(); |
| 116 | /* Remove leading zero if any */ |
||
| 117 | var data = parseInt(shorttime.substr(0,2)); |
||
| 118 | //if (data < 22 && data >= 6) { |
||
| 119 | Dimmer_AbsoluteFade(this.myDimmer3, 132, 0); |
||
| 120 | //} |
||
| 1899 | linlun | 121 | Dimmer_AbsoluteFade(this.myDimmer4, 132, 0); |
| 122 | Dimmer_AbsoluteFade(this.myDimmer5, 132, 0); |
||
| 123 | Dimmer_AbsoluteFade(this.myDimmer6, 132, 0); |
||
| 2300 | linlun | 124 | Dimmer_AbsoluteFade(this.myDimmer7, 132, 0); |
| 1767 | linlun | 125 | this.setLED(0,0,255); |
| 126 | Timer_Cancel(this.myInterval); |
||
| 127 | this.myInterval = Timer_SetTimer(function(timer) {self.timerUpdate(timer)}, 5000, true); |
||
| 128 | |||
| 129 | } |
||
| 130 | /*else if (gesture == "UNDO") |
||
| 131 | { |
||
| 132 | Log("Going to raw mode\n"); |
||
| 133 | this.setLED(255,0,0); |
||
| 134 | this.myTouchMode = "Raw"; |
||
| 135 | |||
| 136 | } */ |
||
| 137 | else if (gesture == "COPY") |
||
| 138 | { |
||
| 139 | this.setLED(0,255,255); |
||
| 140 | //getDimmerService('Badrum').absFade(2,132, 0); |
||
| 141 | //getDimmerService('TakHall').absFade(0,117, 0); |
||
| 142 | //getDimmerService('TakSovrum').absFade(0,105, 0); |
||
| 143 | Dimmer_AbsoluteFade(this.myDimmer1, 132, 0); |
||
| 144 | Dimmer_AbsoluteFade(this.myDimmer2, 117, 0); |
||
| 2300 | linlun | 145 | Dimmer_AbsoluteFade(this.myDimmer3, 132, 0); |
| 1899 | linlun | 146 | Dimmer_AbsoluteFade(this.myDimmer4, 132, 0); |
| 147 | Dimmer_AbsoluteFade(this.myDimmer5, 132, 0); |
||
| 148 | Dimmer_AbsoluteFade(this.myDimmer6, 132, 0); |
||
| 2300 | linlun | 149 | Dimmer_AbsoluteFade(this.myDimmer7, 132, 0); |
| 1767 | linlun | 150 | Timer_Cancel(this.myInterval); |
| 151 | this.myInterval = Timer_SetTimer(function(timer) {self.timerUpdate(timer)}, 5000, true); |
||
| 2300 | linlun | 152 | } else if (gesture == "INSERT_LINE") |
| 153 | { |
||
| 154 | Log("Starting Roomba\n"); |
||
| 155 | this.setLED(255,0,0); |
||
| 156 | IROut_SendBurst(this.myIR, "Roomba", "Clean"); |
||
| 1767 | linlun | 157 | } |
| 2300 | linlun | 158 | |
| 1767 | linlun | 159 | } |
| 160 | |||
| 161 | |||
| 162 | break; |
||
| 163 | case "Raw": |
||
| 164 | |||
| 165 | break; |
||
| 166 | } |
||
| 167 | |||
| 168 | } |
||
| 169 | |||
| 2300 | linlun | 170 | function TouchGetTsFromTime(time) |
| 171 | { |
||
| 172 | var date = new Date().getDateFormated(); |
||
| 173 | var timestamp = Date.parse(date + " " + time); |
||
| 174 | return timestamp/1000; |
||
| 175 | } |
||
| 176 | |||
| 177 | /* Start sending command, could be command to start heating or stop heating */ |
||
| 178 | /* A command is sent <count> number of times to make sure its actually sent */ |
||
| 179 | function TouchstartSend(alias, remote, button, count) |
||
| 180 | { |
||
| 181 | if (count > 0) |
||
| 182 | { |
||
| 183 | //Log("carHeater: Start sending heater command, count="+count); |
||
| 184 | sendCounter = count; |
||
| 185 | sendTimer_id = Timer_SetTimer(function(timer) {send(alias, remote, button)}, 5000, true); |
||
| 186 | send(alias, remote, button); |
||
| 187 | } |
||
| 188 | } |
||
| 189 | |||
| 190 | function Touchsend(alias, remote, button) |
||
| 191 | { |
||
| 192 | if (sendCounter > 0) |
||
| 193 | { |
||
| 194 | //Log("carHeater: Sending heater command, count="+sendCounter); |
||
| 195 | IROut_SendBurst(alias, remote, button); |
||
| 196 | } |
||
| 197 | sendCounter--; |
||
| 198 | if (sendCounter == 0) |
||
| 199 | { |
||
| 200 | Timer_Cancel(sendTimer_id); |
||
| 201 | } |
||
| 202 | } |
||
| 203 | |||
| 204 | |||
| 1767 | linlun | 205 | TouchPanel.prototype.timerUpdate = function(timer) |
| 206 | { |
||
| 207 | this.myTouchMode = "Gesture" |
||
| 208 | Log("Switching back to Gesture mode\n"); |
||
| 209 | this.setLED(0,0,0); |
||
| 210 | Timer_Cancel(timer); |
||
| 211 | //this.myInterval = Timer_SetTimer(function(timer) {self.updateDisplay(timer)}, this.currentMenuItem.UpdateTime, true); |
||
| 212 | } |
||
| 213 | |||
| 214 | |||
| 215 | TouchPanel.prototype.setLED = function(red, green, blue) |
||
| 216 | { |
||
| 217 | //log("setting LED\n"); |
||
| 218 | softPWM_SetPWMValue(this.myRGBLED_red, 10000-(red&0xff)*39); |
||
| 219 | softPWM_SetPWMValue(this.myRGBLED_green, 10000-(green&0xff)*39); |
||
| 220 | softPWM_SetPWMValue(this.myRGBLED_blue, 10000-(blue&0xff)*39); |
||
| 221 | } |
||
| 222 | |||
| 223 | |||
| 224 | /* |
||
| 225 | |||
| 226 | TouchPanel.prototype.incomingStatusChanged = function() |
||
| 227 | { |
||
| 228 | if (this.myTouchMode == "Raw") |
||
| 229 | { |
||
| 230 | if (this.myTouchPanelService.getLastState() == "Pressed") |
||
| 231 | { |
||
| 232 | this.myTouchRawX = this.myTouchPanelService.getLastX(); |
||
| 233 | this.myTouchRawY = this.myTouchPanelService.getLastY(); |
||
| 234 | this.myTouchRawYlast = this.myTouchPanelService.getLastY(); |
||
| 235 | } |
||
| 236 | else if (this.myTouchPanelService.getLastState() == "Released") |
||
| 237 | { |
||
| 238 | *//*var currX = this.myTouchPanelService.getLastX(); |
||
| 239 | var currY = this.myTouchPanelService.getLastY(); |
||
| 240 | log("stored x "+this.myTouchRawX+" currx "+currX+" stored y "+this.myTouchRawY+" curry "+currY+"\n"); |
||
| 241 | if (this.myTouchRawX < currX+8 && this.myTouchRawX > currX-8 && this.myTouchRawY < currY+8 && this.myTouchRawY > currY-8) |
||
| 242 | { |
||
| 243 | log("activating next lightdevice\n"); |
||
| 244 | if (this.currentLightDevice.nextItem) |
||
| 245 | { |
||
| 246 | this.currentLightDevice = this.currentLightDevice.nextItem; |
||
| 247 | this.currentLightDevice.doActivate(); |
||
| 248 | } |
||
| 249 | } |
||
| 250 | *//* |
||
| 251 | //log("starting timer\n"); |
||
| 252 | this.myInterval.start(); |
||
| 253 | } |
||
| 254 | } |
||
| 255 | } |
||
| 256 | |||
| 257 | TouchPanel.prototype.incomingRaw = function() |
||
| 258 | { |
||
| 259 | |||
| 260 | if (this.myTouchMode == "Raw") |
||
| 261 | { |
||
| 262 | if (this.myTouchPanelService.getLastState() == "Pressed") |
||
| 263 | { |
||
| 264 | var yDiff = this.myTouchPanelService.getLastY() - this.myTouchRawYlast; |
||
| 265 | //var xPos = this.myTouchPanelService.getLastX(); |
||
| 266 | if (yDiff > 0) |
||
| 267 | { |
||
| 268 | if (this.myTouchRawX < XLIMIT1) { |
||
| 269 | //this.currentLightDevice.doRelIncrease(yDiff*2) |
||
| 270 | getDimmerService('Badrum').relFade(2,132, "Increase", yDiff*2); |
||
| 271 | } else if (this.myTouchRawX < XLIMIT2) { |
||
| 272 | getDimmerService('TakHall').relFade(0,132, "Increase", yDiff*2); |
||
| 273 | } else { |
||
| 274 | getDimmerService('TakSovrum').relFade(0,132, "Increase", yDiff*2); |
||
| 275 | } |
||
| 276 | } |
||
| 277 | else if (yDiff < 0) |
||
| 278 | { |
||
| 279 | if (this.myTouchRawX < XLIMIT1) { |
||
| 280 | //this.currentLightDevice.doRelIncrease(yDiff*2) |
||
| 281 | getDimmerService('Badrum').relFade(2,132, "Decrease", yDiff*2); |
||
| 282 | } else if (this.myTouchRawX < XLIMIT2) { |
||
| 283 | getDimmerService('TakHall').relFade(0,132, "Decrease", yDiff*2); |
||
| 284 | } else { |
||
| 285 | getDimmerService('TakSovrum').relFade(0,132, "Decrease", yDiff*2); |
||
| 286 | } |
||
| 287 | } |
||
| 288 | this.myTouchRawYlast = this.myTouchPanelService.getLastY(); |
||
| 289 | } |
||
| 290 | //this.myInterval.stop(); |
||
| 291 | //this.myInterval.start(); |
||
| 292 | } |
||
| 293 | } |
||
| 294 | */ |
||
| 295 | |||
| 296 |