-
Notifications
You must be signed in to change notification settings - Fork 0
/
test2.py
102 lines (82 loc) · 2.54 KB
/
test2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import digitalio
import board
## import usb_hid
import time
# from adafruit_hid.keyboard import Keyboard
# from adafruit_hid.mouse import Mouse
# from adafruit_hid.keycode import Keycode
# from adafruit_hid.consumer_control import ConsumerControl
# from adafruit_hid.consumer_control_code import ConsumerControlCode
print("== Pi Pico multifunction knob 1.0 ==")
CLK_PIN = board.D8
DT_PIN = board.D5
SW_PIN = board.D3
clk_last = None
count = 0
totalMode = 3
currentMode = 0
## cc = ConsumerControl(usb_hid.devices)
## mouse = Mouse(usb_hid.devices)
## keyboard = Keyboard(usb_hid.devices)
clk = digitalio.DigitalInOut(CLK_PIN)
clk.direction = digitalio.Direction.INPUT
dt = digitalio.DigitalInOut(DT_PIN)
dt.direction = digitalio.Direction.INPUT
sw = digitalio.DigitalInOut(SW_PIN)
sw.direction = digitalio.Direction.INPUT
sw.pull = digitalio.Pull.UP
def millis():
return time.monotonic() * 1000
# def ccw():
# print("CCW")
#
# if (currentMode == 0): # Mac brightness down
# keyboard.send(Keycode.SCROLL_LOCK)
#
# elif (currentMode == 1): # Mac horizontal scroll right
# keyboard.press(Keycode.SHIFT)
# mouse.move(wheel=-1)
# keyboard.release(Keycode.SHIFT)
#
# elif (currentMode == 2): # Volume decrement
# cc.send(ConsumerControlCode.VOLUME_DECREMENT)
# def cw():
# print("CW")
# if (currentMode == 0): # Mac brightness up
# keyboard.send(Keycode.PAUSE)
#
# elif (currentMode == 1): # Mac horizontal scroll left
# keyboard.press(Keycode.SHIFT)
# mouse.move(wheel=1)
# keyboard.release(Keycode.SHIFT)
#
# elif (currentMode == 2): # Volume increment
# cc.send(ConsumerControlCode.VOLUME_INCREMENT)
# def long_press():
# # Mac sleep: CMD + OPT + EJECT
# keyboard.press(Keycode.ALT, Keycode.COMMAND)
# cc.send(ConsumerControlCode.EJECT)
# keyboard.release_all()
while (1):
clkState = clk.value
if (clk_last != clkState):
if (dt.value != clkState):
# cw()
print("Right")
else:
# ccw()
print("Left")
if (sw.value == 0):
pressTime = millis()
time.sleep(0.2)
longPress = False
while (sw.value == 0):
if (millis() - pressTime > 1000 and not longPress):
print("longPress")
# longPress = True
# long_press()
# if (not longPress):
# currentMode += 1
# currentMode %= totalMode
# print("Mode: " + str(currentMode))
clk_last = clkState