Subversion Repositories HomeAutomation

Rev

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