Rev 1302 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1281 | linlun | 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; |
||
| 1300 | arune | 10 | Touch.prototype.myLastX = null; |
| 11 | Touch.prototype.myLastY = null; |
||
| 12 | Touch.prototype.myLastState = "Released"; |
||
| 1281 | linlun | 13 | |
| 1300 | arune | 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 | |||
| 1281 | linlun | 31 | Touch.prototype.canMessageHandler = function(canMessage) |
| 32 | { |
||
| 33 | if (canMessage.getDirectionFlag() == "From_Owner") |
||
| 34 | { |
||
| 35 | switch (canMessage.getCommandName()) |
||
| 36 | { |
||
| 37 | case "Gesture": |
||
| 1300 | arune | 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")); |
| 1281 | linlun | 39 | |
| 1300 | arune | 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 | } |
||
| 1281 | linlun | 48 | |
| 1300 | arune | 49 | this.callEvent("newGesture", null); |
| 50 | break; |
||
| 51 | case "Raw": |
||
| 1302 | arune | 52 | this.myLastX = canMessage.getData("X"); |
| 53 | this.myLastY = canMessage.getData("Y"); |
||
| 1300 | arune | 54 | if (this.myLastState == "Pressed" && canMessage.getData("Status") == "Released") |
| 55 | { |
||
| 1301 | arune | 56 | this.myLastState = "Released"; |
| 1300 | arune | 57 | this.callEvent("rawStatus", null); |
| 58 | } |
||
| 1303 | arune | 59 | this.callEvent("rawTouch", null); |
| 60 | if (this.myLastState == "Released" && canMessage.getData("Status") == "Pressed") |
||
| 1300 | arune | 61 | { |
| 1301 | arune | 62 | this.myLastState = "Pressed"; |
| 1300 | arune | 63 | this.callEvent("rawStatus", null); |
| 64 | } |
||
| 65 | |||
| 66 | break; |
||
| 1281 | linlun | 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 | { |
||
| 1283 | linlun | 82 | //log(this.myName + ":" + this.myId + "> Checking : " + gestureStore['gestures'][n]['name'] + "\n"); |
| 1282 | linlun | 83 | this.myLastGesture = null; |
| 1281 | linlun | 84 | var result = 1; |
| 1282 | linlun | 85 | if (gestureStore['gestures'][n]['masks']['f1_lower'] > f1 || gestureStore['gestures'][n]['masks']['f1_upper'] < f1) |
| 1281 | linlun | 86 | { |
| 1283 | linlun | 87 | // log("1"); |
| 1281 | linlun | 88 | result = 0; |
| 89 | continue; |
||
| 90 | } |
||
| 1282 | linlun | 91 | if (gestureStore['gestures'][n]['masks']['f2'] == 1 && gestureStore['gestures'][n]['functions']['f2'] != f2) |
| 1281 | linlun | 92 | { |
| 1283 | linlun | 93 | // log("2"); |
| 1281 | linlun | 94 | result = 0; |
| 95 | continue; |
||
| 96 | } |
||
| 1282 | linlun | 97 | if (gestureStore['gestures'][n]['masks']['f3'] == 1 && gestureStore['gestures'][n]['functions']['f3'] != f3) |
| 1281 | linlun | 98 | { |
| 1283 | linlun | 99 | // log("3"); |
| 1281 | linlun | 100 | result = 0; |
| 101 | continue; |
||
| 102 | } |
||
| 1282 | linlun | 103 | if (gestureStore['gestures'][n]['masks']['f4'] == 1 && gestureStore['gestures'][n]['functions']['f4'] != f4) |
| 1281 | linlun | 104 | { |
| 1283 | linlun | 105 | // log("4"); |
| 1281 | linlun | 106 | result = 0; |
| 107 | continue; |
||
| 108 | } |
||
| 1282 | linlun | 109 | if (gestureStore['gestures'][n]['masks']['f5'] == 1 && gestureStore['gestures'][n]['functions']['f5'] != f5) |
| 1281 | linlun | 110 | { |
| 1283 | linlun | 111 | // log("5"); |
| 1281 | linlun | 112 | result = 0; |
| 113 | continue; |
||
| 114 | } |
||
| 1282 | linlun | 115 | if (gestureStore['gestures'][n]['masks']['f6'] == 1 && gestureStore['gestures'][n]['functions']['f6'] != f6) |
| 1281 | linlun | 116 | { |
| 1283 | linlun | 117 | // log("6"); |
| 1281 | linlun | 118 | result = 0; |
| 119 | continue; |
||
| 120 | } |
||
| 1282 | linlun | 121 | if (gestureStore['gestures'][n]['masks']['f7_lower'] > f7 || gestureStore['gestures'][n]['masks']['f7_upper'] < f7) |
| 1281 | linlun | 122 | { |
| 1283 | linlun | 123 | // log("7"); |
| 1281 | linlun | 124 | result = 0; |
| 125 | continue; |
||
| 126 | } |
||
| 1282 | linlun | 127 | if (gestureStore['gestures'][n]['masks']['f8'] == 1 && gestureStore['gestures'][n]['functions']['f8'] != f8) |
| 1281 | linlun | 128 | { |
| 1283 | linlun | 129 | // log("8"); |
| 1281 | linlun | 130 | result = 0; |
| 131 | continue; |
||
| 132 | } |
||
| 1282 | linlun | 133 | if (gestureStore['gestures'][n]['masks']['f9'] == 1 && gestureStore['gestures'][n]['functions']['f9'] != f9) |
| 1281 | linlun | 134 | { |
| 1283 | linlun | 135 | // log("9"); |
| 1281 | linlun | 136 | result = 0; |
| 137 | continue; |
||
| 138 | } |
||
| 139 | if (result == 1) { |
||
| 1282 | linlun | 140 | this.myLastGesture = gestureStore['gestures'][n]['name']; |
| 141 | return; |
||
| 1281 | linlun | 142 | } |
| 143 | } |
||
| 144 | } |
||
| 1282 | linlun | 145 | |
| 1281 | linlun | 146 | } |
| 147 |