Rev 1212 | Rev 1226 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1212 | Rev 1216 | ||
|---|---|---|---|
| Line 37... | Line 37... | ||
| 37 | /* */ |
37 | /* */ |
| 38 | Display.prototype.exchangeCalendarFirstMenuItem = null; |
38 | Display.prototype.exchangeCalendarFirstMenuItem = null; |
| 39 | Display.prototype.exchangeCalendarLastMenuItem = null; |
39 | Display.prototype.exchangeCalendarLastMenuItem = null; |
| 40 | Display.prototype.statusMenuItem = null; |
40 | Display.prototype.statusMenuItem = null; |
| 41 | Display.prototype.bookMenuItem = null; |
41 | Display.prototype.bookMenuItem = null; |
| - | 42 | Display.prototype.bookResultMenuItem = null; |
|
| - | 43 | ||
| 42 | 44 | ||
| 43 | /* The currently displayed menuitem */ |
45 | /* The currently displayed menuitem */ |
| 44 | Display.prototype.currentMenuItem = null; |
46 | Display.prototype.currentMenuItem = null; |
| 45 | 47 | ||
| 46 | /* counter for calling exchange update */ |
48 | /* counter for calling exchange update */ |
| 47 | Display.prototype.exchangeUpdateCnt = null; |
49 | Display.prototype.exchangeUpdateCnt = null; |
| 48 | 50 | ||
| 49 | /* counter for going to screensaver */ |
51 | /* counter for going to screensaver */ |
| 50 | Display.prototype.screenSaverCnt = null; |
52 | Display.prototype.screenSaverCnt = null; |
| 51 | 53 | ||
| 52 | /* counter for going to main screen */ |
54 | /* counter for going to main screen */ |
| 53 | Display.prototype.mainScreenCnt = null; |
55 | Display.prototype.mainScreenCnt = null; |
| 54 | 56 | ||
| 55 | const exchangeUpdateTimeout = 50; |
57 | const exchangeUpdateTimeout = 50; |
| 56 | const mainScreenTimeout = 40; |
58 | const mainScreenTimeout = 40; |
| 57 | const screenSaverTimeout = 120; |
59 | const screenSaverTimeout = 120; |
| 58 | 60 | ||
| 59 | const bookingIncrease = 15; |
61 | const bookingIncrease = 15; |
| 60 | 62 | ||
| 61 | /* This function must always be declared, this is where all the startup code |
63 | /* This function must always be declared, this is where all the startup code |
| 62 | should be placed. Gets called with arguments like what ids to use etc. */ |
64 | should be placed. Gets called with arguments like what ids to use etc. */ |
| 63 | Display.prototype.initialize = function(initialArguments) |
65 | Display.prototype.initialize = function(initialArguments) |
| 64 | { |
66 | { |
| 65 | /* We must always call the parent initialize */ |
67 | /* We must always call the parent initialize */ |
| Line 81... | Line 83... | ||
| 81 | } |
83 | } |
| 82 | 84 | ||
| 83 | if (!this.myInitialArguments["softPWM"]) |
85 | if (!this.myInitialArguments["softPWM"]) |
| 84 | { |
86 | { |
| 85 | log(this.myName + ":" + this.myId + "> Failed to initialize, softPWM-config missing from config.\n"); |
87 | log(this.myName + ":" + this.myId + "> Failed to initialize, softPWM-config missing from config.\n"); |
| 86 | return; |
88 | return; |
| 87 | } |
89 | } |
| 88 | 90 | ||
| 89 | if (!this.myInitialArguments["Name"]) |
91 | if (!this.myInitialArguments["Name"]) |
| 90 | { |
92 | { |
| 91 | log(this.myName + ":" + this.myId + "> Failed to initialize, Name-config missing from config.\n"); |
93 | log(this.myName + ":" + this.myId + "> Failed to initialize, Name-config missing from config.\n"); |
| Line 106... | Line 108... | ||
| 106 | 108 | ||
| 107 | /* Get the LCD service that we want from the ServiceManager, it takes type, service name, service id */ |
109 | /* Get the LCD service that we want from the ServiceManager, it takes type, service name, service id */ |
| 108 | this.myLCDService = ServiceManager.getService("Can", "HD44789", this.myInitialArguments["HD44789"]["Id"]); |
110 | this.myLCDService = ServiceManager.getService("Can", "HD44789", this.myInitialArguments["HD44789"]["Id"]); |
| 109 | /* Add a callback for when the service goes online */ |
111 | /* Add a callback for when the service goes online */ |
| 110 | this.myLCDService.registerEventCallback("online", function(args) { self.lcdOnline(); }); |
112 | this.myLCDService.registerEventCallback("online", function(args) { self.lcdOnline(); }); |
| 111 | /* If the service is already online we should call the handler here */ |
113 | /* If the service is already online we should call the handler here */ |
| 112 | this.lcdOnline(); |
114 | this.lcdOnline(); |
| 113 | /* Add a callback for when the service goes offline */ |
115 | /* Add a callback for when the service goes offline */ |
| 114 | this.myLCDService.registerEventCallback("offline", function(args) { self.lcdOffline(); }); |
116 | this.myLCDService.registerEventCallback("offline", function(args) { self.lcdOffline(); }); |
| 115 | 117 | ||
| 116 | /* Get the Rotary service that we want from the ServiceManager, it takes type, service name, service id */ |
118 | /* Get the Rotary service that we want from the ServiceManager, it takes type, service name, service id */ |
| Line 130... | Line 132... | ||
| 130 | this.mySoftPwmService.registerEventCallback("online", function(args) { self.softPwmOnline(); }); |
132 | this.mySoftPwmService.registerEventCallback("online", function(args) { self.softPwmOnline(); }); |
| 131 | /* If the service is already online we should call the handler here */ |
133 | /* If the service is already online we should call the handler here */ |
| 132 | this.softPwmOnline(); |
134 | this.softPwmOnline(); |
| 133 | 135 | ||
| 134 | this.exchangeCalendar = new ExchangeCalendar(function(shortname, data) { self.exchangeCalendarLookupCallback(shortname, data); }); |
136 | this.exchangeCalendar = new ExchangeCalendar(function(shortname, data) { self.exchangeCalendarLookupCallback(shortname, data); }); |
| - | 137 | this.exchangeCalendarBook = new ExchangeCalendar(function(shortname, data) { self.exchangeCalendarBookCallback(shortname, data); }); |
|
| 135 | 138 | ||
| 136 | /* create the first menu item */ |
139 | /* create the first menu item */ |
| 137 | this.statusMenuItem = new MenuItem(this); |
140 | this.statusMenuItem = new MenuItem(this); |
| 138 | this.statusMenuItem.displayData[0] = this.lcdCenterText(this.niceName); |
141 | this.statusMenuItem.displayData[0] = this.lcdCenterText(this.niceName); |
| 139 | this.statusMenuItem.doUpdate = this.updateStatusMenuItem; |
142 | this.statusMenuItem.doUpdate = this.updateStatusMenuItem; |
| 140 | this.currentMenuItem = this.statusMenuItem; |
143 | this.currentMenuItem = this.statusMenuItem; |
| 141 | 144 | ||
| 142 | /* create the menuitem where you can choose to enter the booking sub-menu */ |
145 | /* create the menuitem where you can choose to enter the booking sub-menu */ |
| 143 | this.bookMenuItem = new MenuItem(this); |
146 | this.bookMenuItem = new MenuItem(this); |
| 144 | this.bookMenuItem.displayData[0] = this.lcdCenterText("Book room"); |
147 | this.bookMenuItem.displayData[0] = this.lcdCenterText("Book room"); |
| 145 | this.bookMenuItem.displayData[1] = this.lcdCenterText("( |
148 | this.bookMenuItem.displayData[1] = this.lcdCenterText("(Push button)"); |
| 146 | this.bookMenuItem.doUpdate = this.updateBookMenuItem; |
149 | this.bookMenuItem.doUpdate = this.updateBookMenuItem; |
| 147 | 150 | ||
| 148 | /* connect the items as a linked list */ |
151 | /* connect the items as a linked list */ |
| 149 | this.statusMenuItem.setNextItem(this.bookMenuItem); |
152 | this.statusMenuItem.setNextItem(this.bookMenuItem); |
| 150 | this.statusMenuItem.setPrevItem(this.bookMenuItem); |
153 | this.statusMenuItem.setPrevItem(this.bookMenuItem); |
| Line 162... | Line 165... | ||
| 162 | /* create the menuitem where you can choose the to-time */ |
165 | /* create the menuitem where you can choose the to-time */ |
| 163 | var menuChooseTo = new MenuItem(this); |
166 | var menuChooseTo = new MenuItem(this); |
| 164 | menuChooseTo.displayData[1] = this.lcdCenterText(" Ok Cancel "); |
167 | menuChooseTo.displayData[1] = this.lcdCenterText(" Ok Cancel "); |
| 165 | menuChooseTo.doUpdate = this.chooseBookTimeTo; |
168 | menuChooseTo.doUpdate = this.chooseBookTimeTo; |
| 166 | 169 | ||
| 167 | this.bookMenuItem.doPress = this. |
170 | this.bookMenuItem.doPress = this.prepareBookingMenu; |
| 168 | this.bookMenuItem.setDescItem(menuChooseTo); |
171 | this.bookMenuItem.setDescItem(menuChooseTo); |
| 169 | 172 | ||
| 170 | /* create the menuitem where you can choose to book the room with OK */ |
173 | /* create the menuitem where you can choose to book the room with OK */ |
| 171 | var menuChooseOk = new MenuItem(this); |
174 | var menuChooseOk = new MenuItem(this); |
| 172 | menuChooseOk.displayData[1] = this.lcdCenterText("<Ok> Cancel "); |
175 | menuChooseOk.displayData[1] = this.lcdCenterText("<Ok> Cancel "); |
| Line 179... | Line 182... | ||
| 179 | 182 | ||
| 180 | /* create the menuitem where you can choose the from-time */ |
183 | /* create the menuitem where you can choose the from-time */ |
| 181 | var menuChooseFrom = new MenuItem(this); |
184 | var menuChooseFrom = new MenuItem(this); |
| 182 | menuChooseFrom.displayData[1] = this.lcdCenterText(" Ok Cancel "); |
185 | menuChooseFrom.displayData[1] = this.lcdCenterText(" Ok Cancel "); |
| 183 | menuChooseFrom.doUpdate = this.chooseBookTimeFrom; |
186 | menuChooseFrom.doUpdate = this.chooseBookTimeFrom; |
| - | 187 | ||
| - | 188 | /* create the menuitem where you see the result of a booking */ |
|
| - | 189 | this.bookResultMenuItem = new MenuItem(this); |
|
| - | 190 | this.bookResultMenuItem.displayData[0] = this.lcdCenterText("Booking..."); |
|
| - | 191 | this.bookResultMenuItem.displayData[1] = this.lcdCenterText("(Push to return)"); |
|
| - | 192 | this.bookResultMenuItem.setDescItem(this.bookMenuItem); |
|
| - | 193 | this.bookResultMenuItem.doPress = this.changeToDesc; |
|
| 184 | 194 | ||
| 185 | /* connect the items as a linked list */ |
195 | /* connect the items as a linked list */ |
| 186 | menuChooseTo.setNextItem(menuChooseOk); |
196 | menuChooseTo.setNextItem(menuChooseOk); |
| 187 | menuChooseTo.setPrevItem(menuChooseFrom); |
197 | menuChooseTo.setPrevItem(menuChooseFrom); |
| 188 | /* set the function that shall be executed when knob is turned */ |
198 | /* set the function that shall be executed when knob is turned */ |
| Line 191... | Line 201... | ||
| 191 | menuChooseTo.doPress = this.changeToDesc; |
201 | menuChooseTo.doPress = this.changeToDesc; |
| 192 | 202 | ||
| 193 | /* connect the items as a linked list */ |
203 | /* connect the items as a linked list */ |
| 194 | menuChooseOk.setNextItem(menuChooseCancel); |
204 | menuChooseOk.setNextItem(menuChooseCancel); |
| 195 | menuChooseOk.setPrevItem(menuChooseTo); |
205 | menuChooseOk.setPrevItem(menuChooseTo); |
| - | 206 | menuChooseOk.setDescItem(this.bookResultMenuItem); |
|
| 196 | /* set the function that shall be executed when knob is turned */ |
207 | /* set the function that shall be executed when knob is turned */ |
| 197 | menuChooseOk.doRight = this.changeToNext; |
208 | menuChooseOk.doRight = this.changeToNext; |
| 198 | menuChooseOk.doLeft = this.changeToPrev; |
209 | menuChooseOk.doLeft = this.changeToPrev; |
| - | 210 | menuChooseOk.doPress = this.doBooking; |
|
| 199 | 211 | ||
| 200 | /* connect the items as a linked list */ |
212 | /* connect the items as a linked list */ |
| 201 | menuChooseCancel.setNextItem(menuChooseFrom); |
213 | menuChooseCancel.setNextItem(menuChooseFrom); |
| 202 | menuChooseCancel.setPrevItem(menuChooseOk); |
214 | menuChooseCancel.setPrevItem(menuChooseOk); |
| 203 | menuChooseCancel.setDescItem(this.bookMenuItem); |
215 | menuChooseCancel.setDescItem(this.bookMenuItem); |
| 204 | /* set the function that shall be executed when knob is turned */ |
216 | /* set the function that shall be executed when knob is turned */ |
| 205 | menuChooseCancel.doRight = this.changeToNext; |
217 | menuChooseCancel.doRight = this.changeToNext; |
| 206 | menuChooseCancel.doLeft = this.changeToPrev; |
218 | menuChooseCancel.doLeft = this.changeToPrev; |
| 207 | menuChooseCancel.doPress = this.changeToDesc; |
219 | menuChooseCancel.doPress = this.changeToDesc; |
| 208 | 220 | ||
| 209 | /* connect the items as a linked list */ |
221 | /* connect the items as a linked list */ |
| Line 211... | Line 223... | ||
| 211 | menuChooseFrom.setPrevItem(menuChooseCancel); |
223 | menuChooseFrom.setPrevItem(menuChooseCancel); |
| 212 | /* set the function that shall be executed when knob is turned */ |
224 | /* set the function that shall be executed when knob is turned */ |
| 213 | menuChooseFrom.doRight = this.changeToNext; |
225 | menuChooseFrom.doRight = this.changeToNext; |
| 214 | menuChooseFrom.doLeft = this.changeToPrev; |
226 | menuChooseFrom.doLeft = this.changeToPrev; |
| 215 | menuChooseFrom.doPress = this.changeToDesc; |
227 | menuChooseFrom.doPress = this.changeToDesc; |
| 216 | 228 | ||
| 217 | /* create the menuitem where you can modify the to-time */ |
229 | /* create the menuitem where you can modify the to-time */ |
| 218 | var menuSetTo = new MenuItem(this); |
230 | var menuSetTo = new MenuItem(this); |
| 219 | menuSetTo.doUpdate = this.setBookTimeTo; |
231 | menuSetTo.doUpdate = this.setBookTimeTo; |
| 220 | menuSetTo.displayData[0] = this.lcdCenterText("Set end time"); |
232 | menuSetTo.displayData[0] = this.lcdCenterText("Set end time"); |
| 221 | menuSetTo.doRight = this.incBookTimeTo; |
233 | menuSetTo.doRight = this.incBookTimeTo; |
| Line 234... | Line 246... | ||
| 234 | menuSetFrom.setDescItem(menuChooseFrom); |
246 | menuSetFrom.setDescItem(menuChooseFrom); |
| 235 | menuChooseFrom.setDescItem(menuSetFrom); |
247 | menuChooseFrom.setDescItem(menuSetFrom); |
| 236 | 248 | ||
| 237 | } |
249 | } |
| 238 | 250 | ||
| - | 251 | Display.prototype.exchangeCalendarBookCallback = function(shortname, data) |
|
| - | 252 | { |
|
| - | 253 | if (shortname == this.shortName) |
|
| - | 254 | { |
|
| - | 255 | //FIXME check if data contains error tag and error message, print to log and keep previous data? |
|
| - | 256 | if (data.result) |
|
| - | 257 | { |
|
| - | 258 | if (data.error) |
|
| - | 259 | { |
|
| - | 260 | this.bookResultMenuItem.displayData[0] = this.lcdCenterText("Booking failed"); |
|
| - | 261 | log("Display: got this error from exchange server: " + data.error + "\n"); |
|
| - | 262 | } |
|
| - | 263 | else |
|
| - | 264 | { |
|
| - | 265 | this.bookResultMenuItem.displayData[0] = this.lcdCenterText("Booking succeeded"); |
|
| - | 266 | ||
| - | 267 | /* do an exchange lookup */ |
|
| - | 268 | this.exchangeCalendar.lookup(this.shortName); |
|
| - | 269 | } |
|
| - | 270 | ||
| - | 271 | } |
|
| - | 272 | else if (data.error) |
|
| - | 273 | { |
|
| - | 274 | this.bookResultMenuItem.displayData[0] = this.lcdCenterText("Booking failed"); |
|
| - | 275 | log("Display: got this error from exchange.php: " + data.error + "\n"); |
|
| - | 276 | } |
|
| - | 277 | this.updateDisplay(); |
|
| - | 278 | } |
|
| - | 279 | } |
|
| - | 280 | ||
| 239 | Display.prototype. |
281 | Display.prototype.doBooking = function() |
| - | 282 | { |
|
| - | 283 | this.parentDisplay.bookResultMenuItem.displayData[0] = this.parentDisplay.lcdCenterText("Booking..."); |
|
| - | 284 | if (this.descItem) |
|
| - | 285 | { |
|
| - | 286 | this.parentDisplay.currentMenuItem = this.descItem; |
|
| - | 287 | } |
|
| - | 288 | //this.parentDisplay.changeToDesc(); |
|
| - | 289 | ||
| - | 290 | var bookFrom = this.parentDisplay.bookFromTime.getTimeShortFormated().replace(".",":"); |
|
| - | 291 | var bookTo = this.parentDisplay.bookToTime.getTimeShortFormated().replace(".",":"); |
|
| - | 292 | this.parentDisplay.exchangeCalendarBook.book(this.parentDisplay.shortName, bookFrom, bookTo); |
|
| - | 293 | ||
| - | 294 | //bookFromTime bookToTime |
|
| - | 295 | } |
|
| - | 296 | ||
| - | 297 | Display.prototype.prepareBookingMenu = function() |
|
| 240 | { |
298 | { |
| 241 | this.parentDisplay.bookFromTime = new Date(); |
299 | this.parentDisplay.bookFromTime = new Date(); |
| 242 | this.parentDisplay.bookToTime = new Date(); |
300 | this.parentDisplay.bookToTime = new Date(); |
| 243 | //this.bookFromTime.setHours(8); |
301 | //this.bookFromTime.setHours(8); |
| 244 | //this.bookToTime.setHours(8); |
302 | //this.bookToTime.setHours(8); |
| Line 314... | Line 372... | ||
| 314 | //FIXME: constraints? |
372 | //FIXME: constraints? |
| 315 | var now = new Date(); |
373 | var now = new Date(); |
| 316 | if (this.parentDisplay.bookFromTime.getHours() >= now.getHours()) |
374 | if (this.parentDisplay.bookFromTime.getHours() >= now.getHours()) |
| 317 | { |
375 | { |
| 318 | this.parentDisplay.bookFromTime.setMinutes(this.parentDisplay.bookFromTime.getMinutes() - bookingIncrease); |
376 | this.parentDisplay.bookFromTime.setMinutes(this.parentDisplay.bookFromTime.getMinutes() - bookingIncrease); |
| 319 | } |
377 | } |
| 320 | } |
378 | } |
| 321 | 379 | ||
| 322 | Display.prototype.setBookTimeFrom = function() |
380 | Display.prototype.setBookTimeFrom = function() |
| 323 | { |
381 | { |
| 324 | this.displayData[1] = " <"+this.parentDisplay.bookFromTime.getTimeShortFormated()+"> "; |
382 | this.displayData[1] = " <"+this.parentDisplay.bookFromTime.getTimeShortFormated()+"> "; |
| 325 | } |
383 | } |
| Line 427... | Line 485... | ||
| 427 | this.exchangeCalendarFirstMenuItem.setPrevItem(this.statusMenuItem); |
485 | this.exchangeCalendarFirstMenuItem.setPrevItem(this.statusMenuItem); |
| 428 | 486 | ||
| 429 | } |
487 | } |
| 430 | /* to link in the newly created menuitems with exchangeinformation the display must be showing |
488 | /* to link in the newly created menuitems with exchangeinformation the display must be showing |
| 431 | either the statusmenu or the bookingmenu */ |
489 | either the statusmenu or the bookingmenu */ |
| 432 | if (this.currentMenuItem == this.statusMenuItem || this.currentMenuItem == this.bookMenuItem) |
490 | if (this.currentMenuItem == this.statusMenuItem || this.currentMenuItem == this.bookMenuItem || this.currentMenuItem == this.bookResultMenuItem) |
| 433 | { |
491 | { |
| 434 | /* if there is one or more exchangemenuitems */ |
492 | /* if there is one or more exchangemenuitems */ |
| 435 | if (this.exchangeCalendarFirstMenuItem && this.exchangeCalendarLastMenuItem) |
493 | if (this.exchangeCalendarFirstMenuItem && this.exchangeCalendarLastMenuItem) |
| 436 | { |
494 | { |
| 437 | this.statusMenuItem.setNextItem(this.exchangeCalendarFirstMenuItem); |
495 | this.statusMenuItem.setNextItem(this.exchangeCalendarFirstMenuItem); |
| Line 450... | Line 508... | ||
| 450 | Display.prototype.replaceAumlauts = function(intext) |
508 | Display.prototype.replaceAumlauts = function(intext) |
| 451 | { |
509 | { |
| 452 | intext = intext.replace(/Å/, "A"); |
510 | intext = intext.replace(/Å/, "A"); |
| 453 | intext = intext.replace(/å/, "a"); |
511 | intext = intext.replace(/å/, "a"); |
| 454 | intext = intext.replace(/Ä/, "A"); |
512 | intext = intext.replace(/Ä/, "A"); |
| 455 | intext = intext.replace(/ä/, "a"); |
513 | intext = intext.replace(/ä/, "a"); // String.fromCharCode(97)); //225 |
| 456 | intext = intext.replace(/Ö/, "O"); |
514 | intext = intext.replace(/Ö/, "O"); |
| 457 | intext = intext.replace(/ö/, "o"); |
515 | intext = intext.replace(/ö/, "o"); |
| 458 | return intext; |
516 | return intext; |
| 459 | } |
517 | } |
| 460 | 518 | ||
| 461 | Display.prototype.softPwmOnline = function() |
519 | Display.prototype.softPwmOnline = function() |
| 462 | { |
520 | { |
| 463 | } |
521 | } |
| 464 | 522 | ||
| 465 | Display.prototype.rotaryOnline = function() |
523 | Display.prototype.rotaryOnline = function() |
| Line 588... | Line 646... | ||
| 588 | /* Go to main screen (time) */ |
646 | /* Go to main screen (time) */ |
| 589 | this.currentMenuItem = this.statusMenuItem; |
647 | this.currentMenuItem = this.statusMenuItem; |
| 590 | 648 | ||
| 591 | /* update the info on display */ |
649 | /* update the info on display */ |
| 592 | this.updateDisplay(); |
650 | this.updateDisplay(); |
| - | 651 | ||
| - | 652 | this.mainScreenCnt = 0; |
|
| 593 | } |
653 | } |
| 594 | 654 | ||
| 595 | if (this.screenSaverCnt > screenSaverTimeout/5) |
655 | if (this.screenSaverCnt > screenSaverTimeout/5) |
| 596 | { |
656 | { |
| 597 | 657 | ||
| - | 658 | this.screenSaverCnt = 0; |
|
| 598 | } |
659 | } |
| 599 | 660 | ||
| 600 | if (this.exchangeUpdateCnt > exchangeUpdateTimeout/5) |
661 | if (this.exchangeUpdateCnt > exchangeUpdateTimeout/5) |
| 601 | { |
662 | { |
| 602 | /* update the info on display */ |
663 | /* update the info on display */ |