9
9
import usb_hid
10
10
from adafruit_hid .keyboard import Keyboard
11
11
from adafruit_hid .keycode import Keycode
12
+ from adafruit_hid .mouse import Mouse
12
13
14
+ mouse = Mouse (usb_hid .devices )
13
15
# neopixel colors
14
16
RED = (255 , 0 , 0 )
15
17
ORANGE = (255 , 127 , 0 )
19
21
BLUE = (0 , 0 , 255 )
20
22
PURPLE = (127 , 0 , 255 )
21
23
PINK = (255 , 0 , 255 )
22
- OFF = (0 , 0 , 0 )
24
+ OFF = (50 , 50 , 50 )
23
25
# axis states selected with keys 9-11
24
26
axis_states = [0 , "x" , "y" , "z" ]
25
27
state = axis_states [0 ]
26
28
# keymap for key matrix
27
29
keymap = {
28
- (0 ): (axis_states [0 ], [ Keycode .HOME ], RED ), # HOME X/Y
29
- (1 ): (axis_states [0 ], [ Keycode .END ], ORANGE ), # HOME Z
30
- (2 ): (axis_states [0 ], (Keycode .HOME , Keycode .END ), YELLOW ), # HOME ALL
30
+ (0 ): (axis_states [0 ], ( Keycode .COMMAND , Keycode . COMMA ), BLUE ), # SETTINGS
31
+ (1 ): (axis_states [0 ], ( Keycode .COMMAND , Keycode . P ), ORANGE ), # SLICE MODEL
32
+ (2 ): (axis_states [0 ], (Keycode .COMMAND , Keycode .D ), RED ), # CLEAR BED
31
33
32
- (3 ): (axis_states [0 ], ( Keycode .SHIFT , Keycode . A ), GREEN ), # SHORTCUT A
33
- (4 ): (axis_states [0 ], ( Keycode .SHIFT , Keycode . B ), AQUA ), # SHORTCUT B
34
- (5 ): (axis_states [0 ], ( Keycode .SHIFT , Keycode . C ), BLUE ), # SHORTCUT C
34
+ (3 ): (axis_states [0 ], [ Keycode .T ], GREEN ), # MOVE
35
+ (4 ): (axis_states [0 ], [ Keycode .S ], AQUA ), # SCALE
36
+ (5 ): (axis_states [0 ], [ Keycode .R ], BLUE ), # ROTATE
35
37
36
- (6 ): (axis_states [0 ], [Keycode .TWO ], AQUA ), # SET STEPS 1MM
37
- (7 ): (axis_states [0 ], [Keycode .THREE ], PURPLE ), # SET STEPS 10MM
38
- (8 ): (axis_states [0 ], [Keycode .FOUR ], PINK ), # SET STEPS 100MM
38
+ (6 ): (axis_states [0 ], [Keycode .M ], AQUA ), # MIRROR
39
+ (7 ): (axis_states [0 ], [Keycode .E ], PURPLE ), # SUPPORT BLOCKERS
40
+ (8 ): (axis_states [0 ], [Keycode .I ], PINK ), # TABS
39
41
40
42
(9 ): (axis_states [1 ], None , RED ), # SET X-AXIS STATE
41
43
(10 ): (axis_states [2 ], None , GREEN ), # SET Y-AXIS STATE
45
47
encoder_map = {
46
48
("x" ): ([Keycode .RIGHT_ARROW ], [Keycode .LEFT_ARROW ]),
47
49
("y" ): ([Keycode .UP_ARROW ], [Keycode .DOWN_ARROW ]),
48
- ("z" ): ([Keycode .W ], [Keycode .S ]),
50
+ # ("z"): ([Keycode.W], [Keycode.S]),
49
51
}
50
52
# make a keyboard
51
53
kbd = Keyboard (usb_hid .devices )
@@ -88,7 +90,7 @@ def key_to_pixel_map(key_number):
88
90
kbd .press (* encoder_map [state ][0 ])
89
91
# ..and state is z:
90
92
if state is axis_states [3 ]:
91
- kbd . press ( * encoder_map [ state ][ 0 ] )
93
+ mouse . move ( wheel = - 1 )
92
94
# ..and it decreases..
93
95
if position < last_position :
94
96
# ..and state is x:
@@ -99,7 +101,7 @@ def key_to_pixel_map(key_number):
99
101
kbd .press (* encoder_map [state ][1 ])
100
102
# ..and state is z:
101
103
if state is axis_states [3 ]:
102
- kbd . press ( * encoder_map [ state ][ 1 ] )
104
+ mouse . move ( wheel = 1 )
103
105
# print(position)
104
106
# release all keys
105
107
kbd .release_all ()
0 commit comments