123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- #ifndef USER_USB_RAM
- #error "This firmware needs to be compiled with a USER USB setting"
- #endif
- #include "usbkvm_fw.h"
- #include "src/remdesHid/USBHIDKeyboardMouse.h"
- uint8_t instr_count = 0;
- uint8_t opr_type = 0x00;
- uint8_t opr_subtype = 0x00;
- uint8_t opr_payload = 0x00;
- uint8_t cursor_direction_data[2] = { 0x00, 0x00 };
- uint8_t serial_data = 0x00;
- uint8_t keyboard_emulation(uint8_t, uint8_t);
- uint8_t mouse_emulation(uint8_t, uint8_t);
- uint8_t mouse_move(uint8_t, uint8_t, uint8_t, uint8_t);
- uint8_t mouse_scroll(uint8_t, uint8_t);
- uint8_t kvm_execute_opr() {
- switch (opr_type) {
- case OPR_TYPE_RESERVED:
-
- return resp_ok;
- case OPR_TYPE_KEYBOARD_WRITE:
-
- return keyboard_emulation(opr_subtype, opr_payload);
- case OPR_TYPE_MOUSE_WRITE:
-
- return mouse_emulation(opr_subtype, opr_payload);
- case OPR_TYPE_MOUSE_SCROLL:
-
-
- return mouse_scroll(opr_subtype, opr_payload);
- default:
- return resp_unknown_opr;
- }
- return resp_ok;
- }
- void setup() {
- Serial0_begin(115200);
- pinMode(USB_SW_SEL, OUTPUT);
- pinMode(LED_RW_SIG, OUTPUT);
- digitalWrite(LED_RW_SIG, HIGH);
- digitalWrite(USB_SW_SEL, LOW);
- USBInit();
- }
- void loop() {
- if (Serial0_available()) {
- serial_data = 0x00;
- serial_data = Serial0_read();
- #ifdef ENABLE_DEBUG_PRINT
-
- Serial0_write(resp_start_of_info_msg);
- Serial0_write(serial_data);
- Serial0_write(resp_end_of_msg);
- #endif
- if (serial_data == OPR_TYPE_DATA_RESET) {
-
- opr_type = OPR_TYPE_RESERVED;
- opr_subtype = SUBTYPE_RESERVED;
- opr_payload = 0x00;
- instr_count = 0;
- Serial0_write(resp_ok);
- } else if (instr_count == 0) {
-
- opr_type = serial_data;
- instr_count++;
- Serial0_write(resp_ok);
- } else if (instr_count == 1) {
-
- opr_subtype = serial_data;
- instr_count++;
- Serial0_write(resp_ok);
- } else if (opr_type == OPR_TYPE_MOUSE_MOVE) {
-
- if (instr_count == 2) {
- opr_payload = serial_data;
- instr_count++;
- } else if (instr_count == 3) {
- cursor_direction_data[0] = serial_data;
- instr_count++;
- } else if (instr_count == 4) {
- cursor_direction_data[1] = serial_data;
- mouse_move(opr_subtype, opr_payload, cursor_direction_data[0], cursor_direction_data[1]);
- opr_type = OPR_TYPE_RESERVED;
- instr_count = 0;
- }
- } else {
- opr_payload = serial_data;
-
- uint8_t err = kvm_execute_opr();
- Serial0_write(err);
-
- instr_count = 0;
- }
- }
- delay(1);
- }
|