Skip to content

Commit 539e876

Browse files
committed
apds9960 返回手势为字符串
1 parent 14d45d4 commit 539e876

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

port/modules/apds9960.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@
165165
APDS9960_DIR_FAR = 6
166166
APDS9960_DIR_ALL = 7
167167

168+
GESTURES = {
169+
0:"none",
170+
1:"left",
171+
2:"right",
172+
3:"up",
173+
4:"down"
174+
}
175+
168176
# 状态定义
169177
APDS9960_STATE_NA = 0
170178
APDS9960_STATE_NEAR = 1
@@ -358,7 +366,8 @@ def readGesture(self):
358366

359367
# 确保电源和手势是打开的,数据是有效的
360368
if not (self.getMode() & 0b01000001) or not self.isGestureAvailable():
361-
return APDS9960_DIR_NONE
369+
# return APDS9960_DIR_NONE
370+
return "none"
362371

363372
# 只要手势数据有效,就保持循环
364373
while(self.isGestureAvailable()):
@@ -399,13 +408,16 @@ def readGesture(self):
399408
motion = self.gesture_motion_
400409

401410
self.resetGestureParameters()
402-
return motion
411+
# return motion
412+
Gesture = GESTURES.get(motion,0)
413+
return Gesture
414+
403415

404-
# 打开APDS-9960电源
416+
# 打开APDS9960电源
405417
def enablePower(self):
406418
self.setMode(APDS9960_MODE_POWER, True)
407419

408-
# 关闭APDS-9960电源
420+
# 关闭APDS9960电源
409421
def disablePower(self):
410422
self.setMode(APDS9960_MODE_POWER, False)
411423

0 commit comments

Comments
 (0)