Subversion Repositories HomeAutomation

Rev

Rev 1351 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. MainMenuItem.prototype.CurrentPower = 0;
  2. MainMenuItem.prototype.CurrentEnergy = 0;
  3.  
  4. function MainMenuItem(parentDisplay, hd44789Object)
  5. {
  6.     this.parentDisplay = parentDisplay;
  7.     this.display = hd44789Object;
  8.     var self = this;
  9.     if (!this.parentDisplay.myInitialArguments["power"])
  10.     {
  11.         log(this.myName + ":" + this.myId + "> Failed to initialize, power-config missing from config.\n");
  12.         return;
  13.     }
  14.    
  15.     /* Get the PWM service that we want from the ServiceManager, it takes type, service name, service id */
  16.     this.myPowerService = ServiceManager.getService("Can", "power", this.parentDisplay.myInitialArguments["power"]["Id"]);
  17.     /* Add a callback for when the service goes online */
  18.     this.myPowerService.registerEventCallback("online", function(args) { self.PowerOnline(); });
  19.     /* Add a callback for when the sensor reports a new value */
  20.     this.myPowerService.registerEventCallback("newValue", function(args) { self.powerUpdate(); });
  21.     /* If the service is already online we should call the handler here */
  22.     this.PowerOnline();
  23.  
  24.  
  25. }
  26.  
  27. MainMenuItem.prototype.PowerOnline = function()
  28. {
  29.     /* If service is not online do nothing */
  30.     if (this.myPowerService.isOnline())
  31.     {
  32.         log("Power is online!\n");
  33.         /* Set report interval to 2 seconds */
  34.     //  this.myPowerService.setReportInterval(4);
  35. //this.myPowerService.setEnergy(1649500);
  36.     }
  37. }
  38.  
  39. MainMenuItem.prototype.powerUpdate = function()
  40. {
  41.     this.CurrentPower = this.myPowerService.getPower();
  42.     this.CurrentEnergy = this.myPowerService.getEnergy();
  43. }
  44.  
  45. /* the display object who created the menu item */
  46. MainMenuItem.prototype.parentDisplay = null;
  47. /* the display that we are writing to */
  48. MainMenuItem.prototype.display = null;
  49.  
  50. /* How often the display shall update [ms]*/
  51. MainMenuItem.prototype.UpdateTime = 5000;
  52.  
  53. /* what MainMenuItem is left of this item, if used */
  54. MainMenuItem.prototype.LeftItem = null;
  55. /* what MainMenuItem is right of this item, if used */
  56. MainMenuItem.prototype.RightItem = null;
  57. /* what MainMenuItem is after of this item, if used */
  58. MainMenuItem.prototype.PressEnterItem = null;
  59. /* what MainMenuItem is before of this item, if used */
  60. MainMenuItem.prototype.PressBackItem = null;
  61. /* what MainMenuItem is below of this item, if used */
  62. MainMenuItem.prototype.DownItem = null;
  63. /* what MainMenuItem is abowe of this item, if used */
  64. MainMenuItem.prototype.UpItem = null;
  65.  
  66. /*
  67. Standard events can be:
  68. left, right, enter, back, up, down....
  69. */
  70. MainMenuItem.prototype.processEvent = function (event)
  71. {
  72.         switch (event)
  73.     {
  74.     case "left":
  75.         this.parentDisplay.changeToLeft();
  76.         break;
  77.  
  78.     case "right":
  79.         this.parentDisplay.changeToRight();
  80.         break;
  81.    
  82.     case "up":
  83.         //parentDisplay.changeToUp();
  84.         break;
  85.    
  86.     case "down":
  87.         //parentDisplay.changeToDown();
  88.         break;
  89.    
  90.     case "enter":
  91.         //parentDisplay.changeToEnter();
  92.         break;
  93.    
  94.     case "back":
  95.         //parentDisplay.changeToBack();
  96.         break;
  97.     }
  98. }
  99.  
  100. MainMenuItem.prototype.onEnter = function ()
  101. {
  102.     this.display.clearScreen("Standard");
  103. }
  104. MainMenuItem.prototype.update = function ()
  105. {
  106.     var date = new Date();
  107.     /* Get the current date time on the format YYYY-mm-dd HH.ii.ss */
  108.     var dateAndTime = date.getDateFormated()+" "+date.getTimeShortFormated();
  109.     this.display.printText(0, 1, this.parentDisplay.lcdCenterText(""+ getSensorValue('Vardagsrumssensor').toFixed(1).toString() + " C   " + getSensorValue('Västersensor').toFixed(1).toString() + "C"));
  110.     this.display.printText(0, 0, this.parentDisplay.lcdCenterText(""+dateAndTime));
  111.  
  112.     this.display.printText(0, 2, this.parentDisplay.lcdCenterText(""+ getSensorValue('Sovrumssensor').toFixed(1).toString() + " C   " + getSensorValue('Ă–stersensor').toFixed(1).toString() + "C"));
  113.  
  114.     this.display.printText(0, 3, this.parentDisplay.lcdCenterText(""+this.CurrentPower.toString()+" W  "+(this.CurrentEnergy/1000).toString() + "kWh"));
  115. }
  116. MainMenuItem.prototype.onExit = function ()
  117. {
  118.    
  119. }
  120.  
  121.