参开教程
https://oshwhub.com/Zoologist/esp32-shi-
硬件
CH9350
下位机状态下可以键鼠转串口
上位机状态下可以串口转键鼠,即模拟键鼠,
https://item.taobao.com/item.htm?_u=j1qf7bf595a4&id=597054931384
USB免驱动 Uart转HID 安卓模拟键盘鼠标 CH9329
串口转键鼠
https://item.taobao.com/item.htm?_u=j1qf7bf5e656&id=678502725576
1 调试
打开串口调试助手
设置数据
1.初始化时,使用下面的代码对于 CH9350 发送数据,这样 Ch9350只会发送有效的信息(就是说鼠标键盘有动作才会有数据出来)。
单片机代码
char SwitchToMode1[] = {0x57, 0xAB, 0x12, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x80, 0x00, 0x20}; for (int i = 0; i < sizeof(SwitchToMode1); i++) { Serial2.write(SwitchToMode1[i]); }
调试助手
57 AB 12 00 00 00 00 FF 80 00 20
2 数据解析
鼠标操作
左键按下和弹起
57 AB 88 0A 21 01 00 00 00 00 00 00 55 56 57 AB 88 0A 21 00 00 00 00 00 00 00 56 56
右键按下和弹起
57 AB 88 0A 21 02 00 00 00 00 00 00 5B 5D 57 AB 88 0A 21 00 00 00 00 00 00 00 5C 5C 57 AB 88 0A 21 02 00 00 00 00 00 00 5D 5F 57 AB 88 0A 21 00 00 00 00 00 00 00 5E 5E
滑轮按下和弹起
57 AB 88 0B 21 01 04 00 00 00 00 00 00 46 4B 57 AB 88 0B 21 01 00 00 00 00 00 00 00 47 48 57 AB 88 0B 21 01 04 00 00 00 00 00 00 48 4D 57 AB 88 0B 21 01 00 00 00 00 00 00 00 49 4A 57 AB 88 0B 21 01 04 00 00 00 00 00 00 4A 4F 57 AB 88 0B 21 01 00 00 00 00 00 00 00 4B 4C 57 AB 88 0B 21 01 04 00 00 00 00 00 00 4C 51
滑轮往前
57 AB 88 0B 21 01 00 00 00 00 00 01 00 93 95 57 AB 88 0B 21 01 00 00 00 00 00 00 00 94 95 57 AB 88 0B 21 01 00 00 00 00 00 01 00 95 97 57 AB 88 0B 21 01 00 00 00 00 00 00 00 96 97 57 AB 88 0B 21 01 00 00 00 00 00 01 00 97 99 57 AB 88 0B 21 01 00 00 00 00 00 00 00 98 99 57 AB 88 0B 21 01 00 00 00 00 00 01 00 99 9B 57 AB 88 0B 21 01 00 00 00 00 00 00 00 9A 9B 57 AB 88 0B 21 01 00 00 00 00 00 01 00 9B 9D 57 AB 88 0B 21 01 00 00 00 00 00 00 00 9C 9D 57 AB 88 0B 21 01 00 00 00 00 00 01 00 9D 9F 57 AB 88 0B 21 01 00 00 00 00 00 00 00 9E 9F
滑轮往后
[12:30:43.649]收←◆57 AB 88 0B 21 01 00 00 00 00 00 FF 00 57 57 57 AB 88 0B 21 01 00 00 00 00 00 00 00 58 59 [12:30:43.704]收←◆57 AB 88 0B 21 01 00 00 00 00 00 FF 00 59 59 57 AB 88 0B 21 01 00 00 00 00 00 00 00 5A 5B [12:30:44.230]收←◆57 AB 88 0B 21 01 00 00 00 00 00 FF 00 5B 5B 57 AB 88 0B 21 01 00 00 00 00 00 00 00 5C 5D [12:30:44.623]收←◆57 AB 88 0B 21 01 00 00 00 00 00 FF 00 5D 5D 57 AB 88 0B 21 01 00 00 00 00 00 00 00 5E 5F [12:30:44.717]收←◆57 AB 88 0B 21 01 00 00 00 00 00 FF 00 5F 5F 57 AB 88 0B 21 01 00 00 00 00 00 00 00 60 61 [12:30:45.016]收←◆57 AB 88 0B 21 01 00 00 00 00 00 FF 00 61 61 57 AB 88 0B 21 01 00 00 00 00 00 00 00 62 63 [12:30:45.088]收←◆57 AB 88 0B 21 01 00 00 00 00 00 FF 00 63 63 57 AB 88 0B 21 01 00 00 00 00 00 00 00 64 65 [12:30:45.372]收←◆57 AB 88 0B 21 01 00 00 00 00 00 FF 00 65 65 57 AB 88 0B 21 01 00 00 00 00 00 00 00 66 67 [12:30:45.417]收←◆57 AB 88 0B 21 01 00 00 00 00 00 FF 00 67 67 57 AB 88 0B 21 01 00 00 00 00 00 00 00 68 69 [12:30:45.726]收←◆57 AB 88 0B 21 01 00 00 00 00 00 FF 00 69 69 57 AB 88 0B 21 01 00 00 00 00 00 00 00 6A 6B [12:30:45.758]收←◆57 AB 88 0B 21 01 00 00 00 00 00 FF 00 6B 6B 57 AB 88 0B 21 01 00 00 00 00 00 00 00 6C 6D [12:30:45.816]收←◆57 AB 88 0B 21 01 00 00 00 00 00 FF 00 6D 6D 57 AB 88 0B 21 01 00 00 00 00 00 00 00 6E 6F [12:30:46.105]收←◆57 AB 88 0B 21 01 00 00 00 00 00 FF 00 6F 6F 57 AB 88 0B 21 01 00 00 00 00 00 00 00 70 71 [12:30:46.142]收←◆57 AB 88 0B 21 01 00 00 00 00 00 FF 00 71 71 57 AB 88 0B 21 01 00 00 00 00 00 00 00 72 73
鼠标左侧前按键按下和弹起
[12:32:44.632]收←◆57 AB 88 0B 21 01 10 00 00 00 00 00 00 BD CE [12:32:44.752]收←◆57 AB 88 0B 21 01 00 00 00 00 00 00 00 BE BF [12:32:44.832]收←◆57 AB 88 0B 21 01 10 00 00 00 00 00 00 BF D0 [12:32:44.952]收←◆57 AB 88 0B 21 01 00 00 00 00 00 00 00 C0 C1 [12:32:45.228]收←◆57 AB 88 0B 21 01 10 00 00 00 00 00 00 C1 D2 [12:32:45.321]收←◆57 AB 88 0B 21 01 00 00 00 00 00 00 00 C2 C3 [12:32:45.408]收←◆57 AB 88 0B 21 01 10 00 00 00 00 00 00 C3 D4 [12:32:45.492]收←◆57 AB 88 0B 21 01 00 00 00 00 00 00 00 C4 C5 [12:32:45.841]收←◆57 AB 88 0B 21 01 10 00 00 00 00 00 00 C5 D6 [12:32:45.916]收←◆57 AB 88 0B 21 01 00 00 00 00 00 00 00 C6 C7 [12:32:45.988]收←◆57 AB 88 0B 21 01 10 00 00 00 00 00 00 C7 D8 [12:32:46.081]收←◆57 AB 88 0B 21 01 00 00 00 00 00 00 00 C8 C9 [12:32:46.312]收←◆57 AB 88 0B 21 01 10 00 00 00 00 00 00 C9 DA [12:32:46.408]收←◆57 AB 88 0B 21 01 00 00 00 00 00 00 00 CA CB [12:32:46.473]收←◆57 AB 88 0B 21 01 10 00 00 00 00 00 00 CB DC [12:32:46.544]收←◆57 AB 88 0B 21 01 00 00 00 00 00 00 00 CC CD
鼠标左侧后按键按下和弹起
[12:33:59.242]收←◆57 AB 88 0B 21 01 08 00 00 00 00 00 00 01 0A [12:33:59.382]收←◆57 AB 88 0B 21 01 00 00 00 00 00 00 00 02 03 [12:33:59.666]收←◆57 AB 88 0B 21 01 08 00 00 00 00 00 00 03 0C [12:33:59.782]收←◆57 AB 88 0B 21 01 00 00 00 00 00 00 00 04 05 [12:34:00.013]收←◆57 AB 88 0B 21 01 08 00 00 00 00 00 00 05 0E [12:34:00.106]收←◆57 AB 88 0B 21 01 00 00 00 00 00 00 00 06 07 [12:34:00.301]收←◆57 AB 88 0B 21 01 08 00 00 00 00 00 00 07 10 [12:34:00.422]收←◆57 AB 88 0B 21 01 00 00 00 00 00 00 00 08 09 [12:34:00.554]收←◆57 AB 88 0B 21 01 08 00 00 00 00 00 00 09 12 [12:34:00.646]收←◆57 AB 88 0B 21 01 00 00 00 00 00 00 00 0A 0B [12:34:00.778]收←◆57 AB 88 0B 21 01 08 00 00 00 00 00 00 0B 14 [12:34:00.902]收←◆57 AB 88 0B 21 01 00 00 00 00 00 00 00 0C 0D
鼠标右侧两个按键没作用
鼠标滑轮后 两个按键 不记录了 数据超级长
鼠标移动
[12:37:22.188]收←◆57 AB 88 0B 21 01 00 00 00 FF FF 00 00 74 73 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 75 74 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 76 75 57 AB 88 0B 21 01 00 01 00 FF FF 00 00 77 77 57 AB 88 0B 21 01 00 01 00 FF FF 00 00 78 78 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 79 78 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 7A 79 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 7B 7A 57 AB 88 0B 21 01 00 01 00 FF FF 00 00 7C 7C 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 7D 7C 57 AB 88 0B 21 01 00 01 00 FF FF 00 00 7E 7E 57 AB 88 0B 21 01 00 00 00 FE FF 00 00 7F 7D 57 AB 88 0B 21 01 00 01 00 FF FF 00 00 80 80 57 AB 88 0B 21 01 00 01 00 FF FF 00 00 81 81 57 AB 88 0B 21 01 00 01 00 FF FF 00 00 82 82 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 83 82 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 84 83 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 85 84 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 86 85 57 AB 88 0B 21 01 00 01 00 FF FF 00 00 87 87 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 88 87 57 AB 88 0B 21 01 00 01 00 FF FF 00 00 89 89 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 8A 89 57 AB 88 0B 21 01 00 01 00 00 00 00 00 8B 8D 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 8C 8B 57 AB 88 0B 21 01 00 01 00 00 00 00 00 8D 8F [12:37:23.537]收←◆57 AB 88 0B 21 01 00 00 00 FF FF 00 00 8E 8D 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 8F 8E 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 90 8F 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 91 90 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 92 91 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 93 92 57 AB 88 0B 21 01 00 01 00 FF FF 00 00 94 94 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 95 94 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 96 95 57 AB 88 0B 21 01 00 01 00 FF FF 00 00 97 97 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 98 97 57 AB 88 0B 21 01 00 01 00 FF FF 00 00 99 99 57 AB 88 0B 21 01 00 01 00 FE FF 00 00 9A 99 57 AB 88 0B 21 01 00 00 00 FE FF 00 00 9B 99 57 AB 88 0B 21 01 00 01 00 FF FF 00 00 9C 9C 57 AB 88 0B 21 01 00 01 00 FF FF 00 00 9D 9D 57 AB 88 0B 21 01 00 01 00 FE FF 00 00 9E 9D 57 AB 88 0B 21 01 00 01 00 FE FF 00 00 9F 9E 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 A0 9F 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 A1 9F 57 AB 88 0B 21 01 00 01 00 FE FF 00 00 A2 A1 57 AB 88 0B 21 01 00 01 00 FE FF 00 00 A3 A2 57 AB 88 0B 21 01 00 01 00 FE FF 00 00 A4 A3 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 A5 A3 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 A6 A4 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 A7 A5 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 A8 A6 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 A9 A7 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 AA A8 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 AB A9 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 AC AA 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 AD AB 57 AB 88 0B 21 01 00 01 00 FC FF 00 00 AE AB 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 AF AD 57 AB 88 0B 21 01 00 01 00 FC FF 00 00 B0 AD 57 AB 88 0B 21 01 00 01 00 FC FF 00 00 B1 AE 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 B2 B0 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 B3 B1 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 B4 B2 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 B5 B3 57 AB 88 0B 21 01 00 01 00 FC FF 00 00 B6 B3 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 B7 B5 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 B8 B6 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 B9 B7 57 AB 88 0B 21 01 00 00 00 FD FF 00 00 BA B7 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 BB B9 57 AB 88 0B 21 01 00 01 00 FE FF 00 00 BC BB 57 AB 88 0B 21 01 00 00 00 FD FF 00 00 BD BA 57 AB 88 0B 21 01 00 00 00 FE FF 00 00 BE BC 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 BF BE 57 AB 88 0B 21 01 00 01 00 FE FF 00 00 C0 BF 57 AB 88 0B 21 01 00 01 00 FF FF 00 00 C1 C1 57 AB 88 0B 21 01 00 01 00 FF FF 00 00 C2 C2 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 C3 C2 57 AB 88 0B 21 01 00 01 00 00 00 00 00 C4 C6 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 C5 C4 57 AB 88 0B 21 01 00 01 00 00 00 00 00 C6 C8 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 C7 C6 57 AB 88 0B 21 01 00 01 00 00 00 00 00 C8 CA [12:37:24.690]收←◆57 AB 88 0B 21 01 00 00 00 FF FF 00 00 C9 C8 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 CA C9 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 CB CA 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 CC CB 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 CD CC 57 AB 88 0B 21 01 00 00 00 FE FF 00 00 CE CC 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 CF CE 57 AB 88 0B 21 01 00 01 00 FF FF 00 00 D0 D0 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 D1 D0 57 AB 88 0B 21 01 00 00 00 FE FF 00 00 D2 D0 57 AB 88 0B 21 01 00 00 00 FE FF 00 00 D3 D1 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 D4 D3 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 D5 D3 57 AB 88 0B 21 01 00 00 00 FE FF 00 00 D6 D4 57 AB 88 0B 21 01 00 00 00 FE FF 00 00 D7 D5 57 AB 88 0B 21 01 00 00 00 FE FF 00 00 D8 D6 57 AB 88 0B 21 01 00 00 00 FE FF 00 00 D9 D7 57 AB 88 0B 21 01 00 00 00 FE FF 00 00 DA D8 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 DB D9 57 AB 88 0B 21 01 00 00 00 FD FF 00 00 DC D9 57 AB 88 0B 21 01 00 00 00 FD FF 00 00 DD DA 57 AB 88 0B 21 01 00 00 00 FD FF 00 00 DE DB 57 AB 88 0B 21 01 00 01 00 FD FF 00 00 DF DD 57 AB 88 0B 21 01 00 00 00 FD FF 00 00 E0 DD 57 AB 88 0B 21 01 00 00 00 FD FF 00 00 E1 DE 57 AB 88 0B 21 01 00 00 00 FC FF 00 00 E2 DE 57 AB 88 0B 21 01 00 00 00 FC FF 00 00 E3 DF 57 AB 88 0B 21 01 00 00 00 FC FF 00 00 E4 E0 57 AB 88 0B 21 01 00 00 00 FC FF 00 00 E5 E1 57 AB 88 0B 21 01 00 00 00 FC FF 00 00 E6 E2 57 AB 88 0B 21 01 00 00 00 FD FF 00 00 E7 E4 57 AB 88 0B 21 01 00 00 00 FC FF 00 00 E8 E4 57 AB 88 0B 21 01 00 00 00 FD FF 00 00 E9 E6 57 AB 88 0B 21 01 00 00 00 FC FF 00 00 EA E6 57 AB 88 0B 21 01 00 00 00 FC FF 00 00 EB E7 57 AB 88 0B 21 01 00 FF FF FC FF 00 00 EC E6 57 AB 88 0B 21 01 00 00 00 FC FF 00 00 ED E9 57 AB 88 0B 21 01 00 00 00 FD FF 00 00 EE EB 57 AB 88 0B 21 01 00 00 00 FC FF 00 00 EF EB 57 AB 88 0B 21 01 00 00 00 FC FF 00 00 F0 EC 57 AB 88 0B 21 01 00 00 00 FC FF 00 00 F1 ED 57 AB 88 0B 21 01 00 00 00 FD FF 00 00 F2 EF 57 AB 88 0B 21 01 00 FF FF FC FF 00 00 F3 ED 57 AB 88 0B 21 01 00 00 00 FE FF 00 00 F4 F2 57 AB 88 0B 21 01 00 FF FF FD FF 00 00 F5 F0 57 AB 88 0B 21 01 00 00 00 FE FF 00 00 F6 F4 57 AB 88 0B 21 01 00 00 00 FE FF 00 00 F7 F5 57 AB 88 0B 21 01 00 00 00 FE FF 00 00 F8 F6 57 AB 88 0B 21 01 00 00 00 FE FF 00 00 F9 F7 57 AB 88 0B 21 01 00 FF FF FE FF 00 00 FA F6 57 AB 88 0B 21 01 00 FF FF FE FF 00 00 FB F7 57 AB 88 0B 21 01 00 00 00 FE FF 00 00 FC FA 57 AB 88 0B 21 01 00 FF FF FF FF 00 00 FD FA 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 FE FD 57 AB 88 0B 21 01 00 00 00 FE FF 00 00 FF FD 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 00 FF 57 AB 88 0B 21 01 00 FF FF FF FF 00 00 01 FE 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 02 01 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 03 02 57 AB 88 0B 21 01 00 FF FF FF FF 00 00 04 01 57 AB 88 0B 21 01 00 FF FF FF FF 00 00 05 02 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 06 05 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 07 06 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 08 07 57 AB 88 0B 21 01 00 FF FF 00 00 00 00 09 08 57 AB 88 0B 21 01 00 FF FF 00 00 00 00 0A 09 57 AB 88 0B 21 01 00 FF FF FF FF 00 00 0B 08 57 AB 88 0B 21 01 00 FF FF 00 00 00 00 0C 0B 57 AB 88 0B 21 01 00 00 00 FF FF 00 00 0D 0C 57 AB 88 0B 21 01 00 FF FF 00 00 00 00 0E 0D
键盘数据测试
程序控制
https://oshwhub.com/Zoologist/esp32-shi-
// 设置接收数据回调函数
// 数据接收回调函数 void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) { char *Starter = (char*)incomingData; if (len>72) {return;} while (Starter < (char *)(incomingData+len)) { if (verifyData((char*)Starter, Starter[3]+4)) { for (int i = 0; i < Starter[3]+4; i++) { Serial.print(Starter[i], HEX); Serial.print(" "); } Serial.println(" "); // 如果是鼠标 if (((Starter[4] >> 4) & 0x3) == 0x2) { device.directMS((char *)&Starter[5]); } //如果是键盘 if ((((Starter[4] >> 4) & 0x3) == 0x3)||(((Starter[4] >> 4) & 0x3) == 0x1)) { device.directKB((char *)&Starter[5]); } } Starter=&Starter[Starter[3]+4]; }//while (Start < (incomingDatalen)) }
标签:00,01,读取,Arduino,键鼠,57,88,AB,FF From: https://www.cnblogs.com/gooutlook/p/16805870.html