Subversion Repositories HomeAutomation

Rev

Rev 1237 | Rev 1239 | 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.     /* Start interval timer for sending timestamp to network. Arguments are the callback function and time in milliseconds
  106.     used to make sure an eth-node gets its init packet */
  107.     this.myInterval = new Interval(function() { self.sendTimeStamp() }, 10000);
  108.    
  109.     this.screenSaverCnt = 0;
  110.     this.mainScreenCnt = 0;
  111.     this.exchangeUpdateCnt = exchangeUpdateTimeout-10;
  112.    
  113.     /* Get the LCD service that we want from the ServiceManager, it takes type, service name, service id */
  114.     this.myLCDService = ServiceManager.getService("Can", "HD44789", this.myInitialArguments["HD44789"]["Id"]);
  115.     /* Add a callback for when the service goes online */
  116.     this.myLCDService.registerEventCallback("online", function(args) { self.lcdOnline(); });
  117.     /* If the service is already online we should call the handler here */
  118.     this.lcdOnline();
  119.     /* Add a callback for when the service goes offline */
  120.     this.myLCDService.registerEventCallback("offline", function(args) { self.lcdOffline(); });
  121.    
  122.     /* Get the Rotary service that we want from the ServiceManager, it takes type, service name, service id */
  123.     this.myRotaryService = ServiceManager.getService("Can", "Rotary", this.myInitialArguments["Rotary"]["Id"]);
  124.     /* Add a callback for when the encoder reports a new position */
  125.     this.myRotaryService.registerEventCallback("newPosition", function(args) { self.rotaryPosUpdate(args); });
  126.     /* Add a callback for when the encoder reports a new button status */
  127.     this.myRotaryService.registerEventCallback("newBtnStatus", function(args) { self.rotaryBtnUpdate(args); });
  128.     /* Add a callback for when the service goes online */
  129.     this.myRotaryService.registerEventCallback("online", function(args) { self.rotaryOnline(); });
  130.     /* If the service is already online we should call the handler here */
  131.     this.rotaryOnline();
  132.    
  133.     /* Get the softPWM service that we want from the ServiceManager, it takes type, service name, service id */
  134.     this.mySoftPwmService = ServiceManager.getService("Can", "softPWM", this.myInitialArguments["softPWM"]["Id"]);
  135.     /* Add a callback for when the service goes online */
  136.     this.mySoftPwmService.registerEventCallback("online", function(args) { self.softPwmOnline(); });
  137.     /* If the service is already online we should call the handler here */
  138.     this.softPwmOnline();
  139.    
  140.     this.exchangeCalendar = new ExchangeCalendar(function(shortname, data) { self.exchangeCalendarLookupCallback(shortname, data); });
  141.     this.exchangeCalendarBook = new ExchangeCalendar(function(shortname, data) { self.exchangeCalendarBookCallback(shortname, data); });
  142.    
  143.     /* create the first menu item */
  144.     this.statusMenuItem = new MenuItem(this);
  145.     this.statusMenuItem.displayData[0] = this.lcdCenterText(this.niceName);
  146.     this.statusMenuItem.doUpdate = function(args) { self.updateStatusMenuItem(); };
  147.     this.currentMenuItem = this.statusMenuItem;
  148.    
  149.     /* create the menuitem where you can choose to enter the booking sub-menu */
  150.     this.bookMenuItem = new MenuItem(this);
  151.     this.bookMenuItem.displayData[0] = this.lcdCenterText("Book room");
  152.     this.bookMenuItem.displayData[1] = this.lcdCenterText("(Push button)");
  153.     this.bookMenuItem.doUpdate = function(args) { self.updateBookMenuItem(); };
  154.  
  155.     /* connect the items as a linked list */
  156.     this.statusMenuItem.setNextItem(this.bookMenuItem);
  157.     this.statusMenuItem.setPrevItem(this.bookMenuItem);
  158.     /* set the function that shall be executed when knob is turned */
  159.     this.statusMenuItem.doRight = function(args) { self.changeToNext(); };
  160.     this.statusMenuItem.doLeft = function(args) { self.changeToPrev(); };
  161.    
  162.     /* connect the items as a linked list */
  163.     this.bookMenuItem.setNextItem(this.statusMenuItem);
  164.     this.bookMenuItem.setPrevItem(this.statusMenuItem);
  165.     /* set the function that shall be executed when knob is turned */
  166.     this.bookMenuItem.doRight = function(args) { self.changeToNext(); };
  167.     this.bookMenuItem.doLeft = function(args) { self.changeToPrev(); };
  168.    
  169.     /* create the menuitem where you can choose the to-time */
  170.     var menuChooseTo = new MenuItem(this);
  171.     menuChooseTo.displayData[1] = this.lcdCenterText(" Ok     Cancel ");
  172.     menuChooseTo.doUpdate = function(args) { self.chooseBookTimeTo(); };
  173.    
  174.     this.bookMenuItem.doPress = function(args) { self.prepareBookingMenu(); };
  175.     this.bookMenuItem.setDescItem(menuChooseTo);
  176.    
  177.     /* create the menuitem where you can choose to book the room with OK */
  178.     var menuChooseOk = new MenuItem(this);
  179.     menuChooseOk.displayData[1] = this.lcdCenterText("<Ok>    Cancel ");
  180.     menuChooseOk.doUpdate = function(args) { self.setBookTime(); };
  181.  
  182.     /* create the menuitem where you can choose to cancel the booking */
  183.     var menuChooseCancel = new MenuItem(this);
  184.     menuChooseCancel.displayData[1] = this.lcdCenterText(" Ok    <Cancel>");
  185.     menuChooseCancel.doUpdate = function(args) { self.setBookTime(); };
  186.  
  187.     /* create the menuitem where you can choose the from-time */
  188.     var menuChooseFrom = new MenuItem(this);
  189.     menuChooseFrom.displayData[1] = this.lcdCenterText(" Ok     Cancel ");
  190.     menuChooseFrom.doUpdate = function(args) { self.chooseBookTimeFrom(); };
  191.  
  192.     /* create the menuitem where you see the result of a booking */
  193.     this.bookResultMenuItem = new MenuItem(this);
  194.     this.bookResultMenuItem.displayData[0] = this.lcdCenterText("Booking...");
  195.     this.bookResultMenuItem.displayData[1] = this.lcdCenterText("(Push to return)");
  196.     this.bookResultMenuItem.setDescItem(this.bookMenuItem);
  197.     this.bookResultMenuItem.doPress = function(args) { self.changeToDesc(); };
  198.  
  199.     /* connect the items as a linked list */
  200.     menuChooseTo.setNextItem(menuChooseOk);
  201.     menuChooseTo.setPrevItem(menuChooseFrom);
  202.     /* set the function that shall be executed when knob is turned */
  203.     menuChooseTo.doRight = function(args) { self.changeToNext(); };
  204.     menuChooseTo.doLeft = function(args) { self.changeToPrev(); };
  205.     menuChooseTo.doPress = function(args) { self.changeToDesc(); };
  206.  
  207.     /* connect the items as a linked list */
  208.     menuChooseOk.setNextItem(menuChooseCancel);
  209.     menuChooseOk.setPrevItem(menuChooseTo);
  210.     menuChooseOk.setDescItem(this.bookResultMenuItem);
  211.     /* set the function that shall be executed when knob is turned */
  212.     menuChooseOk.doRight = function(args) { self.changeToNext(); };
  213.     menuChooseOk.doLeft = function(args) { self.changeToPrev(); };
  214.     menuChooseOk.doPress = function(args) { self.doBooking(); };
  215.  
  216.     /* connect the items as a linked list */
  217.     menuChooseCancel.setNextItem(menuChooseFrom);
  218.     menuChooseCancel.setPrevItem(menuChooseOk);
  219.     menuChooseCancel.setDescItem(this.bookMenuItem);
  220.     /* set the function that shall be executed when knob is turned */
  221.     menuChooseCancel.doRight = function(args) { self.changeToNext(); };
  222.     menuChooseCancel.doLeft = function(args) { self.changeToPrev(); };
  223.     menuChooseCancel.doPress = function(args) { self.changeToDesc(); };
  224.  
  225.     /* connect the items as a linked list */
  226.     menuChooseFrom.setNextItem(menuChooseTo);
  227.     menuChooseFrom.setPrevItem(menuChooseCancel);
  228.     /* set the function that shall be executed when knob is turned */
  229.     menuChooseFrom.doRight = function(args) { self.changeToNext(); };
  230.     menuChooseFrom.doLeft = function(args) { self.changeToPrev(); };
  231.     menuChooseFrom.doPress = function(args) { self.changeToDesc(); };
  232.  
  233.     /* create the menuitem where you can modify the to-time */
  234.     var menuSetTo = new MenuItem(this);
  235.     menuSetTo.doUpdate = function(args) { self.setBookTimeTo(); };
  236.     menuSetTo.displayData[0] = this.lcdCenterText("Set end time");
  237.     menuSetTo.doRight = function(args) { self.incBookTimeTo(); };
  238.     menuSetTo.doLeft = function(args) { self.decBookTimeTo(); };
  239.     menuSetTo.doPress = function(args) { self.changeToDesc(); };
  240.     menuSetTo.setDescItem(menuChooseTo);
  241.     menuChooseTo.setDescItem(menuSetTo);
  242.  
  243.     /* create the menuitem where you can modify the from-time */
  244.     var menuSetFrom = new MenuItem(this);
  245.     menuSetFrom.doUpdate = function(args) { self.setBookTimeFrom(); };
  246.     menuSetFrom.displayData[0] = this.lcdCenterText("Set start time");
  247.     menuSetFrom.doRight = function(args) { self.incBookTimeFrom(); };
  248.     menuSetFrom.doLeft = function(args) { self.decBookTimeFrom(); };
  249.     menuSetFrom.doPress = function(args) { self.changeToDesc(); };
  250.     menuSetFrom.setDescItem(menuChooseFrom);
  251.     menuChooseFrom.setDescItem(menuSetFrom);
  252.  
  253. }
  254.  
  255. Display.prototype.exchangeCalendarBookCallback = function(shortname, data)
  256. {
  257.     if (shortname == this.shortName)
  258.     {
  259.         //FIXME check if data contains error tag and error message, print to log and keep previous data?
  260.         if (data.result)
  261.         {
  262.             if (data.error)
  263.             {
  264.                 this.bookResultMenuItem.displayData[0] = this.lcdCenterText("Booking failed");
  265.                 log("Display: got this error from exchange server: " + data.error + "\n");
  266.             }
  267.             else
  268.             {
  269.                 this.bookResultMenuItem.displayData[0] = this.lcdCenterText("Booking succeeded");
  270.                 log("Display: Successfully booked room\n");
  271.                
  272.                 /* do an exchange lookup */
  273.                 this.exchangeCalendar.lookup(this.shortName);
  274.             }
  275.            
  276.         }
  277.         else if (data.error)
  278.         {
  279.             this.bookResultMenuItem.displayData[0] = this.lcdCenterText("Booking failed");
  280.             log("Display: got this error from exchange.php: " + data.error + "\n");
  281.         }
  282.         this.updateDisplay();
  283.     }
  284. }
  285.  
  286. Display.prototype.doBooking = function()
  287. {
  288.     this.bookResultMenuItem.displayData[0] = this.lcdCenterText("Booking...");
  289.     if (this.currentMenuItem.descItem)
  290.     {
  291.         this.currentMenuItem = this.currentMenuItem.descItem;
  292.     }
  293.     //this.changeToDesc();
  294.  
  295.     var bookFrom = this.bookFromTime.getTimeShortFormated();
  296.     var bookTo = this.bookToTime.getTimeShortFormated();
  297.     this.exchangeCalendarBook.book(this.shortName, bookFrom, bookTo);
  298.    
  299.     //bookFromTime bookToTime
  300. }
  301.  
  302. Display.prototype.prepareBookingMenu = function()
  303. {
  304.     this.bookFromTime = new Date();
  305.     this.bookToTime = new Date();
  306.     //this.bookFromTime.setHours(8);
  307.     //this.bookToTime.setHours(8);
  308.     if (this.bookFromTime.getMinutes() < 30)
  309.     {
  310.         this.bookFromTime.setMinutes(0);
  311.         this.bookToTime.setMinutes(30);
  312.     }
  313.     else
  314.     {
  315.         this.bookFromTime.setMinutes(30);
  316.         this.bookToTime.setHours(this.bookToTime.getHours()+1);
  317.         this.bookToTime.setMinutes(0);
  318.     }
  319.  
  320.     this.currentMenuItem = this.currentMenuItem.descItem;
  321. }
  322.  
  323. Display.prototype.changeToDesc = function()
  324. {
  325.     if (this.currentMenuItem.descItem)
  326.     {
  327.         this.currentMenuItem = this.currentMenuItem.descItem;
  328.     }
  329. }
  330.  
  331. Display.prototype.changeToNext = function()
  332. {
  333.     if (this.currentMenuItem.nextItem)
  334.     {
  335.         this.currentMenuItem = this.currentMenuItem.nextItem;
  336.     }
  337. }
  338.  
  339. Display.prototype.changeToPrev = function()
  340. {
  341.     if (this.currentMenuItem.prevItem)
  342.     {
  343.         this.currentMenuItem = this.currentMenuItem.prevItem;
  344.     }
  345. }
  346.  
  347. Display.prototype.incBookTimeTo = function()
  348. {
  349.     //FIXME: constraints?
  350.     if (this.bookToTime.getHours() < 23)
  351.     {
  352.         this.bookToTime.setMinutes(this.bookToTime.getMinutes() + bookingIncrease);
  353.     }
  354. }
  355.  
  356. Display.prototype.decBookTimeTo = function()
  357. {
  358.     //FIXME: constraints?
  359.     var now = new Date();
  360.     if (this.bookToTime.getHours() >= now.getHours())
  361.     {
  362.         this.bookToTime.setMinutes(this.bookToTime.getMinutes() - bookingIncrease);
  363.     }
  364. }
  365.  
  366. Display.prototype.incBookTimeFrom = function()
  367. {
  368.     //FIXME: constraints?
  369.     if (this.bookFromTime.getHours() < 23)
  370.     {
  371.         this.bookFromTime.setMinutes(this.bookFromTime.getMinutes() + bookingIncrease);
  372.     }
  373. }
  374.  
  375. Display.prototype.decBookTimeFrom = function()
  376. {
  377.     //FIXME: constraints?
  378.     var now = new Date();
  379.     if (this.bookFromTime.getHours() >= now.getHours())
  380.     {
  381.         this.bookFromTime.setMinutes(this.bookFromTime.getMinutes() - bookingIncrease);
  382.     }
  383. }
  384.  
  385. Display.prototype.setBookTimeFrom = function()
  386. {
  387.     this.currentMenuItem.displayData[1] = "      <"+this.bookFromTime.getTimeShortFormated()+">       ";
  388. }
  389.  
  390. Display.prototype.setBookTimeTo = function()
  391. {
  392.     this.currentMenuItem.displayData[1] = "      <"+this.bookToTime.getTimeShortFormated()+">       ";
  393. }
  394.  
  395. Display.prototype.chooseBookTimeTo = function()
  396. {
  397.     this.currentMenuItem.displayData[0] = "  "+this.bookFromTime.getTimeShortFormated()+"  - <"
  398.                                 +this.bookToTime.getTimeShortFormated()+">  ";
  399. }
  400.  
  401. Display.prototype.chooseBookTimeFrom = function()
  402. {
  403.     this.currentMenuItem.displayData[0] = " <"+this.bookFromTime.getTimeShortFormated()+"> -  "
  404.                                 +this.bookToTime.getTimeShortFormated()+"   ";
  405. }
  406.  
  407. Display.prototype.setBookTime = function()
  408. {
  409.     this.currentMenuItem.displayData[0] = "  "+this.bookFromTime.getTimeShortFormated()+"  -  "
  410.                                 +this.bookToTime.getTimeShortFormated()+"   ";
  411. }
  412.  
  413. Display.prototype.updateStatusMenuItem = function()
  414. {
  415.     var date = new Date();
  416.     var dateAndTime = "" + date.getTimeShortFormated();
  417.     this.statusMenuItem.displayData[1] = this.lcdCenterText(dateAndTime);
  418. }
  419.  
  420. Display.prototype.updateBookMenuItem = function()
  421. {
  422.     if (this.exchangeCalendarFirstMenuItem && this.exchangeCalendarLastMenuItem)
  423.     {
  424.         this.statusMenuItem.setNextItem(this.exchangeCalendarFirstMenuItem);
  425.         this.bookMenuItem.setPrevItem(this.exchangeCalendarLastMenuItem);
  426.     }
  427.     else
  428.     {
  429.         this.statusMenuItem.setNextItem(this.bookMenuItem);
  430.         this.bookMenuItem.setPrevItem(this.statusMenuItem);
  431.     }
  432. }
  433.  
  434. Display.prototype.exchangeCalendarLookupCallback = function(shortname, data)
  435. {
  436. //log("callback: "+shortname+" \n");
  437.     if (shortname == this.shortName)
  438.     {
  439.         //FIXME check if data contains error tag and error message, print to log and keep previous data?
  440.         if (data.error)
  441.         {
  442.             log("Display: got this error from exchange.php: " + data.error + "\n");
  443.         }
  444.         else
  445.         {
  446.             this.exchangeData = data;
  447.             this.createCalendarMenu();
  448.         }
  449.     }
  450. }
  451.  
  452. /* this function parses calendar data from exchange-script and creates a menu */
  453. Display.prototype.createCalendarMenu = function()
  454. {
  455.     /* This is used for function declarations like the callbacks below */
  456.     var self = this;
  457.  
  458.     this.exchangeCalendarLastMenuItem = null;
  459.     this.exchangeCalendarFirstMenuItem = null;
  460.    
  461. //log("createCalendar \n");
  462.     if (this.exchangeData)
  463.     {
  464. //log("have data \n");
  465.         var lastMenuItem;
  466.         for (var i = 0; i < this.exchangeData.meetings.length; i++)
  467.         {
  468. //log("looping \n");
  469.             /* create the menuitem for a calendar meeting */
  470.             var menu = new MenuItem(this);
  471.             menu.displayData[0] = this.lcdCenterText(this.replaceAumlauts(this.exchangeData.meetings[i].subject));
  472.             menu.displayData[1] = this.lcdCenterText(this.exchangeData.meetings[i].start.replace(":",".") + " - "
  473.                                         + this.exchangeData.meetings[i].end.replace(":","."));
  474.             menu.doRight = function(args) { self.changeToNext(); };
  475.             menu.doLeft = function(args) { self.changeToPrev(); };
  476.            
  477.             if (i == 0)
  478.             {
  479.                 this.exchangeCalendarFirstMenuItem = menu;
  480.             }
  481.             else
  482.             {
  483.                 menu.setPrevItem(lastMenuItem);
  484.                 lastMenuItem.setNextItem(menu);
  485.             }
  486.            
  487.             lastMenuItem = menu;
  488.         }
  489.         if (lastMenuItem)
  490.         {
  491.             this.exchangeCalendarLastMenuItem = lastMenuItem;
  492.             this.exchangeCalendarLastMenuItem.setNextItem(this.bookMenuItem);
  493.             this.exchangeCalendarFirstMenuItem.setPrevItem(this.statusMenuItem);
  494.        
  495.         }
  496.         /* to link in the newly created menuitems with exchangeinformation the display must be showing
  497.            either the statusmenu or the bookingmenu */
  498.         if (this.currentMenuItem == this.statusMenuItem || this.currentMenuItem == this.bookMenuItem || this.currentMenuItem == this.bookResultMenuItem)
  499.         {
  500.             /* if there is one or more exchangemenuitems */
  501.             if (this.exchangeCalendarFirstMenuItem && this.exchangeCalendarLastMenuItem)
  502.             {
  503.                 this.statusMenuItem.setNextItem(this.exchangeCalendarFirstMenuItem);
  504.                 this.bookMenuItem.setPrevItem(this.exchangeCalendarLastMenuItem);
  505.             }
  506.             /* if not then link statusmenu to bookingmenu */
  507.             else
  508.             {
  509.                 this.statusMenuItem.setNextItem(this.bookMenuItem);
  510.                 this.bookMenuItem.setPrevItem(this.statusMenuItem);
  511.             }
  512.         }
  513.     }
  514. }
  515.  
  516. Display.prototype.replaceAumlauts = function(intext)
  517. {
  518.     intext = intext.replace(/Å/, String.fromCharCode(1));
  519.     intext = intext.replace(/å/, String.fromCharCode(0));
  520.     intext = intext.replace(/Ä/, String.fromCharCode(2));
  521.     intext = intext.replace(/ä/, String.fromCharCode(225));
  522.     intext = intext.replace(/Ö/, String.fromCharCode(3));
  523.     intext = intext.replace(/ö/, String.fromCharCode(239));
  524.     //intext = intext.replace(/:/, ";");
  525.     //intext = intext.replace(/,/, ".");
  526.     return intext;
  527. }
  528.  
  529. Display.prototype.softPwmOnline = function()
  530. {
  531. }
  532.  
  533. Display.prototype.rotaryOnline = function()
  534. {
  535. }
  536.  
  537. Display.prototype.rotaryPosUpdate = function(SwitchId)
  538. {
  539.     this.screenSaverCnt = 0;
  540.     this.mainScreenCnt = 0;
  541.     for (var i = 0; i < this.myRotaryService.getSteps(SwitchId); i++)
  542.     {
  543.         if (this.myRotaryService.getDirection(SwitchId) == "Clockwise")
  544.         {
  545.             if (this.currentMenuItem.doRight)
  546.             {
  547.                 this.currentMenuItem.doRight();
  548.             }
  549.         }
  550.         else
  551.         {
  552.             if (this.currentMenuItem.doLeft)
  553.             {
  554.                 this.currentMenuItem.doLeft();
  555.             }
  556.         }
  557.     }
  558.    
  559.     this.updateDisplay();
  560. }
  561.  
  562. Display.prototype.rotaryBtnUpdate = function(SwitchId)
  563. {
  564.     this.screenSaverCnt = 0;
  565.     this.mainScreenCnt = 0;
  566.     if (this.myRotaryService.getButtonStatus(SwitchId) == "Released")
  567.     {
  568.         if (this.currentMenuItem.doPress)
  569.         {
  570.             this.currentMenuItem.doPress();
  571.         }
  572.         this.updateDisplay();
  573.     }
  574. }
  575.  
  576. Display.prototype.updateDisplay = function()
  577. {
  578.     /* see if the current menuitem wants to update itself */
  579.     if (this.currentMenuItem.doUpdate)
  580.     {
  581.         this.currentMenuItem.doUpdate();
  582.     }
  583.  
  584.     /* Clear the LCD screen */
  585.     //this.myLCDService.clearScreen();
  586.    
  587.     /* send the data for the current menuitem to display */
  588.     for (var i = 0; i < this.currentMenuItem.displayData.length; i++)
  589.     {
  590.         this.myLCDService.printText(0, i, this.currentMenuItem.displayData[i]);
  591.     }
  592.    
  593. }
  594.  
  595. Display.prototype.lcdCenterText = function(text)
  596. {
  597.     returnText = text;
  598.     var displayWidth = 20;  //this.myLCDService.getWidth();
  599.     /* pad on both sides with spaces to displayWidth */
  600.     returnText = text.pad(displayWidth, " ", 2);
  601.    
  602.     return returnText;
  603. }
  604.  
  605. Display.prototype.lcdOffline = function()
  606. {
  607.     /* If we have no interval timer running do nothing */
  608.     if (this.myInterval != null)
  609.     {
  610.         /* Stop the interval */
  611.         this.myInterval.stop();
  612.     }
  613. }
  614.  
  615. Display.prototype.lcdOnline = function()
  616. {
  617.     /* If service is not online do nothing */
  618.     if (this.myLCDService.isOnline())
  619.     {
  620.         /* Clear the LCD screen */
  621.         this.myLCDService.clearScreen();
  622.         /* Set backlight to max */
  623.         this.myLCDService.setBacklight(255);
  624.  
  625.         /* If we have no interval timer running start it */
  626.         if (this.myInterval == null)
  627.         {
  628.             var self = this;
  629.        
  630.             /* Start interval timer for our printout. Arguments are the callback function and time in milliseconds */
  631.             this.myInterval = new Interval(function() { self.timerUpdate() }, 5000);
  632.         }
  633.        
  634.         this.myInterval.start();
  635.        
  636.         this.timerUpdate();
  637.     }
  638. }
  639.  
  640. Display.prototype.setLED = function(red, green, blue)
  641. {
  642.    
  643. }
  644.  
  645. Display.prototype.sendTimeStamp = function()
  646. {
  647.     var canMessage = new CanNMTMessage("nmt", "Time");
  648.     canMessage.send();
  649.  
  650. }
  651.  
  652. Display.prototype.timerUpdate = function()
  653. {
  654.     /* If LCD service is not online do nothing */
  655.     if (this.myLCDService.isOnline())
  656.     {
  657.         this.screenSaverCnt++;
  658.         this.mainScreenCnt++;
  659.         this.exchangeUpdateCnt++;
  660.  
  661.         if (this.mainScreenCnt > mainScreenTimeout/5)
  662.         {
  663.             /* Go to main screen (time) */
  664.             this.currentMenuItem = this.statusMenuItem;
  665.  
  666.             /* update the info on display */
  667.             this.updateDisplay();
  668.  
  669.             this.mainScreenCnt = 0;
  670.         }
  671.        
  672.         if (this.screenSaverCnt > screenSaverTimeout/5)
  673.         {
  674.            
  675.             this.screenSaverCnt = 0;
  676.         }
  677.  
  678.         if (this.exchangeUpdateCnt > exchangeUpdateTimeout/5)
  679.         {
  680.             /* update the info on display */
  681.             this.updateDisplay();
  682.            
  683.             /* do an exchange lookup */
  684.             this.exchangeCalendar.lookup(this.shortName);
  685.            
  686.             this.exchangeUpdateCnt = 0;
  687.         }
  688.        
  689.     }
  690.    
  691.     /*if (this.mySoftPwmService.isOnline())
  692.     {
  693.         this.mySoftPwmService.setPWMValue(0, 0);
  694.         this.mySoftPwmService.setPWMValue(11, 1);
  695.         this.mySoftPwmService.setPWMValue(11, 2);
  696.     }*/
  697. }
  698.  
  699.