Subversion Repositories HomeAutomation

Rev

Rev 1226 | Rev 1231 | 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.                 log("Display: Successfully booked room\n");
  267.                
  268.                 /* do an exchange lookup */
  269.                 this.exchangeCalendar.lookup(this.shortName);
  270.             }
  271.            
  272.         }
  273.         else if (data.error)
  274.         {
  275.             this.bookResultMenuItem.displayData[0] = this.lcdCenterText("Booking failed");
  276.             log("Display: got this error from exchange.php: " + data.error + "\n");
  277.         }
  278.         this.updateDisplay();
  279.     }
  280. }
  281.  
  282. Display.prototype.doBooking = function()
  283. {
  284.     this.parentDisplay.bookResultMenuItem.displayData[0] = this.parentDisplay.lcdCenterText("Booking...");
  285.     if (this.descItem)
  286.     {
  287.         this.parentDisplay.currentMenuItem = this.descItem;
  288.     }
  289.     //this.parentDisplay.changeToDesc();
  290.  
  291.     var bookFrom = this.parentDisplay.bookFromTime.getTimeShortFormated().replace(".",":");
  292.     var bookTo = this.parentDisplay.bookToTime.getTimeShortFormated().replace(".",":");
  293.     this.parentDisplay.exchangeCalendarBook.book(this.parentDisplay.shortName, bookFrom, bookTo);
  294.    
  295.     //bookFromTime bookToTime
  296. }
  297.  
  298. Display.prototype.prepareBookingMenu = function()
  299. {
  300.     this.parentDisplay.bookFromTime = new Date();
  301.     this.parentDisplay.bookToTime = new Date();
  302.     //this.bookFromTime.setHours(8);
  303.     //this.bookToTime.setHours(8);
  304.     if (this.parentDisplay.bookFromTime.getMinutes() < 30)
  305.     {
  306.         this.parentDisplay.bookFromTime.setMinutes(0);
  307.         this.parentDisplay.bookToTime.setMinutes(30);
  308.     }
  309.     else
  310.     {
  311.         this.parentDisplay.bookFromTime.setMinutes(30);
  312.         this.parentDisplay.bookToTime.setHours(this.parentDisplay.bookToTime.getHours()+1);
  313.         this.parentDisplay.bookToTime.setMinutes(0);
  314.     }
  315.  
  316.     this.parentDisplay.currentMenuItem = this.parentDisplay.currentMenuItem.descItem;
  317. }
  318.  
  319. Display.prototype.changeToDesc = function()
  320. {
  321.     if (this.descItem)
  322.     {
  323.         this.parentDisplay.currentMenuItem = this.descItem;
  324.     }
  325. }
  326.  
  327. Display.prototype.changeToNext = function()
  328. {
  329.     if (this.nextItem)
  330.     {
  331.         this.parentDisplay.currentMenuItem = this.nextItem;
  332.     }
  333. }
  334.  
  335. Display.prototype.changeToPrev = function()
  336. {
  337.     if (this.prevItem)
  338.     {
  339.         this.parentDisplay.currentMenuItem = this.prevItem;
  340.     }
  341. }
  342.  
  343. Display.prototype.incBookTimeTo = function()
  344. {
  345.     //FIXME: constraints?
  346.     if (this.parentDisplay.bookToTime.getHours() < 23)
  347.     {
  348.         this.parentDisplay.bookToTime.setMinutes(this.parentDisplay.bookToTime.getMinutes() + bookingIncrease);
  349.     }
  350. }
  351.  
  352. Display.prototype.decBookTimeTo = function()
  353. {
  354.     //FIXME: constraints?
  355.     var now = new Date();
  356.     if (this.parentDisplay.bookToTime.getHours() >= now.getHours())
  357.     {
  358.         this.parentDisplay.bookToTime.setMinutes(this.parentDisplay.bookToTime.getMinutes() - bookingIncrease);
  359.     }
  360. }
  361.  
  362. Display.prototype.incBookTimeFrom = function()
  363. {
  364.     //FIXME: constraints?
  365.     if (this.parentDisplay.bookFromTime.getHours() < 23)
  366.     {
  367.         this.parentDisplay.bookFromTime.setMinutes(this.parentDisplay.bookFromTime.getMinutes() + bookingIncrease);
  368.     }
  369. }
  370.  
  371. Display.prototype.decBookTimeFrom = function()
  372. {
  373.     //FIXME: constraints?
  374.     var now = new Date();
  375.     if (this.parentDisplay.bookFromTime.getHours() >= now.getHours())
  376.     {
  377.         this.parentDisplay.bookFromTime.setMinutes(this.parentDisplay.bookFromTime.getMinutes() - bookingIncrease);
  378.     }
  379. }
  380.  
  381. Display.prototype.setBookTimeFrom = function()
  382. {
  383.     this.displayData[1] = "      <"+this.parentDisplay.bookFromTime.getTimeShortFormated()+">       ";
  384. }
  385.  
  386. Display.prototype.setBookTimeTo = function()
  387. {
  388.     this.displayData[1] = "      <"+this.parentDisplay.bookToTime.getTimeShortFormated()+">       ";
  389. }
  390.  
  391. Display.prototype.chooseBookTimeTo = function()
  392. {
  393.     this.displayData[0] = "  "+this.parentDisplay.bookFromTime.getTimeShortFormated()+"  - <"
  394.                                 +this.parentDisplay.bookToTime.getTimeShortFormated()+">  ";
  395. }
  396.  
  397. Display.prototype.chooseBookTimeFrom = function()
  398. {
  399.     this.displayData[0] = " <"+this.parentDisplay.bookFromTime.getTimeShortFormated()+"> -  "
  400.                                 +this.parentDisplay.bookToTime.getTimeShortFormated()+"   ";
  401. }
  402.  
  403. Display.prototype.setBookTime = function()
  404. {
  405.     this.displayData[0] = "  "+this.parentDisplay.bookFromTime.getTimeShortFormated()+"  -  "
  406.                                 +this.parentDisplay.bookToTime.getTimeShortFormated()+"   ";
  407. }
  408.  
  409. Display.prototype.updateStatusMenuItem = function()
  410. {
  411.     var date = new Date();
  412.     var dateAndTime = "" + date.getTimeShortFormated();
  413.     this.displayData[1] = "       " + dateAndTime + "        ";
  414. }
  415.  
  416. Display.prototype.updateBookMenuItem = function()
  417. {
  418.     if (this.parentDisplay.exchangeCalendarFirstMenuItem && this.parentDisplay.exchangeCalendarLastMenuItem)
  419.     {
  420.         this.parentDisplay.statusMenuItem.setNextItem(this.parentDisplay.exchangeCalendarFirstMenuItem);
  421.         this.parentDisplay.bookMenuItem.setPrevItem(this.parentDisplay.exchangeCalendarLastMenuItem);
  422.     }
  423.     else
  424.     {
  425.         this.parentDisplay.statusMenuItem.setNextItem(this.parentDisplay.bookMenuItem);
  426.         this.parentDisplay.bookMenuItem.setPrevItem(this.parentDisplay.statusMenuItem);
  427.     }
  428. }
  429.  
  430. Display.prototype.exchangeCalendarLookupCallback = function(shortname, data)
  431. {
  432. //log("callback: "+shortname+" \n");
  433.     if (shortname == this.shortName)
  434.     {
  435.         //FIXME check if data contains error tag and error message, print to log and keep previous data?
  436.         if (data.error)
  437.         {
  438.             log("Display: got this error from exchange.php: " + data.error + "\n");
  439.         }
  440.         else
  441.         {
  442.             this.exchangeData = data;
  443.             this.createCalendarMenu();
  444.         }
  445.     }
  446. }
  447.  
  448. /* this function parses calendar data from exchange-script and creates a menu */
  449. Display.prototype.createCalendarMenu = function()
  450. {
  451.     this.exchangeCalendarLastMenuItem = null;
  452.     this.exchangeCalendarFirstMenuItem = null;
  453.    
  454. //log("createCalendar \n");
  455.     if (this.exchangeData)
  456.     {
  457. //log("have data \n");
  458.         var lastMenuItem;
  459.         for (var i = 0; i < this.exchangeData.meetings.length; i++)
  460.         {
  461. //log("looping \n");
  462.             /* create the menuitem for a calendar meeting */
  463.             var menu = new MenuItem(this);
  464.             menu.displayData[0] = this.lcdCenterText(this.replaceAumlauts(this.exchangeData.meetings[i].subject));
  465.             menu.displayData[1] = this.lcdCenterText(this.exchangeData.meetings[i].start.replace(":",".") + " - "
  466.                                         + this.exchangeData.meetings[i].end.replace(":","."));
  467.             menu.doRight = this.changeToNext;
  468.             menu.doLeft = this.changeToPrev;
  469.            
  470.             if (i == 0)
  471.             {
  472.                 this.exchangeCalendarFirstMenuItem = menu;
  473.             }
  474.             else
  475.             {
  476.                 menu.setPrevItem(lastMenuItem);
  477.                 lastMenuItem.setNextItem(menu);
  478.             }
  479.            
  480.             lastMenuItem = menu;
  481.         }
  482.         if (lastMenuItem)
  483.         {
  484.             this.exchangeCalendarLastMenuItem = lastMenuItem;
  485.             this.exchangeCalendarLastMenuItem.setNextItem(this.bookMenuItem);
  486.             this.exchangeCalendarFirstMenuItem.setPrevItem(this.statusMenuItem);
  487.        
  488.         }
  489.         /* to link in the newly created menuitems with exchangeinformation the display must be showing
  490.            either the statusmenu or the bookingmenu */
  491.         if (this.currentMenuItem == this.statusMenuItem || this.currentMenuItem == this.bookMenuItem || this.currentMenuItem == this.bookResultMenuItem)
  492.         {
  493.             /* if there is one or more exchangemenuitems */
  494.             if (this.exchangeCalendarFirstMenuItem && this.exchangeCalendarLastMenuItem)
  495.             {
  496.                 this.statusMenuItem.setNextItem(this.exchangeCalendarFirstMenuItem);
  497.                 this.bookMenuItem.setPrevItem(this.exchangeCalendarLastMenuItem);
  498.             }
  499.             /* if not then link statusmenu to bookingmenu */
  500.             else
  501.             {
  502.                 this.statusMenuItem.setNextItem(this.bookMenuItem);
  503.                 this.bookMenuItem.setPrevItem(this.statusMenuItem);
  504.             }
  505.         }
  506.     }
  507. }
  508.  
  509. Display.prototype.replaceAumlauts = function(intext)
  510. {
  511.     intext = intext.replace(/Å/, "A");
  512.     intext = intext.replace(/å/, "a");
  513.     intext = intext.replace(/Ä/, "A");
  514.     intext = intext.replace(/ä/, String.fromCharCode(225));
  515.     intext = intext.replace(/Ö/, "O");
  516.     intext = intext.replace(/ö/, String.fromCharCode(239));
  517.     intext = intext.replace(/:/, ";");
  518.     intext = intext.replace(/,/, ".");
  519.     return intext;
  520. }
  521.  
  522. Display.prototype.softPwmOnline = function()
  523. {
  524. }
  525.  
  526. Display.prototype.rotaryOnline = function()
  527. {
  528. }
  529.  
  530. Display.prototype.rotaryPosUpdate = function(SwitchId)
  531. {
  532.     this.screenSaverCnt = 0;
  533.     this.mainScreenCnt = 0;
  534.     for (var i = 0; i < this.myRotaryService.getSteps(SwitchId); i++)
  535.     {
  536.         if (this.myRotaryService.getDirection(SwitchId) == "Clockwise")
  537.         {
  538.             if (this.currentMenuItem.doRight)
  539.             {
  540.                 this.currentMenuItem.doRight();
  541.             }
  542.         }
  543.         else
  544.         {
  545.             if (this.currentMenuItem.doLeft)
  546.             {
  547.                 this.currentMenuItem.doLeft();
  548.             }
  549.         }
  550.     }
  551.    
  552.     this.updateDisplay();
  553. }
  554.  
  555. Display.prototype.rotaryBtnUpdate = function(SwitchId)
  556. {
  557.     this.screenSaverCnt = 0;
  558.     this.mainScreenCnt = 0;
  559.     if (this.myRotaryService.getButtonStatus(SwitchId) == "Released")
  560.     {
  561.         if (this.currentMenuItem.doPress)
  562.         {
  563.             this.currentMenuItem.doPress();
  564.         }
  565.         this.updateDisplay();
  566.     }
  567. }
  568.  
  569. Display.prototype.updateDisplay = function()
  570. {
  571.     /* see if the current menuitem wants to update itself */
  572.     if (this.currentMenuItem.doUpdate)
  573.     {
  574.         this.currentMenuItem.doUpdate();
  575.     }
  576.  
  577.     /* Clear the LCD screen */
  578.     //this.myLCDService.clearScreen();
  579.    
  580.     /* send the data for the current menuitem to display */
  581.     for (var i = 0; i < this.currentMenuItem.displayData.length; i++)
  582.     {
  583.         this.myLCDService.printText(0, i, this.currentMenuItem.displayData[i]);
  584.     }
  585.    
  586. }
  587.  
  588. Display.prototype.lcdCenterText = function(text)
  589. {
  590.     returnText = text;
  591.     var displayWidth = 20;  //this.myLCDService.getWidth();
  592.     /* pad on both sides with spaces to displayWidth */
  593.     returnText = text.pad(displayWidth, " ", 2);
  594.    
  595.     return returnText;
  596. }
  597.  
  598. Display.prototype.lcdOffline = function()
  599. {
  600.     /* If we have no interval timer running do nothing */
  601.     if (this.myInterval != null)
  602.     {
  603.         /* Stop the interval */
  604.         this.myInterval.stop();
  605.     }
  606. }
  607.  
  608. Display.prototype.lcdOnline = function()
  609. {
  610.     /* If service is not online do nothing */
  611.     if (this.myLCDService.isOnline())
  612.     {
  613.         /* Clear the LCD screen */
  614.         this.myLCDService.clearScreen();
  615.         /* Set backlight to max */
  616.         this.myLCDService.setBacklight(255);
  617.  
  618.         /* If we have no interval timer running start it */
  619.         if (this.myInterval == null)
  620.         {
  621.             var self = this;
  622.        
  623.             /* Start interval timer for our printout. Arguments are the callback function and time in milliseconds */
  624.             this.myInterval = new Interval(function() { self.timerUpdate() }, 5000);
  625.         }
  626.        
  627.         this.myInterval.start();
  628.        
  629.         this.timerUpdate();
  630.     }
  631. }
  632.  
  633. Display.prototype.setLED = function(red, green, blue)
  634. {
  635.    
  636. }
  637.  
  638. Display.prototype.timerUpdate = function()
  639. {
  640.     /* If LCD service is not online do nothing */
  641.     if (this.myLCDService.isOnline())
  642.     {
  643.         this.screenSaverCnt++;
  644.         this.mainScreenCnt++;
  645.         this.exchangeUpdateCnt++;
  646.  
  647.         if (this.mainScreenCnt > mainScreenTimeout/5)
  648.         {
  649.             /* Go to main screen (time) */
  650.             this.currentMenuItem = this.statusMenuItem;
  651.  
  652.             /* update the info on display */
  653.             this.updateDisplay();
  654.  
  655.             this.mainScreenCnt = 0;
  656.         }
  657.        
  658.         if (this.screenSaverCnt > screenSaverTimeout/5)
  659.         {
  660.            
  661.             this.screenSaverCnt = 0;
  662.         }
  663.  
  664.         if (this.exchangeUpdateCnt > exchangeUpdateTimeout/5)
  665.         {
  666.             /* update the info on display */
  667.             this.updateDisplay();
  668.            
  669.             /* do an exchange lookup */
  670.             this.exchangeCalendar.lookup(this.shortName);
  671.            
  672.             this.exchangeUpdateCnt = 0;
  673.         }
  674.        
  675.     }
  676.    
  677.     /*if (this.mySoftPwmService.isOnline())
  678.     {
  679.         this.mySoftPwmService.setPWMValue(0, 0);
  680.         this.mySoftPwmService.setPWMValue(11, 1);
  681.         this.mySoftPwmService.setPWMValue(11, 2);
  682.     }*/
  683. }
  684.  
  685.