Subversion Repositories HomeAutomation

Rev

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