@@ -108,7 +108,14 @@ class APDS9960:
108
108
_proximity_persistance = RWBits (4 , APDS9960_PERS , 4 )
109
109
110
110
def __init__ (
111
- self , i2c , * , interrupt_pin = None , address = 0x39 , integration_time = 0x01 , gain = 0x01
111
+ self ,
112
+ i2c ,
113
+ * ,
114
+ interrupt_pin = None ,
115
+ address = 0x39 ,
116
+ integration_time = 0x01 ,
117
+ gain = 0x01 ,
118
+ rotation = 0
112
119
):
113
120
114
121
self .buf129 = None
@@ -125,6 +132,7 @@ def __init__(
125
132
self .enable_gesture = False
126
133
self .enable_proximity = False
127
134
self .enable_color = False
135
+ self ._rotation = rotation
128
136
self .enable_proximity_interrupt = False
129
137
self .clear_interrupt ()
130
138
@@ -169,6 +177,17 @@ def _reset_counts(self):
169
177
"""Proximity interrupt enable flag. True if enabled,
170
178
False to disable"""
171
179
180
+ ## GESTURE ROTATION
181
+ @property
182
+ def rotation (self ):
183
+ """Gesture rotation offset"""
184
+ return self ._rotation
185
+
186
+ @rotation .setter
187
+ def rotation (self , new_rotation ):
188
+ if new_rotation in [0 , 90 , 180 , 270 ]:
189
+ self ._rotation = new_rotation
190
+
172
191
## GESTURE DETECTION
173
192
@property
174
193
def enable_gesture (self ):
@@ -263,7 +282,14 @@ def gesture(self): # pylint: disable-msg=too-many-branches
263
282
if gesture_received or time .monotonic () - time_mark > 0.300 :
264
283
self ._reset_counts ()
265
284
break
266
-
285
+ if gesture_received != 0 :
286
+ if self ._rotation != 0 :
287
+ directions = [1 , 4 , 2 , 3 ]
288
+ new_index = (
289
+ directions .index (gesture_received ) + self ._rotation // 90
290
+ ) % 4
291
+ modified_gesture = directions [new_index ]
292
+ return modified_gesture
267
293
return gesture_received
268
294
269
295
@property
0 commit comments