Subversion Repositories HomeAutomation

Rev

Rev 1212 | Rev 1228 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. loadScript("Logic/MenuItem.js");
  3.  
  4. function Display(type, name, id)
  5. {
  6.     /* We must always call the parent constructor, initialization
  7.        of variables could be done here, but initialize is a better place */
  8.     this.Service(type, name, id);
  9. }
  10.  
  11. /* We inherit from Service with this call, it must always be next
  12.    after the constructor */
  13. extend(Display, Service);
  14.  
  15. /* Declaration of instance variables, for static variables remove prototype */
  16.  
  17. /* format: dat objects, just use the time */
  18. Display.prototype.bookFromTime = null;
  19. Display.prototype.bookToTime = null;
  20.  
  21. /* the shortname for this exchangeobject */
  22. Display.prototype.shortName = null;
  23.  
  24. /* the name for this display (shown on first screen) */
  25. Display.prototype.niceName = null;
  26.  
  27. /* The display should regulary update and store the calendar */
  28. Display.prototype.exchangeData = null;
  29.  
  30. Display.prototype.myLCDService = null;
  31. Display.prototype.myRotaryService = null;
  32. Display.prototype.mySoftPwmService = null;
  33. Display.prototype.myInterval = null;
  34.  
  35. /*  */
  36. Display.prototype.exchangeCalendar = null;
  37. /*  */
  38. Display.prototype.exchangeCalendarFirstMenuItem = null;
  39. Display.prototype.exchangeCalendarLastMenuItem = null;
  40. Display.prototype.statusMenuItem = null;
  41. Display.prototype.bookMenuItem = null;
  42. Display.prototype.bookResultMenuItem = null;
  43.  
  44.  
  45. /* The currently displayed menuitem */
  46. Display.prototype.currentMenuItem = null;
  47.  
  48. /* counter for calling exchange update */
  49. Display.prototype.exchangeUpdateCnt = null;
  50.  
  51. /* counter for going to screensaver */
  52. Display.prototype.screenSaverCnt = null;
  53.  
  54. /* counter for going to main screen */
  55. Display.prototype.mainScreenCnt = null;
  56.  
  57. const exchangeUpdateTimeout = 50;
  58. const mainScreenTimeout = 40;
  59. const screenSaverTimeout = 120;
  60.  
  61. const bookingIncrease = 15;
  62.  
  63. /* This function must always be declared, this is where all the startup code
  64.    should be placed. Gets called with arguments like what ids to use etc. */
  65. Display.prototype.initialize = function(initialArguments)
  66. {
  67.     /* We must always call the parent initialize */
  68.     this.Service.prototype.initialize.call(this, initialArguments);
  69.  
  70.     /* This is used for function declarations like the callbacks below */
  71.     var self = this;
  72.  
  73.     if (!this.myInitialArguments["HD44789"])
  74.     {
  75.         log(this.myName + ":" + this.myId + "> Failed to initialize, HD44789-config missing from config.\n");
  76.         return;
  77.     }
  78.    
  79.     if (!this.myInitialArguments["Rotary"])
  80.     {
  81.         log(this.myName + ":" + this.myId + "> Failed to initialize, Rotary-config missing from config.\n");
  82.         return;
  83.     }
  84.    
  85.     if (!this.myInitialArguments["softPWM"])
  86.     {
  87.         log(this.myName + ":" + this.myId + "> Failed to initialize, softPWM-config missing from config.\n");
  88.         return;
  89.     }
  90.    
  91.     if (!this.myInitialArguments["Name"])
  92.     {
  93.         log(this.myName + ":" + this.myId + "> Failed to initialize, Name-config missing from config.\n");
  94.         return;
  95.     }
  96.     this.niceName = this.myInitialArguments["Name"];
  97.  
  98.     if (!this.myInitialArguments["ShortName"])
  99.     {
  100.         log(this.myName + ":" + this.myId + "> Failed to initialize, Name-config missing from config.\n");
  101.         return;
  102.     }
  103.     this.shortName = this.myInitialArguments["ShortName"];
  104.    
  105.     this.screenSaverCnt = 0;
  106.     this.mainScreenCnt = 0;
  107.     this.exchangeUpdateCnt = exchangeUpdateTimeout-10;
  108.    
  109.     /* Get the LCD service that we want from the ServiceManager, it takes type, service name, service id */
  110.     this.myLCDService = ServiceManager.getService("Can", "HD44789", this.myInitialArguments["HD44789"]["Id"]);
  111.     /* Add a callback for when the service goes online */
  112.     this.myLCDService.registerEventCallback("online", function(args) { self.lcdOnline(); });
  113.     /* If the service is already online we should call the handler here */
  114.     this.lcdOnline();
  115.     /* Add a callback for when the service goes offline */
  116.     this.myLCDService.registerEventCallback("offline", function(args) { self.lcdOffline(); });
  117.    
  118.     /* Get the Rotary service that we want from the ServiceManager, it takes type, service name, service id */
  119.     this.myRotaryService = ServiceManager.getService("Can", "Rotary", this.myInitialArguments["Rotary"]["Id"]);
  120.     /* Add a callback for when the encoder reports a new position */
  121.     this.myRotaryService.registerEventCallback("newPosition", function(args) { self.rotaryPosUpdate(args); });
  122.     /* Add a callback for when the encoder reports a new button status */
  123.     this.myRotaryService.registerEventCallback("newBtnStatus", function(args) { self.rotaryBtnUpdate(args); });
  124.     /* Add a callback for when the service goes online */
  125.     this.myRotaryService.registerEventCallback("online", function(args) { self.rotaryOnline(); });
  126.     /* If the service is already online we should call the handler here */
  127.     this.rotaryOnline();
  128.    
  129.     /* Get the softPWM service that we want from the ServiceManager, it takes type, service name, service id */
  130.     this.mySoftPwmService = ServiceManager.getService("Can", "softPWM", this.myInitialArguments["softPWM"]["Id"]);
  131.     /* Add a callback for when the service goes online */
  132.     this.mySoftPwmService.registerEventCallback("online", function(args) { self.softPwmOnline(); });
  133.     /* If the service is already online we should call the handler here */
  134.     this.softPwmOnline();
  135.    
  136.     this.exchangeCalendar = new ExchangeCalendar(function(shortname, data) { self.exchangeCalendarLookupCallback(shortname, data); });
  137.     this.exchangeCalendarBook = new ExchangeCalendar(function(shortname, data) { self.exchangeCalendarBookCallback(shortname, data); });
  138.    
  139.     /* create the first menu item */
  140.     this.statusMenuItem = new MenuItem(this);
  141.     this.statusMenuItem.displayData[0] = this.lcdCenterText(this.niceName);
  142.     this.statusMenuItem.doUpdate = this.updateStatusMenuItem;
  143.     this.currentMenuItem = this.statusMenuItem;
  144.    
  145.     /* create the menuitem where you can choose to enter the booking sub-menu */
  146.     this.bookMenuItem = new MenuItem(this);
  147.     this.bookMenuItem.displayData[0] = this.lcdCenterText("Book room");
  148.     this.bookMenuItem.displayData[1] = this.lcdCenterText("(Push button)");
  149.     this.bookMenuItem.doUpdate = this.updateBookMenuItem;
  150.  
  151.     /* connect the items as a linked list */
  152.     this.statusMenuItem.setNextItem(this.bookMenuItem);
  153.     this.statusMenuItem.setPrevItem(this.bookMenuItem);
  154.     /* set the function that shall be executed when knob is turned */
  155.     this.statusMenuItem.doRight = this.changeToNext;
  156.     this.statusMenuItem.doLeft = this.changeToPrev;
  157.    
  158.     /* connect the items as a linked list */
  159.     this.bookMenuItem.setNextItem(this.statusMenuItem);
  160.     this.bookMenuItem.setPrevItem(this.statusMenuItem);
  161.     /* set the function that shall be executed when knob is turned */
  162.     this.bookMenuItem.doRight = this.changeToNext;
  163.     this.bookMenuItem.doLeft = this.changeToPrev;
  164.    
  165.     /* create the menuitem where you can choose the to-time */
  166.     var menuChooseTo = new MenuItem(this);
  167.     menuChooseTo.displayData[1] = this.lcdCenterText(" Ok     Cancel ");
  168.     menuChooseTo.doUpdate = this.chooseBookTimeTo;
  169.    
  170.     this.bookMenuItem.doPress = this.prepareBookingMenu;
  171.     this.bookMenuItem.setDescItem(menuChooseTo);
  172.    
  173.     /* create the menuitem where you can choose to book the room with OK */
  174.     var menuChooseOk = new MenuItem(this);
  175.     menuChooseOk.displayData[1] = this.lcdCenterText("<Ok>    Cancel ");
  176.     menuChooseOk.doUpdate = this.setBookTime;
  177.  
  178.     /* create the menuitem where you can choose to cancel the booking */
  179.     var menuChooseCancel = new MenuItem(this);
  180.     menuChooseCancel.displayData[1] = this.lcdCenterText(" Ok    <Cancel>");
  181.     menuChooseCancel.doUpdate = this.setBookTime;
  182.  
  183.     /* create the menuitem where you can choose the from-time */
  184.     var menuChooseFrom = new MenuItem(this);
  185.     menuChooseFrom.displayData[1] = this.lcdCenterText(" Ok     Cancel ");
  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;
  194.  
  195.     /* connect the items as a linked list */
  196.     menuChooseTo.setNextItem(menuChooseOk);
  197.     menuChooseTo.setPrevItem(menuChooseFrom);
  198.     /* set the function that shall be executed when knob is turned */
  199.     menuChooseTo.doRight = this.changeToNext;
  200.     menuChooseTo.doLeft = this.changeToPrev;
  201.     menuChooseTo.doPress = this.changeToDesc;
  202.  
  203.     /* connect the items as a linked list */
  204.     menuChooseOk.setNextItem(menuChooseCancel);
  205.     menuChooseOk.setPrevItem(menuChooseTo);
  206.     menuChooseOk.setDescItem(this.bookResultMenuItem);
  207.     /* set the function that shall be executed when knob is turned */
  208.     menuChooseOk.doRight = this.changeToNext;
  209.     menuChooseOk.doLeft = this.changeToPrev;
  210.     menuChooseOk.doPress = this.doBooking;
  211.  
  212.     /* connect the items as a linked list */
  213.     menuChooseCancel.setNextItem(menuChooseFrom);
  214.     menuChooseCancel.setPrevItem(menuChooseOk);
  215.     menuChooseCancel.setDescItem(this.bookMenuItem);
  216.     /* set the function that shall be executed when knob is turned */
  217.     menuChooseCancel.doRight = this.changeToNext;
  218.     menuChooseCancel.doLeft = this.changeToPrev;
  219.     menuChooseCancel.doPress = this.changeToDesc;
  220.  
  221.     /* connect the items as a linked list */
  222.     menuChooseFrom.setNextItem(menuChooseTo);
  223.     menuChooseFrom.setPrevItem(menuChooseCancel);
  224.     /* set the function that shall be executed when knob is turned */
  225.     menuChooseFrom.doRight = this.changeToNext;
  226.     menuChooseFrom.doLeft = this.changeToPrev;
  227.     menuChooseFrom.doPress = this.changeToDesc;
  228.  
  229.     /* create the menuitem where you can modify the to-time */
  230.     var menuSetTo = new MenuItem(this);
  231.     menuSetTo.doUpdate = this.setBookTimeTo;
  232.     menuSetTo.displayData[0] = this.lcdCenterText("Set end time");
  233.     menuSetTo.doRight = this.incBookTimeTo;
  234.     menuSetTo.doLeft = this.decBookTimeTo;
  235.     menuSetTo.doPress = this.changeToDesc;
  236.     menuSetTo.setDescItem(menuChooseTo);
  237.     menuChooseTo.setDescItem(menuSetTo);
  238.  
  239.     /* create the menuitem where you can modify the from-time */
  240.     var menuSetFrom = new MenuItem(this);
  241.     menuSetFrom.doUpdate = this.setBookTimeFrom;
  242.     menuSetFrom.displayData[0] = this.lcdCenterText("Set start time");
  243.     menuSetFrom.doRight = this.incBookTimeFrom;
  244.     menuSetFrom.doLeft = this.decBookTimeFrom;
  245.     menuSetFrom.doPress = this.changeToDesc;
  246.     menuSetFrom.setDescItem(menuChooseFrom);
  247.     menuChooseFrom.setDescItem(menuSetFrom);
  248.  
  249. }
  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.  
  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()
  298. {
  299.     this.parentDisplay.bookFromTime = new Date();
  300.     this.parentDisplay.bookToTime = new Date();
  301.     //this.bookFromTime.setHours(8);
  302.     //this.bookToTime.setHours(8);
  303.     if (this.parentDisplay.bookFromTime.getMinutes() < 30)
  304.     {
  305.         this.parentDisplay.bookFromTime.setMinutes(0);
  306.         this.parentDisplay.bookToTime.setMinutes(30);
  307.     }
  308.     else
  309.     {
  310.         this.parentDisplay.bookFromTime.setMinutes(30);
  311.         this.parentDisplay.bookToTime.setHours(this.parentDisplay.bookToTime.getHours()+1);
  312.         this.parentDisplay.bookToTime.setMinutes(0);
  313.     }
  314.  
  315.     this.parentDisplay.currentMenuItem = this.parentDisplay.currentMenuItem.descItem;
  316. }
  317.  
  318. Display.prototype.changeToDesc = function()
  319. {
  320.     if (this.descItem)
  321.     {
  322.         this.parentDisplay.currentMenuItem = this.descItem;
  323.     }
  324. }
  325.  
  326. Display.prototype.changeToNext = function()
  327. {
  328.     if (this.nextItem)
  329.     {
  330.         this.parentDisplay.currentMenuItem = this.nextItem;
  331.     }
  332. }
  333.  
  334. Display.prototype.changeToPrev = function()
  335. {
  336.     if (this.prevItem)
  337.     {
  338.         this.parentDisplay.currentMenuItem = this.prevItem;
  339.     }
  340. }
  341.  
  342. Display.prototype.incBookTimeTo = function()
  343. {
  344.     //FIXME: constraints?
  345.     if (this.parentDisplay.bookToTime.getHours() < 23)
  346.     {
  347.         this.parentDisplay.bookToTime.setMinutes(this.parentDisplay.bookToTime.getMinutes() + bookingIncrease);
  348.     }
  349. }
  350.  
  351. Display.prototype.decBookTimeTo = function()
  352. {
  353.     //FIXME: constraints?
  354.     var now = new Date();
  355.     if (this.parentDisplay.bookToTime.getHours() >= now.getHours())
  356.     {
  357.         this.parentDisplay.bookToTime.setMinutes(this.parentDisplay.bookToTime.getMinutes() - bookingIncrease);
  358.     }
  359. }
  360.  
  361. Display.prototype.incBookTimeFrom = function()
  362. {
  363.     //FIXME: constraints?
  364.     if (this.parentDisplay.bookFromTime.getHours() < 23)
  365.     {
  366.         this.parentDisplay.bookFromTime.setMinutes(this.parentDisplay.bookFromTime.getMinutes() + bookingIncrease);
  367.     }
  368. }
  369.  
  370. Display.prototype.decBookTimeFrom = function()
  371. {
  372.     //FIXME: constraints?
  373.     var now = new Date();
  374.     if (this.parentDisplay.bookFromTime.getHours() >= now.getHours())
  375.     {
  376.         this.parentDisplay.bookFromTime.setMinutes(this.parentDisplay.bookFromTime.getMinutes() - bookingIncrease);
  377.     }
  378. }
  379.  
  380. Display.prototype.setBookTimeFrom = function()
  381. {
  382.     this.displayData[1] = "      <"+this.parentDisplay.bookFromTime.getTimeShortFormated()+">       ";
  383. }
  384.  
  385. Display.prototype.setBookTimeTo = function()
  386. {
  387.     this.displayData[1] = "      <"+this.parentDisplay.bookToTime.getTimeShortFormated()+">       ";
  388. }
  389.  
  390. Display.prototype.chooseBookTimeTo = function()
  391. {
  392.     this.displayData[0] = "  "+this.parentDisplay.bookFromTime.getTimeShortFormated()+"  - <"
  393.                                 +this.parentDisplay.bookToTime.getTimeShortFormated()+">  ";
  394. }
  395.  
  396. Display.prototype.chooseBookTimeFrom = function()
  397. {
  398.     this.displayData[0] = " <"+this.parentDisplay.bookFromTime.getTimeShortFormated()+"> -  "
  399.                                 +this.parentDisplay.bookToTime.getTimeShortFormated()+"   ";
  400. }
  401.  
  402. Display.prototype.setBookTime = function()
  403. {
  404.     this.displayData[0] = "  "+this.parentDisplay.bookFromTime.getTimeShortFormated()+"  -  "
  405.                                 +this.parentDisplay.bookToTime.getTimeShortFormated()+"   ";
  406. }
  407.  
  408. Display.prototype.updateStatusMenuItem = function()
  409. {
  410.     var date = new Date();
  411.     var dateAndTime = "" + date.getTimeShortFormated();
  412.     this.displayData[1] = "       " + dateAndTime + "        ";
  413. }
  414.  
  415. Display.prototype.updateBookMenuItem = function()
  416. {
  417.     if (this.parentDisplay.exchangeCalendarFirstMenuItem && this.parentDisplay.exchangeCalendarLastMenuItem)
  418.     {
  419.         this.parentDisplay.statusMenuItem.setNextItem(this.parentDisplay.exchangeCalendarFirstMenuItem);
  420.         this.parentDisplay.bookMenuItem.setPrevItem(this.parentDisplay.exchangeCalendarLastMenuItem);
  421.     }
  422.     else
  423.     {
  424.         this.parentDisplay.statusMenuItem.setNextItem(this.parentDisplay.bookMenuItem);
  425.         this.parentDisplay.bookMenuItem.setPrevItem(this.parentDisplay.statusMenuItem);
  426.     }
  427. }
  428.  
  429. Display.prototype.exchangeCalendarLookupCallback = function(shortname, data)
  430. {
  431. //log("callback: "+shortname+" \n");
  432.     if (shortname == this.shortName)
  433.     {
  434.         //FIXME check if data contains error tag and error message, print to log and keep previous data?
  435.         if (data.error)
  436.         {
  437.             log("Display: got this error from exchange.php: " + data.error + "\n");
  438.         }
  439.         else
  440.         {
  441.             this.exchangeData = data;
  442.             this.createCalendarMenu();
  443.         }
  444.     }
  445. }
  446.  
  447. /* this function parses calendar data from exchange-script and creates a menu */
  448. Display.prototype.createCalendarMenu = function()
  449. {
  450.     this.exchangeCalendarLastMenuItem = null;
  451.     this.exchangeCalendarFirstMenuItem = null;
  452.    
  453. //log("createCalendar \n");
  454.     if (this.exchangeData)
  455.     {
  456. //log("have data \n");
  457.         var lastMenuItem;
  458.         for (var i = 0; i < this.exchangeData.meetings.length; i++)
  459.         {
  460. //log("looping \n");
  461.             /* create the menuitem for a calendar meeting */
  462.             var menu = new MenuItem(this);
  463.             menu.displayData[0] = this.lcdCenterText(this.replaceAumlauts(this.exchangeData.meetings[i].subject));
  464.             menu.displayData[1] = this.lcdCenterText(this.exchangeData.meetings[i].start.replace(":",".") + " - "
  465.                                         + this.exchangeData.meetings[i].end.replace(":","."));
  466.             menu.doRight = this.changeToNext;
  467.             menu.doLeft = this.changeToPrev;
  468.            
  469.             if (i == 0)
  470.             {
  471.                 this.exchangeCalendarFirstMenuItem = menu;
  472.             }
  473.             else
  474.             {
  475.                 menu.setPrevItem(lastMenuItem);
  476.                 lastMenuItem.setNextItem(menu);
  477.             }
  478.            
  479.             lastMenuItem = menu;
  480.         }
  481.         if (lastMenuItem)
  482.         {
  483.             this.exchangeCalendarLastMenuItem = lastMenuItem;
  484.             this.exchangeCalendarLastMenuItem.setNextItem(this.bookMenuItem);
  485.             this.exchangeCalendarFirstMenuItem.setPrevItem(this.statusMenuItem);
  486.        
  487.         }
  488.         /* to link in the newly created menuitems with exchangeinformation the display must be showing
  489.            either the statusmenu or the bookingmenu */
  490.         if (this.currentMenuItem == this.statusMenuItem || this.currentMenuItem == this.bookMenuItem || this.currentMenuItem == this.bookResultMenuItem)
  491.         {
  492.             /* if there is one or more exchangemenuitems */
  493.             if (this.exchangeCalendarFirstMenuItem && this.exchangeCalendarLastMenuItem)
  494.             {
  495.                 this.statusMenuItem.setNextItem(this.exchangeCalendarFirstMenuItem);
  496.                 this.bookMenuItem.setPrevItem(this.exchangeCalendarLastMenuItem);
  497.             }
  498.             /* if not then link statusmenu to bookingmenu */
  499.             else
  500.             {
  501.                 this.statusMenuItem.setNextItem(this.bookMenuItem);
  502.                 this.bookMenuItem.setPrevItem(this.statusMenuItem);
  503.             }
  504.         }
  505.     }
  506. }
  507.  
  508. Display.prototype.replaceAumlauts = function(intext)
  509. {
  510.     intext = intext.replace(/Å/, "A");
  511.     intext = intext.replace(/å/, "a");
  512.     intext = intext.replace(/Ä/, "A");
  513.     intext = intext.replace(/ä/, "a");     //  String.fromCharCode(97)); //225
  514.     intext = intext.replace(/Ö/, "O");
  515.     intext = intext.replace(/ö/, "o");
  516.     return intext;
  517. }
  518.  
  519. Display.prototype.softPwmOnline = function()
  520. {
  521. }
  522.  
  523. Display.prototype.rotaryOnline = function()
  524. {
  525. }
  526.  
  527. Display.prototype.rotaryPosUpdate = function(SwitchId)
  528. {
  529.     this.screenSaverCnt = 0;
  530.     this.mainScreenCnt = 0;
  531.     for (var i = 0; i < this.myRotaryService.getSteps(SwitchId); i++)
  532.     {
  533.         if (this.myRotaryService.getDirection(SwitchId) == "Clockwise")
  534.         {
  535.             if (this.currentMenuItem.doRight)
  536.             {
  537.                 this.currentMenuItem.doRight();
  538.             }
  539.         }
  540.         else
  541.         {
  542.             if (this.currentMenuItem.doLeft)
  543.             {
  544.                 this.currentMenuItem.doLeft();
  545.             }
  546.         }
  547.     }
  548.    
  549.     this.updateDisplay();
  550. }
  551.  
  552. Display.prototype.rotaryBtnUpdate = function(SwitchId)
  553. {
  554.     this.screenSaverCnt = 0;
  555.     this.mainScreenCnt = 0;
  556.     if (this.myRotaryService.getButtonStatus(SwitchId) == "Released")
  557.     {
  558.         if (this.currentMenuItem.doPress)
  559.         {
  560.             this.currentMenuItem.doPress();
  561.         }
  562.         this.updateDisplay();
  563.     }
  564. }
  565.  
  566. Display.prototype.updateDisplay = function()
  567. {
  568.     /* see if the current menuitem wants to update itself */
  569.     if (this.currentMenuItem.doUpdate)
  570.     {
  571.         this.currentMenuItem.doUpdate();
  572.     }
  573.  
  574.     /* Clear the LCD screen */
  575.     //this.myLCDService.clearScreen();
  576.    
  577.     /* send the data for the current menuitem to display */
  578.     for (var i = 0; i < this.currentMenuItem.displayData.length; i++)
  579.     {
  580.         this.myLCDService.printText(0, i, this.currentMenuItem.displayData[i]);
  581.     }
  582.    
  583. }
  584.  
  585. Display.prototype.lcdCenterText = function(text)
  586. {
  587.     returnText = text;
  588.     var displayWidth = 20;  //this.myLCDService.getWidth();
  589.     /* pad on both sides with spaces to displayWidth */
  590.     returnText = text.pad(displayWidth, " ", 2);
  591.    
  592.     return returnText;
  593. }
  594.  
  595. Display.prototype.lcdOffline = function()
  596. {
  597.     /* If we have no interval timer running do nothing */
  598.     if (this.myInterval != null)
  599.     {
  600.         /* Stop the interval */
  601.         this.myInterval.stop();
  602.     }
  603. }
  604.  
  605. Display.prototype.lcdOnline = function()
  606. {
  607.     /* If service is not online do nothing */
  608.     if (this.myLCDService.isOnline())
  609.     {
  610.         /* Clear the LCD screen */
  611.         this.myLCDService.clearScreen();
  612.         /* Set backlight to max */
  613.         this.myLCDService.setBacklight(255);
  614.  
  615.         /* If we have no interval timer running start it */
  616.         if (this.myInterval == null)
  617.         {
  618.             var self = this;
  619.        
  620.             /* Start interval timer for our printout. Arguments are the callback function and time in milliseconds */
  621.             this.myInterval = new Interval(function() { self.timerUpdate() }, 5000);
  622.         }
  623.        
  624.         this.myInterval.start();
  625.        
  626.         this.timerUpdate();
  627.     }
  628. }
  629.  
  630. Display.prototype.setLED = function(red, green, blue)
  631. {
  632.    
  633. }
  634.  
  635. Display.prototype.timerUpdate = function()
  636. {
  637.     /* If LCD service is not online do nothing */
  638.     if (this.myLCDService.isOnline())
  639.     {
  640.         this.screenSaverCnt++;
  641.         this.mainScreenCnt++;
  642.         this.exchangeUpdateCnt++;
  643.  
  644.         if (this.mainScreenCnt > mainScreenTimeout/5)
  645.         {
  646.             /* Go to main screen (time) */
  647.             this.currentMenuItem = this.statusMenuItem;
  648.  
  649.             /* update the info on display */
  650.             this.updateDisplay();
  651.  
  652.             this.mainScreenCnt = 0;
  653.         }
  654.        
  655.         if (this.screenSaverCnt > screenSaverTimeout/5)
  656.         {
  657.            
  658.             this.screenSaverCnt = 0;
  659.         }
  660.  
  661.         if (this.exchangeUpdateCnt > exchangeUpdateTimeout/5)
  662.         {
  663.             /* update the info on display */
  664.             this.updateDisplay();
  665.            
  666.             /* do an exchange lookup */
  667.             this.exchangeCalendar.lookup(this.shortName);
  668.            
  669.             this.exchangeUpdateCnt = 0;
  670.         }
  671.        
  672.     }
  673.    
  674.     /*if (this.mySoftPwmService.isOnline())
  675.     {
  676.         this.mySoftPwmService.setPWMValue(0, 0);
  677.         this.mySoftPwmService.setPWMValue(11, 1);
  678.         this.mySoftPwmService.setPWMValue(11, 2);
  679.     }*/
  680. }
  681.  
  682.