Subversion Repositories HomeAutomation

Rev

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

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