Subversion Repositories HomeAutomation

Rev

Blame | Last modification | View Log | SVN | RSS feed

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