Subversion Repositories HomeAutomation

Rev

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

  1.  
  2. function Touch(type, name, id)
  3. {
  4.     this.CanService(type, name, id);
  5. }
  6.  
  7. extend(Touch, CanService);
  8.  
  9. Touch.prototype.myLastGesture = null;
  10. Touch.prototype.myLastX = null;
  11. Touch.prototype.myLastY = null;
  12. Touch.prototype.myLastState = "Released";
  13.  
  14. Touch.prototype.getLastGesture = function()
  15. {
  16.     return this.myLastGesture;
  17. }
  18. Touch.prototype.getLastState = function()
  19. {
  20.     return this.myLastState;
  21. }
  22. Touch.prototype.getLastX = function()
  23. {
  24.     return this.myLastX;
  25. }
  26. Touch.prototype.getLastY = function()
  27. {
  28.     return this.myLastY;
  29. }
  30.  
  31. Touch.prototype.canMessageHandler = function(canMessage)
  32. {
  33.     if (canMessage.getDirectionFlag() == "From_Owner")
  34.     {
  35.         switch (canMessage.getCommandName())
  36.         {
  37.         case "Gesture":
  38.             this.lookupGesture(canMessage.getData("f1"),canMessage.getData("f2"),canMessage.getData("f3"),canMessage.getData("f4"),canMessage.getData("f5"),canMessage.getData("f6"),canMessage.getData("f7"),canMessage.getData("f8"),canMessage.getData("f9"));
  39.        
  40.             if (this.myLastGesture == null)
  41.             {
  42.                 log(this.myName + ":" + this.myId + "> New Gesture, f1: " + canMessage.getData("f1") + ", f2: " + canMessage.getData("f2")+ ", f3: " + canMessage.getData("f3")+ ", f4: " + canMessage.getData("f4")+ ", f5: " + canMessage.getData("f5")+ ", f6: " + canMessage.getData("f6")+ ", f7: " + canMessage.getData("f7")+ ", f8: " + canMessage.getData("f8")+ ", f9: " + canMessage.getData("f9") +"\n");
  43.             }
  44.             else
  45.             {
  46.                 log(this.myName + ":" + this.myId + "> New Gesture: " + this.myLastGesture + "\n");
  47.             }
  48.        
  49.             this.callEvent("newGesture", null);
  50.             break;
  51.         case "Raw":
  52.             this.myLastX = canMessage.getData("X");
  53.             this.myLastY = canMessage.getData("Y");
  54.             if (this.myLastState == "Pressed" && canMessage.getData("Status") == "Released")
  55.             {
  56.                 this.myLastState = "Released";
  57.                 this.callEvent("rawStatus", null);
  58.             }
  59.             this.callEvent("rawTouch", null);
  60.             if (this.myLastState == "Released" && canMessage.getData("Status") == "Pressed")
  61.             {
  62.                 this.myLastState = "Pressed";
  63.                 this.callEvent("rawStatus", null);
  64.             }
  65.            
  66.             break;
  67.         }
  68.     }
  69.    
  70.     this.CanService.prototype.canMessageHandler.call(this, canMessage);
  71. }
  72.  
  73.  
  74. Touch.prototype.lookupGesture = function(f1, f2, f3, f4, f5, f6, f7, f8, f9)
  75. {
  76.     var gestureStore = DataStore.getStore("Gestures");
  77.     this.myLastGesture = null;
  78.     if (gestureStore)
  79.     {
  80.         for (var n = 0; n < gestureStore['gestures'].length; n++)
  81.         {
  82.             //log(this.myName + ":" + this.myId + "> Checking : " + gestureStore['gestures'][n]['name'] + "\n");
  83.             this.myLastGesture = null;
  84.             var result = 1;
  85.             if (gestureStore['gestures'][n]['masks']['f1_lower'] > f1 || gestureStore['gestures'][n]['masks']['f1_upper'] < f1)
  86.             {
  87.             //  log("1");
  88.                 result = 0;
  89.                 continue;
  90.             }
  91.             if (gestureStore['gestures'][n]['masks']['f2'] == 1 && gestureStore['gestures'][n]['functions']['f2'] != f2)
  92.             {
  93.             //  log("2");
  94.                 result = 0;
  95.                 continue;
  96.             }
  97.             if (gestureStore['gestures'][n]['masks']['f3'] == 1 && gestureStore['gestures'][n]['functions']['f3'] != f3)
  98.             {
  99.             //  log("3");
  100.                 result = 0;
  101.                 continue;
  102.             }
  103.             if (gestureStore['gestures'][n]['masks']['f4'] == 1 && gestureStore['gestures'][n]['functions']['f4'] != f4)
  104.             {
  105.             //  log("4");
  106.                 result = 0;
  107.                 continue;
  108.             }
  109.             if (gestureStore['gestures'][n]['masks']['f5'] == 1 && gestureStore['gestures'][n]['functions']['f5'] != f5)
  110.             {
  111.             //  log("5");
  112.                 result = 0;
  113.                 continue;
  114.             }
  115.             if (gestureStore['gestures'][n]['masks']['f6'] == 1 && gestureStore['gestures'][n]['functions']['f6'] != f6)
  116.             {
  117.             //  log("6");
  118.                 result = 0;
  119.                 continue;
  120.             }
  121.             if (gestureStore['gestures'][n]['masks']['f7_lower'] > f7 || gestureStore['gestures'][n]['masks']['f7_upper'] < f7)
  122.             {
  123.             //  log("7");
  124.                 result = 0;
  125.                 continue;
  126.             }
  127.             if (gestureStore['gestures'][n]['masks']['f8'] == 1 && gestureStore['gestures'][n]['functions']['f8'] != f8)
  128.             {
  129.             //  log("8");
  130.                 result = 0;
  131.                 continue;
  132.             }
  133.             if (gestureStore['gestures'][n]['masks']['f9'] == 1 && gestureStore['gestures'][n]['functions']['f9'] != f9)
  134.             {
  135.             //  log("9");
  136.                 result = 0;
  137.                 continue;
  138.             }
  139.             if (result == 1) {
  140.                 this.myLastGesture = gestureStore['gestures'][n]['name'];
  141.                 return;
  142.             }
  143.         }
  144.     }
  145.    
  146. }
  147.  
  148.