Subversion Repositories HomeAutomation

Rev

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