Subversion Repositories HomeAutomation

Rev

Rev 1351 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2.  
  3. /* the display object who created the menu item */
  4. DimmerGlcdMenuItem.prototype.parentDisplay = null;
  5.  
  6. DimmerGlcdMenuItem.prototype.dimmers = null;
  7. DimmerGlcdMenuItem.prototype.mode = 0;
  8. DimmerGlcdMenuItem.prototype.currentDimmerItem = 0;
  9. DimmerGlcdMenuItem.prototype.window_low = 0;
  10. DimmerGlcdMenuItem.prototype.window_high = 3;
  11.  
  12. function DimmerGlcdMenuItem(parentDisplay, ks0108Object)
  13. {
  14.     var self = this;
  15.     this.parentDisplay = parentDisplay;
  16.     this.display = ks0108Object;   
  17. }
  18.  
  19. /* the display object who created the menu item */
  20. DimmerGlcdMenuItem.prototype.parentDisplay = null;
  21. /* the display that we are writing to */
  22. DimmerGlcdMenuItem.prototype.display = null;
  23.  
  24. /* How often the display shall update [ms]*/
  25. DimmerGlcdMenuItem.prototype.UpdateTime = 5000;
  26.  
  27. /* what DimmerGlcdMenuItem is left of this item, if used */
  28. DimmerGlcdMenuItem.prototype.LeftItem = null;
  29. /* what DimmerGlcdMenuItem is right of this item, if used */
  30. DimmerGlcdMenuItem.prototype.RightItem = null;
  31. /* what DimmerGlcdMenuItem is after of this item, if used */
  32. DimmerGlcdMenuItem.prototype.PressEnterItem = null;
  33. /* what DimmerGlcdMenuItem is left of this item, if used */
  34. DimmerGlcdMenuItem.prototype.UpItem = null;
  35. /* what DimmerGlcdMenuItem is right of this item, if used */
  36. DimmerGlcdMenuItem.prototype.DownItem = null;
  37. /* what DimmerGlcdMenuItem is after of this item, if used */
  38. DimmerGlcdMenuItem.prototype.PressBackItem = null;
  39. /*
  40. Standard events can be:
  41. left, right, enter, back, up, down....
  42. */
  43. DimmerGlcdMenuItem.prototype.processEvent = function (event)
  44. {
  45.     switch (event)
  46.     {
  47.     case "right":
  48.         if (this.mode == 0) {
  49.             this.parentDisplay.changeToRight();
  50.         } else if (this.mode == 1){
  51.             this.currentDimmerItem--;
  52.             if (this.currentDimmerItem < 0) {
  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. this.display.DrawRect(4,17,150,8*(this.window_high-this.window_low+1),"Inverted","Fill",1);
  59. }
  60.             }
  61.         }
  62. if (this.currentDimmerItem < this.window_low ) {
  63.                 this.window_low--;
  64.                 this.window_high--;
  65.                 //this.display.clearScreen();
  66. this.display.DrawRect(4,17,150,8*(this.window_high-this.window_low+1),"Inverted","Fill",1);
  67.             }
  68.         break;
  69.  
  70.     case "left":
  71.         if (this.mode == 0) {
  72.             this.parentDisplay.changeToLeft();
  73.         } else if (this.mode == 1){
  74.             this.currentDimmerItem++;
  75.             if (this.currentDimmerItem >= this.dimmers.length) {
  76. this.currentDimmerItem=0;
  77.                 this.window_high = this.window_high-this.window_low;
  78.                 this.window_low = 0;
  79.                 //this.display.clearScreen();
  80. this.display.DrawRect(4,17,150,8*(this.window_high-this.window_low+1),"Inverted","Fill",1);
  81.             }
  82.         }
  83. if (this.currentDimmerItem > this.window_high ) {
  84.                 this.window_low++;
  85.                 this.window_high++;
  86.                 //this.display.clearScreen();
  87. this.display.DrawRect(4,17,150,8*(this.window_high-this.window_low+1),"Inverted","Fill",1);
  88.             }
  89.         break;
  90.     case "enter":
  91. if (this.mode == 0) {
  92.             if (this.dimmers.length > 0) {
  93.                 //this.currentDimmerItem = 0;
  94.                 this.mode = 1;
  95. this.display.DrawRect(1,17,3,8*(this.window_high-this.window_low+1),"Standard","Fill",0);
  96. //.DrawRect = function(x, y , width, height, inverted, fill, radius)
  97.  
  98.             }
  99.         } else {
  100.             this.mode = 0;
  101. this.display.DrawRect(1,17,3,8*(this.window_high-this.window_low+1),"Inverted","Fill",0);
  102.         }
  103.         break;
  104.     case "up":
  105. this.dimmers[this.currentDimmerItem]['service'].relFade(this.dimmers[this.currentDimmerItem]['channel'],132, "Increase", 25);
  106.         //parentDisplay.changeToUp();
  107.         break;
  108.    
  109.     case "down":
  110. this.dimmers[this.currentDimmerItem]['service'].relFade(this.dimmers[this.currentDimmerItem]['channel'],132, "Decrease", 25);
  111.         //parentDisplay.changeToDown();
  112.         break;
  113.    
  114.     case "back":
  115. if (this.dimmers[this.currentDimmerItem]['service'].currentValue != 0)
  116. this.dimmers[this.currentDimmerItem]['service'].absFade(1, 129, 0);
  117. else
  118. this.dimmers[this.currentDimmerItem]['service'].absFade(1, 129, 255);
  119.         //parentDisplay.changeToBack();
  120.         break;
  121.     }
  122. }
  123.  
  124. DimmerGlcdMenuItem.prototype.onEnter = function ()
  125. {
  126.     this.display.clearScreen("Standard");
  127.     this.display.printText(0,0,"Dimmer menu:","Standard","Standard");
  128. this.dimmers = getDimmerList();
  129. this.mode = 0;
  130. }
  131. DimmerGlcdMenuItem.prototype.update = function ()
  132. {
  133.     //this.display.clearScreen();
  134. row = 0;
  135.  
  136.     for (var i = this.window_low; i < this.dimmers.length && i <= this.window_high; i++) {
  137. if (this.currentDimmerItem == i) {
  138. this.display.printText(1, row+2, " >"+ this.dimmers[i]['shortName'],"Standard","Standard");
  139.  
  140.  
  141. } else {
  142. this.display.printText(1, row+2, "  "+ this.dimmers[i]['shortName'],"Standard","Standard");
  143.  
  144. }
  145. this.display.printText(16,row+2,""+(getDimmerValue(this.dimmers[i]['name'])/2.55).toFixed(0).toString() + "  " ,"Standard","Standard");
  146. this.display.DrawRect(120,17+row*8,25,5,"Inverted","Fill",0);
  147. this.display.DrawRect(120,17+row*8,getDimmerValue(this.dimmers[i]['name'])/10,5,"Standard","Fill",0);
  148. this.display.DrawRect(120,17+row*8,25,5,"Standard","NoFill",0);
  149.  
  150.  
  151. row++;
  152. }
  153. }
  154.  
  155. DimmerGlcdMenuItem.prototype.onExit = function ()
  156. {
  157.     this.mode = 0;
  158. }
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196. /*-----------------------------------------------------------------*/
  197. /*
  198. DimmerGlcdMenuItem.prototype.myDimmer230Service = null;
  199. DimmerGlcdMenuItem.prototype.myself;
  200. DimmerGlcdMenuItem.prototype.dimmerServices = new Array();
  201.  
  202. function DimmerGlcdMenuItem(parentDisplay, ks0108Object)
  203. {
  204.     this.parentDisplay = parentDisplay;
  205.     this.display = ks0108Object;
  206.     // This is used for function declarations like the callbacks below
  207.     myself = this;
  208. var self = this;
  209.     if (!this.parentDisplay.myInitialArguments["Dimmer230"])
  210.     {
  211.         log(this.myName + ":" + this.myId + "> Failed to initialize, Dimmer230-config missing from config.\n");
  212.         return;
  213.     }
  214. // Get the PWM service that we want from the ServiceManager, it takes type, service name, service id
  215.     this.myDimmer230Service = ServiceManager.getService("Can", "Dimmer230", parentDisplay.myInitialArguments["Dimmer230"]["Id"]);
  216.     // Add a callback for when the service goes online
  217.     this.myDimmer230Service.registerEventCallback("online", function(args) { self.Dimmer230Online(); });
  218. this.myDimmer230Service.registerEventCallback("newValue", function(args) { self.NewDimmerValue(); });
  219.     // If the service is already online we should call the handler here
  220.     this.Dimmer230Online();
  221. ServiceManager.addCallback(self.SeviceOnline);
  222.  
  223. }
  224. DimmerGlcdMenuItem.prototype.DimmerValue = 0;
  225.  
  226.  
  227. DimmerGlcdMenuItem.prototype.SeviceOnline = function(service) {
  228. log("Dimmer...0!\n");
  229. if (service.getName() == "Dimmer230") {
  230. log("Dimmer...1!\n");
  231. this.updateDimmerList();
  232. }
  233. }
  234.  
  235. DimmerGlcdMenuItem.prototype.updateDimmerList = function() {
  236.  
  237. for (var id in ServiceManager.Services)
  238. {if (ServiceManager.Services[id].getName() == "Dimmer230")
  239. {
  240. log("Dimmer...!\n");
  241. this.dimmerServices[dimmerServices.length] = ServiceManager.Services[id];
  242. }}}
  243.  
  244. DimmerGlcdMenuItem.prototype.Dimmer230Online = function()
  245. {
  246.     // If service is not online do nothing
  247.     if (this.myDimmer230Service.isOnline())
  248.     {
  249.         log("Dimmer is online!\n");
  250.     }
  251. }
  252.  
  253. DimmerGlcdMenuItem.prototype.NewDimmerValue = function()
  254. {
  255.     if (this.parentDisplay.currentMenuItem == this.myself)
  256.     {// If service is not online do nothing
  257.     if (this.display.isOnline()) {
  258.     this.display.printText(2,2,"Dimmer value: "+getDimmerService('TakSovrum').currentValue + "  " ,"Standard","Standard");
  259. this.display.DrawRect(120,17,25,5,"Inverted","Fill",0);
  260. this.display.DrawRect(120,17,getDimmerService('TakSovrum').currentValue/10,5,"Standard","Fill",0);
  261. this.display.DrawRect(120,17,25,5,"Standard","NoFill",0);
  262.  
  263.  
  264. }} else {
  265. this.DimmerValue = getDimmerService('TakSovrum').currentValue
  266. }
  267. }
  268. */
  269. /* the display object who created the menu item */
  270. //DimmerGlcdMenuItem.prototype.parentDisplay = null;
  271. /* the display that we are writing to */
  272. //DimmerGlcdMenuItem.prototype.display = null;
  273.  
  274. /* what DimmerGlcdMenuItem is left of this item, if used */
  275. //DimmerGlcdMenuItem.prototype.LeftItem = null;
  276. /* what DimmerGlcdMenuItem is right of this item, if used */
  277. //DimmerGlcdMenuItem.prototype.RightItem = null;
  278. /* what DimmerGlcdMenuItem is after of this item, if used */
  279. //DimmerGlcdMenuItem.prototype.PressEnterItem = null;
  280. /* what DimmerGlcdMenuItem is before of this item, if used */
  281. //DimmerGlcdMenuItem.prototype.PressBackItem = null;
  282. /* what DimmerGlcdMenuItem is below of this item, if used */
  283. //DimmerGlcdMenuItem.prototype.DownItem = null;
  284. /* what DimmerGlcdMenuItem is abowe of this item, if used */
  285. //DimmerGlcdMenuItem.prototype.UpItem = null;
  286.  
  287. /*
  288. Standard events can be:
  289. left, right, enter, back, up, down....
  290. */
  291. /*
  292. DimmerGlcdMenuItem.prototype.processEvent = function (event)
  293. {
  294.     switch (event)
  295.     {
  296.     case "left":
  297.         this.parentDisplay.changeToLeft();
  298.         break;
  299.  
  300.     case "right":
  301.         this.parentDisplay.changeToRight();
  302.         break;
  303.    
  304.     case "up":
  305. this.DimmerValue += 25;
  306. if (this.DimmerValue > 255)
  307. this.DimmerValue = 255;
  308. getDimmerService('TakSovrum').absFade(1, 132, this.DimmerValue);
  309.         //parentDisplay.changeToUp();
  310.         break;
  311.    
  312.     case "down":
  313. this.DimmerValue -= 25;
  314. if (this.DimmerValue < 0)
  315. this.DimmerValue = 0;
  316. getDimmerService('TakSovrum').absFade(1, 132, this.DimmerValue);
  317.         //parentDisplay.changeToDown();
  318.         break;
  319.    
  320.     case "enter":
  321. this.display.printText(3,3,"enter ","Standard","Standard");
  322.         //parentDisplay.changeToEnter();
  323.         break;
  324.    
  325.     case "back":
  326. if (this.DimmerValue != 0)
  327. this.DimmerValue = 0;
  328. else
  329. this.DimmerValue = 255;
  330. getDimmerService('TakSovrum').absFade(1, 129, this.DimmerValue);
  331.  
  332.         //parentDisplay.changeToBack();
  333.         break;
  334.     }
  335. }
  336.  
  337. DimmerGlcdMenuItem.prototype.onEnter = function ()
  338. {
  339.     this.display.clearScreen("Standard");
  340.     this.display.printText(0,0,"Dimmer menu:","Standard","Standard");
  341.     getDimmerService('TakSovrum').absFade(1, 132, this.DimmerValue);
  342. for (var n in this.dimmerServices)
  343. {
  344. log("Dimmer: " + this.dimmerServices[n].getName() + " id: " + this.dimmerServices[n].getId() + "\n");
  345. }
  346.  
  347.  
  348. }
  349. DimmerGlcdMenuItem.prototype.update = function ()
  350. {
  351.  
  352. if (getDimmerService('TakSovrum').isOnline()) {
  353. this.display.printText(2,2,"Dimmer value: "+this.DimmerValue + "  " ,"Standard","Standard");
  354. this.display.DrawRect(120,17,25,5,"Inverted","Fill",0);
  355. this.display.DrawRect(120,17,this.DimmerValue/10,5,"Standard","Fill",0);
  356. this.display.DrawRect(120,17,25,5,"Standard","NoFill",0);
  357.  
  358. }
  359. }
  360. DimmerGlcdMenuItem.prototype.onExit = function ()
  361. {
  362.    
  363. }
  364. */
  365.