Subversion Repositories HomeAutomation

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2.  
  3. DimmerGlcdMenuItem.prototype.myDimmer230Service = null;
  4. DimmerGlcdMenuItem.prototype.myself;
  5. DimmerGlcdMenuItem.prototype.dimmerServices = new Array();
  6.  
  7. function DimmerGlcdMenuItem(parentDisplay, ks0108Object)
  8. {
  9.     this.parentDisplay = parentDisplay;
  10.     this.display = ks0108Object;
  11.     /* This is used for function declarations like the callbacks below */
  12.     myself = this;
  13. var self = this;
  14.     if (!this.parentDisplay.myInitialArguments["Dimmer230"])
  15.     {
  16.         log(this.myName + ":" + this.myId + "> Failed to initialize, Dimmer230-config missing from config.\n");
  17.         return;
  18.     }
  19. // Get the PWM service that we want from the ServiceManager, it takes type, service name, service id
  20.     this.myDimmer230Service = ServiceManager.getService("Can", "Dimmer230", parentDisplay.myInitialArguments["Dimmer230"]["Id"]);
  21.     // Add a callback for when the service goes online
  22.     this.myDimmer230Service.registerEventCallback("online", function(args) { self.Dimmer230Online(); });
  23. this.myDimmer230Service.registerEventCallback("newValue", function(args) { self.NewDimmerValue(); });
  24.     // If the service is already online we should call the handler here
  25.     this.Dimmer230Online();
  26. ServiceManager.addCallback(self.SeviceOnline);
  27.  
  28. }
  29. DimmerGlcdMenuItem.prototype.DimmerValue = 0;
  30.  
  31.  
  32. DimmerGlcdMenuItem.prototype.SeviceOnline = function(service) {
  33. log("Dimmer...0!\n");
  34. if (service.getName() == "Dimmer230") {
  35. log("Dimmer...1!\n");
  36. this.updateDimmerList();
  37. }
  38. }
  39.  
  40. DimmerGlcdMenuItem.prototype.updateDimmerList = function() {
  41.  
  42. for (var id in ServiceManager.Services)
  43. {if (ServiceManager.Services[id].getName() == "Dimmer230")
  44. {
  45. log("Dimmer...!\n");
  46. this.dimmerServices[dimmerServices.length] = ServiceManager.Services[id];
  47. }}}
  48.  
  49. DimmerGlcdMenuItem.prototype.Dimmer230Online = function()
  50. {
  51.     // If service is not online do nothing
  52.     if (this.myDimmer230Service.isOnline())
  53.     {
  54.         log("Dimmer is online!\n");
  55.     }
  56. }
  57.  
  58. DimmerGlcdMenuItem.prototype.NewDimmerValue = function()
  59. {
  60.     if (this.parentDisplay.currentMenuItem == this.myself)
  61.     {// If service is not online do nothing
  62.     if (this.display.isOnline()) {
  63.     this.display.printText(2,2,"Dimmer value: "+this.myDimmer230Service.currentValue + "  " ,"Standard","Standard");
  64. this.display.DrawRect(120,17,25,5,"Inverted","Fill",0);
  65. this.display.DrawRect(120,17,this.myDimmer230Service.currentValue/10,5,"Standard","Fill",0);
  66. this.display.DrawRect(120,17,25,5,"Standard","NoFill",0);
  67.  
  68.  
  69. }} else {
  70. this.DimmerValue = this.myDimmer230Service.currentValue
  71. }
  72. }
  73.  
  74. /* the display object who created the menu item */
  75. DimmerGlcdMenuItem.prototype.parentDisplay = null;
  76. /* the display that we are writing to */
  77. DimmerGlcdMenuItem.prototype.display = null;
  78.  
  79. /* what DimmerGlcdMenuItem is left of this item, if used */
  80. DimmerGlcdMenuItem.prototype.LeftItem = null;
  81. /* what DimmerGlcdMenuItem is right of this item, if used */
  82. DimmerGlcdMenuItem.prototype.RightItem = null;
  83. /* what DimmerGlcdMenuItem is after of this item, if used */
  84. DimmerGlcdMenuItem.prototype.PressEnterItem = null;
  85. /* what DimmerGlcdMenuItem is before of this item, if used */
  86. DimmerGlcdMenuItem.prototype.PressBackItem = null;
  87. /* what DimmerGlcdMenuItem is below of this item, if used */
  88. DimmerGlcdMenuItem.prototype.DownItem = null;
  89. /* what DimmerGlcdMenuItem is abowe of this item, if used */
  90. DimmerGlcdMenuItem.prototype.UpItem = null;
  91.  
  92. /*
  93. Standard events can be:
  94. left, right, enter, back, up, down....
  95. */
  96. DimmerGlcdMenuItem.prototype.processEvent = function (event)
  97. {
  98.     switch (event)
  99.     {
  100.     case "left":
  101.         this.parentDisplay.changeToLeft();
  102.         break;
  103.  
  104.     case "right":
  105.         this.parentDisplay.changeToRight();
  106.         break;
  107.    
  108.     case "up":
  109. this.DimmerValue += 25;
  110. if (this.DimmerValue > 255)
  111. this.DimmerValue = 255;
  112. this.myDimmer230Service.absFade(1, 132, this.DimmerValue);
  113.         //parentDisplay.changeToUp();
  114.         break;
  115.    
  116.     case "down":
  117. this.DimmerValue -= 25;
  118. if (this.DimmerValue < 0)
  119. this.DimmerValue = 0;
  120. this.myDimmer230Service.absFade(1, 132, this.DimmerValue);
  121.         //parentDisplay.changeToDown();
  122.         break;
  123.    
  124.     case "enter":
  125. this.display.printText(3,3,"enter ","Standard","Standard");
  126.         //parentDisplay.changeToEnter();
  127.         break;
  128.    
  129.     case "back":
  130. if (this.DimmerValue != 0)
  131. this.DimmerValue = 0;
  132. else
  133. this.DimmerValue = 255;
  134. this.myDimmer230Service.absFade(1, 129, this.DimmerValue);
  135.  
  136.         //parentDisplay.changeToBack();
  137.         break;
  138.     }
  139. }
  140.  
  141. DimmerGlcdMenuItem.prototype.onEnter = function ()
  142. {
  143.     this.display.clearScreen("Standard");
  144.     this.display.printText(0,0,"Dimmer menu:","Standard","Standard");
  145.     this.myDimmer230Service.absFade(1, 132, this.DimmerValue);
  146. for (var n in this.dimmerServices)
  147. {
  148. log("Dimmer: " + this.dimmerServices[n].getName() + " id: " + this.dimmerServices[n].getId() + "\n");
  149. }
  150.  
  151.  
  152. }
  153. DimmerGlcdMenuItem.prototype.update = function ()
  154. {
  155.  
  156. if (this.myDimmer230Service.isOnline()) {
  157. this.display.printText(2,2,"Dimmer value: "+this.DimmerValue + "  " ,"Standard","Standard");
  158. this.display.DrawRect(120,17,25,5,"Inverted","Fill",0);
  159. this.display.DrawRect(120,17,this.DimmerValue/10,5,"Standard","Fill",0);
  160. this.display.DrawRect(120,17,25,5,"Standard","NoFill",0);
  161.  
  162. }
  163. }
  164. DimmerGlcdMenuItem.prototype.onExit = function ()
  165. {
  166.    
  167. }
  168.  
  169.