Subversion Repositories HomeAutomation

Rev

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

  1. /* the display object who created the menu item */
  2. SensorMenuItem.prototype.parentDisplay = null;
  3. SensorMenuItem.prototype.sensors = null;
  4. SensorMenuItem.prototype.sensorNames = null;
  5. SensorMenuItem.prototype.mode = 0;
  6. SensorMenuItem.prototype.currentSensorItem = 0;
  7. SensorMenuItem.prototype.window_low = 0;
  8. SensorMenuItem.prototype.window_high = 3; //set to nummber of rows you want to display minus 1
  9.  
  10.  
  11. function SensorMenuItem(parentDisplay, hd44789Object)
  12. {
  13.     var self = this;
  14.     this.parentDisplay = parentDisplay;
  15.     this.display = hd44789Object;  
  16. }
  17.  
  18. /* the display object who created the menu item */
  19. SensorMenuItem.prototype.parentDisplay = null;
  20. /* the display that we are writing to */
  21. SensorMenuItem.prototype.display = null;
  22.  
  23. /* How often the display shall update [ms]*/
  24. SensorMenuItem.prototype.UpdateTime = 5000;
  25.  
  26. /* what SensorMenuItem is left of this item, if used */
  27. SensorMenuItem.prototype.LeftItem = null;
  28. /* what SensorMenuItem is right of this item, if used */
  29. SensorMenuItem.prototype.RightItem = null;
  30. /* what SensorMenuItem is after of this item, if used */
  31. SensorMenuItem.prototype.PressEnterItem = null;
  32.  
  33. /*
  34. Standard events can be:
  35. left, right, enter, back, up, down....
  36. */
  37. SensorMenuItem.prototype.processEvent = function (event)
  38. {
  39.     switch (event)
  40.     {
  41.     case "right":
  42.         if (this.mode == 0) {
  43.             this.parentDisplay.changeToRight();
  44.         } else {
  45.             this.currentSensorItem--;
  46.             if (this.currentSensorItem == -1) {
  47.                 this.currentSensorItem= this.sensors.length-1;
  48.                 if (this.sensors.length-1 - (this.window_high-this.window_low) >= 0) {
  49.                     this.window_low = this.sensors.length-1 - (this.window_high-this.window_low);
  50.                     this.window_high = this.sensors.length-1;
  51.                     Display_Clear(this.display);
  52.                 }
  53.             }
  54.             if (this.currentSensorItem < this.window_low ) {
  55.                 this.window_low--;
  56.                 this.window_high--;
  57.                 Display_Clear(this.display);
  58.             }
  59.         }
  60.         break;
  61.     case "left":
  62.         if (this.mode == 0) {
  63.             this.parentDisplay.changeToLeft();
  64.         } else {
  65.             this.currentSensorItem++;
  66.             if (this.currentSensorItem == this.sensors.length) {
  67.                 this.currentSensorItem=0;
  68.                 this.window_high = this.window_high-this.window_low;
  69.                 this.window_low = 0;
  70.                 Display_Clear(this.display);
  71.             }
  72.             if (this.currentSensorItem > this.window_high ) {
  73.                 this.window_low++;
  74.                 this.window_high++;
  75.                 Display_Clear(this.display);
  76.             }
  77.         }
  78.         break;
  79.     case "enter":
  80.         if (this.mode == 0) {
  81.             if (this.sensors.length > 0) {
  82.                 this.currentSensorItem = 0;
  83.                 this.mode = 1;
  84.             }
  85.         } else {
  86.             this.mode = 0;
  87.         }
  88.         break;
  89.     }
  90. }
  91.  
  92. SensorMenuItem.prototype.onEnter = function ()
  93. {
  94.     var SensorMenuData = Storage_GetParameter("CLCD_config", "SensorMenuItem");
  95.    
  96.     //Log("\033[33mon Enter1: "+SensorMenuData+".\033[0m\n");  
  97.     var alias_data = eval("(" + SensorMenuData + ")");
  98.     this.sensors = alias_data["Sensors"];
  99.     this.sensorNames = alias_data["SensorNames"];
  100.   //Log("\033[33mon Enter: "+alias_data["Sensors"][1].toString()+". "+alias_data["Sensors"].length+"\033[0m\n");   
  101.   //this.sensors = getSensorList();
  102. //  var i = 0;
  103. //  for (i=0; i< this.sensors.length;i++)
  104. //  {
  105. //    Log("\033[33mdata: "+this.sensors[i]+".\033[0m\n");  
  106. //  }
  107.    
  108.     this.mode = 0;
  109.     Display_Clear(this.display);
  110. }
  111. SensorMenuItem.prototype.update = function ()
  112. {
  113.     Display_Clear(this.display);
  114.     row = 0;
  115.     for (var i = this.window_low; i < this.sensors.length && i <= this.window_high; i++) {
  116.         var last_value_string = Storage_GetParameter("LastValues", this.sensors[i]);
  117.         var last_value = eval("(" + last_value_string + ")");
  118.         if (this.mode == 1 && this.currentSensorItem == i) {
  119.             Display_Print(this.display, 0, row, ">"+ this.sensorNames[i]);
  120.         } else {
  121.             Display_Print(this.display, 0, row, " "+ this.sensorNames[i]);
  122.         }
  123.         if (last_value["Temperature_Celsius"]) {
  124.             Display_Print(this.display, 14, row,parseFloat(last_value["Temperature_Celsius"]["value"]).toFixed(1).toString()+"¤C");
  125.         } else if (last_value["Humidity_Percent"]){
  126.             Display_Print(this.display, 14, row,parseFloat(last_value["Humidity_Percent"]["value"]).toFixed(1).toString()+"%");
  127.         } else if (last_value["Voltage"]){
  128.             Display_Print(this.display, 14, row,parseFloat(last_value["Voltage"]["value"]).toFixed(1).toString()+"V");
  129.         } else if (last_value["Current"]){
  130.             Display_Print(this.display, 14, row,parseFloat(last_value["Current"]["value"]).toFixed(1).toString()+"A");
  131.         } else {
  132.             Display_Print(this.display, 14, "Error");
  133.         }
  134.         row++;
  135.     }
  136.     //Display_Print(this.display,0, 0, this.parentDisplay.lcdCenterText("Tillbaka"));
  137. }
  138.  
  139. SensorMenuItem.prototype.onExit = function ()
  140. {
  141.     this.mode = 0;
  142. }
  143.  
  144.  
  145.