Subversion Repositories HomeAutomation

Rev

Rev 1351 | Blame | Compare with Previous | 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.mode = 0;
  5. SensorMenuItem.prototype.currentSensorItem = 0;
  6. SensorMenuItem.prototype.window_low = 0;
  7. SensorMenuItem.prototype.window_high = 3; //set to nummber of rows you want to display minus 1
  8.  
  9.  
  10. function SensorMenuItem(parentDisplay, hd44789Object)
  11. {
  12.     var self = this;
  13.     this.parentDisplay = parentDisplay;
  14.     this.display = hd44789Object;  
  15. }
  16.  
  17. /* the display object who created the menu item */
  18. SensorMenuItem.prototype.parentDisplay = null;
  19. /* the display that we are writing to */
  20. SensorMenuItem.prototype.display = null;
  21.  
  22. /* How often the display shall update [ms]*/
  23. SensorMenuItem.prototype.UpdateTime = 5000;
  24.  
  25. /* what SensorMenuItem is left of this item, if used */
  26. SensorMenuItem.prototype.LeftItem = null;
  27. /* what SensorMenuItem is right of this item, if used */
  28. SensorMenuItem.prototype.RightItem = null;
  29. /* what SensorMenuItem is after of this item, if used */
  30. SensorMenuItem.prototype.PressEnterItem = null;
  31.  
  32. /*
  33. Standard events can be:
  34. left, right, enter, back, up, down....
  35. */
  36. SensorMenuItem.prototype.processEvent = function (event)
  37. {
  38.     switch (event)
  39.     {
  40.     case "right":
  41.         if (this.mode == 0) {
  42.             this.parentDisplay.changeToRight();
  43.         } else {
  44.             this.currentSensorItem--;
  45.             if (this.currentSensorItem == -1) {
  46.                 this.currentSensorItem= this.sensors.length-1;
  47. if (this.sensors.length-1 - (this.window_high-this.window_low) >= 0) {
  48.                 this.window_low = this.sensors.length-1 - (this.window_high-this.window_low);
  49.                 this.window_high = this.sensors.length-1;
  50.                 this.display.clearScreen();
  51. }
  52.             }
  53.             if (this.currentSensorItem < this.window_low ) {
  54.                 this.window_low--;
  55.                 this.window_high--;
  56.                 this.display.clearScreen();
  57.             }
  58.         }
  59.         break;
  60.     case "left":
  61.         if (this.mode == 0) {
  62.             this.parentDisplay.changeToLeft();
  63.         } else {
  64.             this.currentSensorItem++;
  65.             if (this.currentSensorItem == this.sensors.length) {
  66.                 this.currentSensorItem=0;
  67.                 this.window_high = this.window_high-this.window_low;
  68.                 this.window_low = 0;
  69.                 this.display.clearScreen();
  70.             }
  71.             if (this.currentSensorItem > this.window_high ) {
  72.                 this.window_low++;
  73.                 this.window_high++;
  74.                 this.display.clearScreen();
  75.             }
  76.         }
  77.         break;
  78.     case "enter":
  79.         if (this.mode == 0) {
  80.             if (this.sensors.length > 0) {
  81.                 this.currentSensorItem = 0;
  82.                 this.mode = 1;
  83.             }
  84.         } else {
  85.             this.mode = 0;
  86.         }
  87.         break;
  88.     }
  89. }
  90.  
  91. SensorMenuItem.prototype.onEnter = function ()
  92. {
  93.     this.sensors = getSensorList();
  94.     this.mode = 0;
  95.     this.display.clearScreen();
  96. }
  97. SensorMenuItem.prototype.update = function ()
  98. {
  99.     //this.display.clearScreen();
  100.     row = 0;
  101.     for (var i = this.window_low; i < this.sensors.length && i <= this.window_high; i++) {
  102.         if (this.mode == 1 && this.currentSensorItem == i) {
  103.             this.display.printText(0, row, ">"+ this.sensors[i]['shortName']);
  104.             this.display.printText(14, row,getSensorValue(this.sensors[i]['name']).toFixed(1).toString()+"¤C");
  105.  
  106.         } else {
  107.             this.display.printText(0, row, " "+ this.sensors[i]['shortName']);
  108.             this.display.printText(14, row,getSensorValue(this.sensors[i]['name']).toFixed(1).toString()+"¤C");
  109.         }
  110.         row++;
  111.     }
  112. }
  113.  
  114. SensorMenuItem.prototype.onExit = function ()
  115. {
  116.     this.mode = 0;
  117. }
  118.  
  119.  
  120.