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. DimmerMenuItem.prototype.parentDisplay = null;
  3.  
  4. DimmerMenuItem.prototype.dimmers = null;
  5. DimmerMenuItem.prototype.mode = 0;
  6. DimmerMenuItem.prototype.currentDimmerItem = 0;
  7. DimmerMenuItem.prototype.window_low = 0;
  8. DimmerMenuItem.prototype.window_high = 3;
  9.  
  10. function DimmerMenuItem(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. DimmerMenuItem.prototype.parentDisplay = null;
  19. /* the display that we are writing to */
  20. DimmerMenuItem.prototype.display = null;
  21.  
  22. /* How often the display shall update [ms]*/
  23. DimmerMenuItem.prototype.UpdateTime = 5000;
  24.  
  25. /* what DimmerMenuItem is left of this item, if used */
  26. DimmerMenuItem.prototype.LeftItem = null;
  27. /* what DimmerMenuItem is right of this item, if used */
  28. DimmerMenuItem.prototype.RightItem = null;
  29. /* what DimmerMenuItem is after of this item, if used */
  30. DimmerMenuItem.prototype.PressEnterItem = null;
  31.  
  32. /*
  33. Standard events can be:
  34. left, right, enter, back, up, down....
  35. */
  36. DimmerMenuItem.prototype.processEvent = function (event)
  37. {
  38.     switch (event)
  39.     {
  40.     case "right":
  41.         if (this.mode == 0) {
  42.             this.parentDisplay.changeToRight();
  43.         } else if (this.mode == 1){
  44.             this.currentDimmerItem--;
  45.             if (this.currentDimmerItem < 0) {
  46.                 this.mode = 2;
  47. this.currentDimmerItem= this.dimmers.length-1;
  48.             }
  49.         } else if (this.mode == 3){
  50. this.dimmers[this.currentDimmerItem]['service'].relFade(this.dimmers[this.currentDimmerItem]['channel'],132, "Decrease", 25);
  51.         } else {
  52. this.mode = 1;
  53. this.currentDimmerItem= this.dimmers.length-1;
  54. if (this.dimmers.length-1 - (this.window_high-this.window_low) >= 0) {
  55.                 this.window_low = this.dimmers.length-1 - (this.window_high-this.window_low);
  56.                 this.window_high = this.dimmers.length-1;
  57.                 this.display.clearScreen();
  58. }
  59. }
  60. if (this.currentDimmerItem < this.window_low ) {
  61.                 this.window_low--;
  62.                 this.window_high--;
  63.                 this.display.clearScreen();
  64.             }
  65.         break;
  66.  
  67.     case "left":
  68.         if (this.mode == 0) {
  69.             this.parentDisplay.changeToLeft();
  70.         } else if (this.mode == 1){
  71.             this.currentDimmerItem++;
  72.             if (this.currentDimmerItem >= this.dimmers.length) {
  73.                 this.mode = 2;
  74. this.currentDimmerItem=0;
  75.             }
  76.         } else if (this.mode == 3){
  77. this.dimmers[this.currentDimmerItem]['service'].relFade(this.dimmers[this.currentDimmerItem]['channel'],132, "Increase", 25);
  78.         } else {
  79. this.mode = 1;
  80. this.currentDimmerItem=0;
  81.                 this.window_high = this.window_high-this.window_low;
  82.                 this.window_low = 0;
  83.                 this.display.clearScreen();
  84.  
  85. }
  86. if (this.currentDimmerItem > this.window_high ) {
  87.                 this.window_low++;
  88.                 this.window_high++;
  89.                 this.display.clearScreen();
  90.             }
  91.         break;
  92.     case "enter":
  93. if (this.mode == 0) {
  94.             if (this.dimmers.length > 0) {
  95.                 //this.currentDimmerItem = 0;
  96.                 this.mode = 1;
  97.             }
  98.         } else if (this.mode == 1){
  99.             this.mode = 3;
  100.         } else if (this.mode == 3) {
  101.             this.mode = 1;
  102.         } else {
  103.             this.mode = 0;
  104.         }
  105.         break;
  106.     }
  107. }
  108.  
  109. DimmerMenuItem.prototype.onEnter = function ()
  110. {
  111. this.dimmers = getDimmerList();
  112. this.mode = 0;
  113.     this.display.clearScreen();
  114. }
  115. DimmerMenuItem.prototype.update = function ()
  116. {
  117.     //this.display.clearScreen();
  118. if (this.mode != 2) {
  119. row = 0;
  120.  
  121.     for (var i = this.window_low; i < this.dimmers.length && i <= this.window_high; i++) {
  122. if (this.mode == 1 && this.currentDimmerItem == i) {
  123. this.display.printText(0, row, this.parentDisplay.lcdCenterText("-"+ this.dimmers[i]['name'] + " " +getDimmerValue(this.dimmers[i]['name'])+"   "));
  124. } else if (this.mode == 3 && this.currentDimmerItem == i) {
  125. this.display.printText(0, row, this.parentDisplay.lcdCenterText("<>"+ this.dimmers[i]['name'] + " " +getDimmerValue(this.dimmers[i]['name'])+"   "));
  126. } else {
  127. this.display.printText(0, row, this.parentDisplay.lcdCenterText(""+ this.dimmers[i]['name'] + " " +getDimmerValue(this.dimmers[i]['name'])+"   "));
  128.  
  129. }
  130. row++;
  131. }
  132. } else {
  133. this.display.clearScreen();
  134. this.display.printText(0, 0, this.parentDisplay.lcdCenterText("Tillbaka"));
  135. }
  136. }
  137.  
  138. DimmerMenuItem.prototype.onExit = function ()
  139. {
  140.     this.mode = 0;
  141. }
  142.  
  143.  
  144.