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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
/* ========================================================================= #
# #
# KVMD - The main PiKVM daemon. #
# #
# Copyright (C) 2018-2023 Maxim Devaev <[email protected]> #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
# #
# ========================================================================= */
#include "tusb.h"
#include "ph_types.h"
#include "ph_tools.h"
#include "ph_proto.h"
#include "ph_outputs.h"
#include "ph_usb.h"
#include "ph_usb_keymap.h"
#include "ph_ps2.h"
u8 ph_cmd_kbd_get_leds(void) {
u8 leds = 0;
if (PH_O_IS_KBD_USB) {
leds = ph_g_usb_kbd_leds;
} else if (PH_O_IS_KBD_PS2) {
leds = ph_g_ps2_kbd_leds;
}
# define GET(x_mod) ((leds & KEYBOARD_LED_##x_mod##LOCK) ? PH_PROTO_PONG_##x_mod : 0)
return (GET(CAPS) | GET(SCROLL) | GET(NUM));
# undef GET
}
u8 ph_cmd_get_offlines(void) {
bool kbd_online = true;
if (PH_O_IS_KBD_USB) {
kbd_online = ph_g_usb_kbd_online;
} else if (PH_O_IS_KBD_PS2) {
kbd_online = ph_g_ps2_kbd_online;
}
bool mouse_online = true;
if (PH_O_IS_MOUSE_USB) {
mouse_online = ph_g_usb_mouse_online;
} else if (PH_O_IS_MOUSE_PS2) {
mouse_online = ph_g_ps2_mouse_online;
}
return (
(kbd_online ? 0 : PH_PROTO_PONG_KBD_OFFLINE)
| (mouse_online ? 0 : PH_PROTO_PONG_MOUSE_OFFLINE)
);
}
void ph_cmd_set_kbd(const u8 *args) { // 1 byte
ph_outputs_write(PH_PROTO_OUT1_KBD_MASK, args[0], false);
}
void ph_cmd_set_mouse(const u8 *args) { // 1 byte
ph_outputs_write(PH_PROTO_OUT1_MOUSE_MASK, args[0], false);
}
void ph_cmd_send_clear(const u8 *args) { // 0 bytes
(void)args;
ph_usb_send_clear();
ph_ps2_send_clear();
}
void ph_cmd_kbd_send_key(const u8 *args) { // 2 bytes
const u8 key = ph_usb_keymap(args[0]);
if (key > 0) {
if (PH_O_IS_KBD_USB) {
ph_usb_kbd_send_key(key, args[1]);
} else if (PH_O_IS_KBD_PS2) {
ph_ps2_kbd_send_key(key, args[1]);
}
}
}
void ph_cmd_mouse_send_button(const u8 *args) { // 2 bytes
# define HANDLE(x_byte_n, x_button) { \
if (args[x_byte_n] & PH_PROTO_CMD_MOUSE_##x_button##_SELECT) { \
const bool m_state = !!(args[x_byte_n] & PH_PROTO_CMD_MOUSE_##x_button##_STATE); \
if (PH_O_IS_MOUSE_USB) { \
ph_usb_mouse_send_button(MOUSE_BUTTON_##x_button, m_state); \
} else if (PH_O_IS_MOUSE_PS2) { \
ph_ps2_mouse_send_button(MOUSE_BUTTON_##x_button, m_state); \
} \
} \
}
HANDLE(0, LEFT);
HANDLE(0, RIGHT);
HANDLE(0, MIDDLE);
HANDLE(1, BACKWARD);
HANDLE(1, FORWARD);
# undef HANDLE
}
void ph_cmd_mouse_send_abs(const u8 *args) { // 4 bytes
if (PH_O_IS_MOUSE_USB_ABS) {
const s16 x = ph_merge8_s16(args[0], args[1]);
const s16 y = ph_merge8_s16(args[2], args[3]);
ph_usb_mouse_send_abs(x, y);
}
}
void ph_cmd_mouse_send_rel(const u8 *args) { // 2 bytes
if (PH_O_IS_MOUSE_USB_REL) {
ph_usb_mouse_send_rel(args[0], args[1]);
} else if (PH_O_IS_MOUSE_PS2) {
ph_ps2_mouse_send_rel(args[0], args[1]);
}
}
void ph_cmd_mouse_send_wheel(const u8 *args) { // 2 bytes
if (PH_O_IS_MOUSE_USB) {
ph_usb_mouse_send_wheel(args[0], args[1]);
} else if (PH_O_IS_MOUSE_PS2) {
ph_ps2_mouse_send_wheel(args[0], args[1]);
}
}
|