Skip to content

Commit 426dd13

Browse files
committed
Initial commit. Application is able to initialize HID and read from it. Furthermore, it contains a lookup table for all keys
0 parents  commit 426dd13

6 files changed

Lines changed: 332 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
**/*.rs.bk

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "footswitch-rs"
3+
version = "0.1.0"
4+
authors = ["Dennis <dennis@dennispotter.eu>"]
5+
6+
[dependencies]
7+
structopt = "0.2.10"
8+
hidapi = "0.4.1"
9+
users = "0.7"
10+

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Dennis Potter <dennis@dennispotter.eu>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# footswitch-rs
2+
3+
This repository contains a C to Rust translation of the GitHub repository [rgerganov/footswitch](https://github.com/rgerganov/footswitch).

src/key_operations.rs

Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
// http://www.freebsddiary.org/APC/usb_hid_usages.php
2+
static KEY_MAP : &[(&str, u8)] = &[
3+
("<00>" , 0x00),
4+
("<01>" , 0x01),
5+
("<02>" , 0x02),
6+
("<03>" , 0x03),
7+
("a" , 0x04),
8+
("b" , 0x05),
9+
("c" , 0x06),
10+
("d" , 0x07),
11+
("e" , 0x08),
12+
("f" , 0x09),
13+
("g" , 0x0a),
14+
("h" , 0x0b),
15+
("i" , 0x0c),
16+
("j" , 0x0d),
17+
("k" , 0x0e),
18+
("l" , 0x0f),
19+
("m" , 0x10),
20+
("n" , 0x11),
21+
("o" , 0x12),
22+
("p" , 0x13),
23+
("q" , 0x14),
24+
("r" , 0x15),
25+
("s" , 0x16),
26+
("t" , 0x17),
27+
("u" , 0x18),
28+
("v" , 0x19),
29+
("w" , 0x1a),
30+
("x" , 0x1b),
31+
("y" , 0x1c),
32+
("z" , 0x1d),
33+
("1" , 0x1e),
34+
("2" , 0x1f),
35+
("3" , 0x20),
36+
("4" , 0x21),
37+
("5" , 0x22),
38+
("6" , 0x23),
39+
("7" , 0x24),
40+
("8" , 0x25),
41+
("9" , 0x26),
42+
("0" , 0x27),
43+
("enter" , 0x28),
44+
("Return" , 0x28),
45+
("esc" , 0x29),
46+
("Escape" , 0x29),
47+
("backspace" , 0x2a),
48+
("tab" , 0x2b),
49+
(" " , 0x2c),
50+
("space" , 0x2c),
51+
("-" , 0x2d),
52+
("=" , 0x2e),
53+
("[" , 0x2f),
54+
("]" , 0x30),
55+
("\\" , 0x31),
56+
("\\" , 0x32), // yes a repeat
57+
(";" , 0x33),
58+
("\'" , 0x34),
59+
("`" , 0x35),
60+
("," , 0x36),
61+
("." , 0x37),
62+
("/" , 0x38),
63+
("capslock" , 0x39),
64+
("f1" , 0x3a),
65+
("f2" , 0x3b),
66+
("f3" , 0x3c),
67+
("f4" , 0x3d),
68+
("f5" , 0x3e),
69+
("f6" , 0x3f),
70+
("f7" , 0x40),
71+
("f8" , 0x41),
72+
("f9" , 0x42),
73+
("f10" , 0x43),
74+
("f11" , 0x44),
75+
("f12" , 0x45),
76+
("f13" , 0x68),
77+
("f14" , 0x69),
78+
("f15" , 0x6A),
79+
("f16" , 0x6B),
80+
("f17" , 0x6C),
81+
("f18" , 0x6D),
82+
("f19" , 0x6E),
83+
("f20" , 0x6F),
84+
("f21" , 0x70),
85+
("f22" , 0x71),
86+
("f23" , 0x72),
87+
("f24" , 0x73),
88+
("printscreen" , 0x46),
89+
("scrollock" , 0x47),
90+
("pause" , 0x48),
91+
("insert" , 0x49),
92+
("home" , 0x4a),
93+
("pageup" , 0x4b),
94+
("Prior" , 0x4b),
95+
("delete" , 0x4c),
96+
("end" , 0x4d),
97+
("pagedown" , 0x4e),
98+
("Next" , 0x4e),
99+
("right" , 0x4f),
100+
("down" , 0x51),
101+
("left" , 0x50),
102+
("up" , 0x52),
103+
("numlock" , 0x53),
104+
("KP_Divide" , 0x54),
105+
("KP_Multiply" , 0x55),
106+
("KP_Subtract" , 0x56),
107+
("KP_Add" , 0x57),
108+
("KP_Enter" , 0x58),
109+
("KP_End" , 0x59),
110+
("KP_Down" , 0x5a),
111+
("KP_Next" , 0x5b),
112+
("KP_Left" , 0x5c),
113+
("KP_Begin" , 0x5d),
114+
("KP_Right" , 0x5e),
115+
("KP_Home" , 0x5f),
116+
("KP_Up" , 0x60),
117+
("KP_Prior" , 0x61),
118+
("KP_Insert" , 0x62),
119+
("KP_Delete" , 0x63),
120+
("less" , 0x64),
121+
("Multi_key" , 0x65),
122+
("compose" , 0x65),
123+
("XF86PowerOff" , 0x66),
124+
("KP_Equal" , 0x67),
125+
("XF86Tools" , 0x68),
126+
("XF86Launch5" , 0x69),
127+
("XF86MenuKB" , 0x6a),
128+
("XF86Launch7" , 0x6b),
129+
("XF86Launch8" , 0x6c),
130+
("XF86Launch9" , 0x6d),
131+
("<6e>" , 0x6e),
132+
("<6f>" , 0x6f),
133+
("XF86TouchpadToggle" , 0x70),
134+
("XF86TouchpadToggle" , 0x71),
135+
("XF86TouchpadOff" , 0x72),
136+
("<73>" , 0x73),
137+
("SunOpen" , 0x74),
138+
("Help" , 0x75),
139+
("SunProps" , 0x76),
140+
("SunFront" , 0x77),
141+
("Cancel" , 0x78),
142+
("Redo" , 0x79),
143+
("Undo" , 0x7a),
144+
("XF86Cut" , 0x7b),
145+
("XF86Copy" , 0x7c),
146+
("XF86Paste" , 0x7d),
147+
("Find" , 0x7e),
148+
("XF86AudioMute" , 0x7f),
149+
("XF86AudioRaiseVolume", 0x80),
150+
("XF86AudioLowerVolume", 0x81),
151+
("<82>" , 0x82),
152+
("<83>" , 0x83),
153+
("A" , 0x84),
154+
("B" , 0x85),
155+
("C" , 0x86),
156+
("D" , 0x87),
157+
("E" , 0x88),
158+
("F" , 0x89),
159+
("G" , 0x8a),
160+
("H" , 0x8b),
161+
("I" , 0x8c),
162+
("J" , 0x8d),
163+
("K" , 0x8e),
164+
("L" , 0x8f),
165+
("M" , 0x90),
166+
("N" , 0x91),
167+
("O" , 0x92),
168+
("P" , 0x93),
169+
("Q" , 0x94),
170+
("R" , 0x95),
171+
("S" , 0x96),
172+
("T" , 0x97),
173+
("U" , 0x98),
174+
("V" , 0x99),
175+
("W" , 0x9a),
176+
("X" , 0x9b),
177+
("Y" , 0x9c),
178+
("Z" , 0x9d),
179+
("!" , 0x9e),
180+
("@" , 0x9f),
181+
("#" , 0xa0),
182+
("$" , 0xa1),
183+
("%" , 0xa2),
184+
("^" , 0xa3),
185+
("&" , 0xa4),
186+
("*" , 0xa5),
187+
("(" , 0xa6),
188+
(")" , 0xa7),
189+
("<a8>" , 0xa8),
190+
("<a9>" , 0xa9),
191+
("<aa>" , 0xaa),
192+
("<ab>" , 0xab),
193+
("<ac>" , 0xac),
194+
("_" , 0xad),
195+
("+" , 0xae),
196+
("(" , 0xaf),
197+
(")" , 0xb0),
198+
("|" , 0xb1),
199+
("|" , 0xb2),
200+
(":" , 0xb3),
201+
("\"" , 0xb4),
202+
("~" , 0xb5),
203+
("<" , 0xb6),
204+
(">" , 0xb7),
205+
("?" , 0xb8),
206+
("<b9>" , 0xb9),
207+
("<ba>" , 0xba),
208+
("<bb>" , 0xbb),
209+
("<bc>" , 0xbc),
210+
("<bd>" , 0xbd),
211+
("<be>" , 0xbe),
212+
("<bf>" , 0xbf),
213+
("<c0>" , 0xc0),
214+
("<c1>" , 0xc1),
215+
("<c2>" , 0xc2),
216+
("<c3>" , 0xc3),
217+
("<c4>" , 0xc4),
218+
("<c5>" , 0xc5),
219+
("<c6>" , 0xc6),
220+
("<c7>" , 0xc7),
221+
("<c8>" , 0xc8),
222+
("<c9>" , 0xc9),
223+
("<ca>" , 0xca),
224+
("<cb>" , 0xcb),
225+
("<cc>" , 0xcc),
226+
("<cd>" , 0xcd),
227+
("<ce>" , 0xce),
228+
("<cf>" , 0xcf),
229+
("<d0>" , 0xd0),
230+
("<d1>" , 0xd1),
231+
("<d2>" , 0xd2),
232+
("<d3>" , 0xd3),
233+
("<d4>" , 0xd4),
234+
("<d5>" , 0xd5),
235+
("<d6>" , 0xd6),
236+
("<d7>" , 0xd7),
237+
("<d8>" , 0xd8),
238+
("<d9>" , 0xd9),
239+
("<da>" , 0xda),
240+
("<db>" , 0xdb),
241+
("<dc>" , 0xdc),
242+
("<dd>" , 0xdd),
243+
("<de>" , 0xde),
244+
("<df>" , 0xdf),
245+
("Control_L" , 0xe0),
246+
("Shift_L" , 0xe1),
247+
("Alt_L" , 0xe2),
248+
("Super_L" , 0xe3),
249+
("Control_R" , 0xe4),
250+
("Shift_R" , 0xe5),
251+
("Meta_R" , 0xe6),
252+
("Super_R" , 0xe7),
253+
("XF86AudioPause" , 0xe8),
254+
("XF86Eject" , 0xe9),
255+
("XF86AudioPrev" , 0xea),
256+
("XF86AudioNext" , 0xeb),
257+
("XF86Eject" , 0xec),
258+
("XF86AudioRaiseVolume", 0xed),
259+
("XF86AudioLowerVolume", 0xee),
260+
("XF86AudioMute" , 0xef),
261+
("XF86WWW" , 0xf0),
262+
("XF86Back" , 0xf1),
263+
("XF86Forward" , 0xf2),
264+
("Cancel" , 0xf3),
265+
("Find" , 0xf4),
266+
("XF86ScrollUp" , 0xf5),
267+
("XF86ScrollDown" , 0xf6),
268+
("<f7>" , 0xf7),
269+
("XF86Sleep" , 0xf8),
270+
("XF86ScreenSaver" , 0xf9),
271+
("XF86Reload" , 0xfa),
272+
("XF86Calculator" , 0xfb),
273+
("<fc>" , 0xfc),
274+
("<fd>" , 0xfd),
275+
("<fe>" , 0xfe),
276+
("<ff>" , 0xff),
277+
];
278+
279+
pub fn decode_byte(c: &str) -> u8 {
280+
for key in KEY_MAP.iter() {
281+
if key.0 == c {
282+
return key.1
283+
}
284+
}
285+
286+
return 0
287+
}
288+
289+
pub fn print_key_map(rows: usize) {
290+
291+
print!("{}", " ‖ Key Name ¦ Value ".repeat(rows));
292+
println!(" ‖");
293+
294+
println!(" {}", "-".repeat(rows*36));
295+
for (i, key) in KEY_MAP.iter().enumerate() {
296+
297+
print!(" ‖ {name:<-name_width$} ¦ <0x{value:>0value_width$x}> ",
298+
name=key.0, name_width=20, value = key.1, value_width = 2);
299+
300+
if (i + 1) % rows == 0 {
301+
println!(" ‖");
302+
}
303+
}
304+
305+
}

src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

0 commit comments

Comments
 (0)