Subversion Repositories HomeAutomation

Rev

Go to most recent revision | 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;
  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.             }
  48.             if (this.currentSensorItem < this.window_low ) {
  49.                 this.window_low--;
  50.                 this.window_high--;
  51.             }
  52.         }
  53.         break;
  54.     case "left":
  55.         if (this.mode == 0) {
  56.             this.parentDisplay.changeToLeft();
  57.         } else {
  58.             this.currentSensorItem++;
  59.             if (this.currentSensorItem == this.sensors.length) {
  60.                 this.currentSensorItem=0;
  61.             }
  62.             if (this.currentSensorItem > this.window_high ) {
  63.                 this.window_low++;
  64.                 this.window_high++;
  65.             }
  66.         }
  67.         break;
  68.     case "enter":
  69.         if (this.mode == 0) {
  70.             if (this.sensors.length > 0) {
  71.                 this.currentSensorItem = 0;
  72.                 this.mode = 1;
  73.             }
  74.         } else {
  75.             this.mode = 0;
  76.         }
  77.         break;
  78.     }
  79. }
  80.  
  81. SensorMenuItem.prototype.onEnter = function ()
  82. {
  83.     this.sensors = getSensorList();
  84.     this.mode = 0;
  85.     this.display.clearScreen();
  86. }
  87. SensorMenuItem.prototype.update = function ()
  88. {
  89.     //this.display.clearScreen();
  90. row = 0;
  91.     for (var i = this.window_low; i < this.sensors.length && i <= this.window_high; i++) {
  92.         if (this.mode == 1 && this.currentSensorItem == i) {
  93.             this.display.printText(0, row, ">"+ this.sensors[i]['shortName'] + " " +getSensorValue(this.sensors[i]['name']).toFixed(1).toString()+" C");
  94.         } else {
  95.             this.display.printText(0, row, " "+ this.sensors[i]['shortName'] + " " +getSensorValue(this.sensors[i]['name']).toFixed(1).toString()+" C");
  96.         }
  97. row++;
  98.     }
  99. }
  100.  
  101. SensorMenuItem.prototype.onExit = function ()
  102. {
  103.     this.mode = 0;
  104. }
  105.  
  106.  
  107.