Subversion Repositories HomeAutomation

Rev

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