Subversion Repositories HomeAutomation

Rev

Blame | Last modification | View Log | SVN | RSS feed

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