Subversion Repositories HomeAutomation

Rev

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

  1.  
  2.  
  3. function TouchPanel(aliasnameRGBLED_red,aliasnameRGBLED_green, aliasnameRGBLED_blue, aliasnameTouch, aliasnameDimmer1, aliasnameDimmer2, aliasnameDimmer3)
  4. {
  5.  
  6. /* Declaration of instance variables, for static variables remove prototype */
  7.  
  8.     /* We must always call the parent constructor, initialization
  9.        of variables could be done here, but initialize is a better place */
  10.     var self = this;
  11.     this.myTouch = aliasnameTouch;
  12.     this.myRGBLED_red = aliasnameRGBLED_red;
  13.     this.myRGBLED_blue = aliasnameRGBLED_blue;
  14.     this.myRGBLED_green = aliasnameRGBLED_green;
  15.     this.myDimmer1 = aliasnameDimmer1;
  16.     this.myDimmer2 = aliasnameDimmer2;
  17.     this.myDimmer3 = aliasnameDimmer3;
  18.     this.myTouchMode = "Gesture";
  19.     this.myTouchRawX = 0;
  20.     this.myTouchRawY = 0;
  21.     this.myTouchRawYlast = 0;
  22.     Module_RegisterToOnMessage(aliasnameTouch, function(alias_name, command, variables) { self.touchOnMessage(alias_name, command, variables) });
  23.    
  24.     /* Start interval timer for sending timestamp to network. Arguments are the callback function and time in milliseconds
  25.     used to make sure an eth-node gets its init packet (600s) */
  26.     this.myTimer = Timer_SetTimer(function(timer) {self.timerUpdate(timer)}, 5000, true);
  27.     Log("\033[33mTouchpanel created.\033[0m");
  28.    
  29. }
  30.  
  31. /* Declaration of instance variables, for static variables remove prototype */
  32. TouchPanel.prototype.myDimmer1 = null;
  33. TouchPanel.prototype.myDimmer2 = null;
  34. TouchPanel.prototype.myDimmer3 = null;
  35. TouchPanel.prototype.myTouch = null;
  36. TouchPanel.prototype.myRGBLED_red = null;
  37. TouchPanel.prototype.myRGBLED_green = null;
  38. TouchPanel.prototype.myRGBLED_blue = null;
  39. //TouchPanel.prototype.outputStatus = "Low";
  40. TouchPanel.prototype.myInterval = null;
  41. //TouchPanel.prototype.oldPwmValue = 0;
  42. //TouchPanel.prototype.turnOffCnt = 0;
  43.  
  44. TouchPanel.prototype.myTouchMode = null;
  45. TouchPanel.prototype.myTouchRawX = null;
  46. TouchPanel.prototype.myTouchRawY = null;
  47. TouchPanel.prototype.myTouchRawYlast = null;
  48.  
  49. const XMIN = 40;
  50. const XMAX = 215;
  51. //const XLIMIT1 = XMIN + (XMAX-XMIN)/3;
  52. //const XLIMIT2 = XMIN*2 + (XMAX-XMIN)/3;
  53. const XLIMIT1 = 100;
  54. const XLIMIT2 = 155;
  55.  
  56.  
  57.  
  58. TouchPanel.prototype.touchOnMessage = function(alias_name, command, variables)
  59. {
  60. //Log("\033[33mMessage.\033[0m\n");
  61.     switch (command)
  62.     {
  63.         case "Gesture":
  64.             var gesture = null;
  65.             gesture = Touch_lookupGesture(variables["f1"],variables["f2"],variables["f3"],variables["f4"],variables["f5"],variables["f6"],variables["f7"],variables["f8"],variables["f9"]);
  66.             if (this.myTouchMode == "Gesture")
  67.             {
  68.                 var self = this;
  69.                 Log("New gesture: "+gesture);
  70.                 if (gesture == "INSERT")
  71.                 {
  72.                     ////getDimmerService('Badrum').absFade(2,132, 255);
  73.                     //getDimmerService('TakHall').absFade(0,132, 255);
  74.                     //getDimmerService('TakSovrum').absFade(0,132, 255);
  75.                     //Dimmer_AbsoluteFade(this.myDimmer1, 132, 255);
  76.                     Dimmer_AbsoluteFade(this.myDimmer2, 132, 255);
  77.                     Dimmer_AbsoluteFade(this.myDimmer3, 132, 255);
  78.                     this.setLED(0,255,0);
  79.                     Timer_Cancel(this.myInterval);
  80.                     this.myInterval = Timer_SetTimer(function(timer) {self.timerUpdate(timer)}, 5000, true);
  81.                 }
  82.                 else if (gesture == "JOIN")
  83.                 {
  84.                     //getDimmerService('Badrum').absFade(2,132, 0);
  85.                     //getDimmerService('TakHall').absFade(0,132, 0);
  86.                     //getDimmerService('TakSovrum').absFade(0,132, 0);
  87.                     Dimmer_AbsoluteFade(this.myDimmer1, 132, 0);
  88.                     Dimmer_AbsoluteFade(this.myDimmer2, 132, 0);
  89.                     Dimmer_AbsoluteFade(this.myDimmer3, 132, 0);
  90.                     this.setLED(0,0,255);
  91.                     Timer_Cancel(this.myInterval);
  92.                     this.myInterval = Timer_SetTimer(function(timer) {self.timerUpdate(timer)}, 5000, true);
  93.                    
  94.                 }
  95.                 /*else if (gesture == "UNDO")
  96.                 {
  97.                     Log("Going to raw mode\n");
  98.                     this.setLED(255,0,0);
  99.                     this.myTouchMode = "Raw";
  100.                
  101.                 } */
  102.                 else if (gesture == "COPY")
  103.                 {
  104.                     this.setLED(0,255,255);
  105.                     //getDimmerService('Badrum').absFade(2,132, 0);
  106.                     //getDimmerService('TakHall').absFade(0,117, 0);
  107.                     //getDimmerService('TakSovrum').absFade(0,105, 0);
  108.                     Dimmer_AbsoluteFade(this.myDimmer1, 132, 0);
  109.                     Dimmer_AbsoluteFade(this.myDimmer2, 117, 0);
  110.                     Dimmer_AbsoluteFade(this.myDimmer3, 103, 0);
  111.                     Timer_Cancel(this.myInterval);
  112.                     this.myInterval = Timer_SetTimer(function(timer) {self.timerUpdate(timer)}, 5000, true);
  113.                 }
  114.             }
  115.            
  116.            
  117.             break;
  118.         case "Raw":
  119.  
  120.             break;
  121.     }
  122.  
  123. }
  124.  
  125. TouchPanel.prototype.timerUpdate = function(timer)
  126. {
  127.     this.myTouchMode = "Gesture"
  128.     Log("Switching back to Gesture mode\n");
  129.     this.setLED(0,0,0);
  130.     Timer_Cancel(timer);
  131.     //this.myInterval = Timer_SetTimer(function(timer) {self.updateDisplay(timer)}, this.currentMenuItem.UpdateTime, true);
  132. }
  133.  
  134.  
  135. TouchPanel.prototype.setLED = function(red, green, blue)
  136. {
  137.     //log("setting LED\n");
  138.     softPWM_SetPWMValue(this.myRGBLED_red, 10000-(red&0xff)*39);
  139.     softPWM_SetPWMValue(this.myRGBLED_green, 10000-(green&0xff)*39);
  140.     softPWM_SetPWMValue(this.myRGBLED_blue, 10000-(blue&0xff)*39);
  141. }
  142.  
  143.  
  144. /*
  145.  
  146. TouchPanel.prototype.incomingStatusChanged = function()
  147. {
  148.     if (this.myTouchMode == "Raw")
  149.     {
  150.         if (this.myTouchPanelService.getLastState() == "Pressed")
  151.         {
  152.             this.myTouchRawX = this.myTouchPanelService.getLastX();
  153.             this.myTouchRawY = this.myTouchPanelService.getLastY();
  154.             this.myTouchRawYlast = this.myTouchPanelService.getLastY();
  155.         }
  156.         else if (this.myTouchPanelService.getLastState() == "Released")
  157.         {
  158.             *//*var currX = this.myTouchPanelService.getLastX();
  159.             var currY = this.myTouchPanelService.getLastY();
  160.             log("stored x "+this.myTouchRawX+" currx "+currX+" stored y "+this.myTouchRawY+" curry "+currY+"\n");
  161.             if (this.myTouchRawX < currX+8 && this.myTouchRawX > currX-8 && this.myTouchRawY < currY+8 && this.myTouchRawY > currY-8)
  162.             {
  163.                 log("activating next lightdevice\n");
  164.                 if (this.currentLightDevice.nextItem)
  165.                 {
  166.                     this.currentLightDevice = this.currentLightDevice.nextItem;
  167.                     this.currentLightDevice.doActivate();
  168.                 }
  169.             }
  170. *//*
  171. //log("starting timer\n");
  172.         this.myInterval.start();
  173.         }
  174.     }
  175. }
  176.  
  177. TouchPanel.prototype.incomingRaw = function()
  178. {
  179.    
  180.     if (this.myTouchMode == "Raw")
  181.     {
  182.         if (this.myTouchPanelService.getLastState() == "Pressed")
  183.         {
  184.             var yDiff = this.myTouchPanelService.getLastY() - this.myTouchRawYlast;
  185.             //var xPos = this.myTouchPanelService.getLastX();
  186.             if (yDiff > 0)
  187.             {  
  188.                 if (this.myTouchRawX < XLIMIT1) {
  189.                 //this.currentLightDevice.doRelIncrease(yDiff*2)
  190.                     getDimmerService('Badrum').relFade(2,132, "Increase", yDiff*2);
  191.                 } else if (this.myTouchRawX < XLIMIT2) {
  192.                     getDimmerService('TakHall').relFade(0,132, "Increase", yDiff*2);
  193.                 } else {
  194.                     getDimmerService('TakSovrum').relFade(0,132, "Increase", yDiff*2);
  195.                 }
  196.             }
  197.             else if (yDiff < 0)
  198.             {
  199.                 if (this.myTouchRawX < XLIMIT1) {
  200.                 //this.currentLightDevice.doRelIncrease(yDiff*2)
  201.                     getDimmerService('Badrum').relFade(2,132, "Decrease", yDiff*2);
  202.                 } else if (this.myTouchRawX < XLIMIT2) {
  203.                     getDimmerService('TakHall').relFade(0,132, "Decrease", yDiff*2);
  204.                 } else {
  205.                     getDimmerService('TakSovrum').relFade(0,132, "Decrease", yDiff*2);
  206.                 }
  207.             }
  208.             this.myTouchRawYlast = this.myTouchPanelService.getLastY();
  209.         }
  210.         //this.myInterval.stop();
  211.         //this.myInterval.start();
  212.     }
  213. }
  214. */
  215.  
  216.  
  217.