Răsfoiți Sursa

ADded mouse absolute mode

Toby Chui 21 ore în urmă
părinte
comite
f1cd8456e9

+ 0 - 15
usbkvm/testcase_fw2/mouse_home.bat

@@ -1,15 +0,0 @@
-@echo off
-:: Move cursor to the top left corner
-.\send.exe COM4 115200 0x02 0x04 0x00
-timeout /t 3 /nobreak >nul
-
-:: Move cursor to the bottom left corner
-.\send.exe COM4 115200 0x02 0x04 0x01
-timeout /t 3 /nobreak >nul
-
-:: Move cursor to the top left corner
-.\send.exe COM4 115200 0x02 0x04 0x02
-timeout /t 3 /nobreak >nul
-
-:: Move cursor to the bottom right corner
-.\send.exe COM4 115200 0x02 0x04 0x03

+ 0 - 12
usbkvm/testcase_fw2/mouse_move.bat

@@ -1,12 +0,0 @@
-@echo off
-:: Move down x_value, y_value, x_positive, y_positive
-.\send.exe COM4 115200 0x03 0x00 0x80 0x00 0x00
-timeout /t 1 /nobreak >nul
-:: Move up
-.\send.exe COM4 115200 0x03 0x00 0x80 0x00 0x01
-timeout /t 1 /nobreak >nul
-:: Move right
-.\send.exe COM4 115200 0x03 0x80 0x00 0x00 0x00
-timeout /t 1 /nobreak >nul
-:: Move left
-.\send.exe COM4 115200 0x03 0x80 0x00 0x01 0x00

+ 22 - 0
usbkvm/testcase_fw2/mouse_move_abs.bat

@@ -0,0 +1,22 @@
+@echo off
+
+.\send.exe COM3 115200 0xFF
+timeout /t 1 /nobreak >nul
+
+:: Move cursor to the top left with 10% padding
+.\send.exe COM3 115200 0x05 0x09 0x9A 0x01 0x9A 0x01
+timeout /t 1 /nobreak >nul
+
+:: Move cursor to the bottom left corner
+.\send.exe COM3 115200 0x05 0x09 0x9A 0x01 0x5D 0x0E
+timeout /t 1 /nobreak >nul
+
+:: Move cursor to the bottom right corner
+.\send.exe COM3 115200 0x05 0x09 0x5D 0x0E 0x5D 0x0E
+timeout /t 1 /nobreak >nul
+
+:: Move cursor to the top right corner
+.\send.exe COM3 115200 0x05 0x09 0x5D 0x0E 0x9A 0x01
+
+
+

+ 17 - 0
usbkvm/testcase_fw2/mouse_move_rel.bat

@@ -0,0 +1,17 @@
+@echo off
+.\send.exe COM3 115200 0xFF
+
+:: Move down
+.\send.exe COM3 115200 0x03 0x0A 0x00 0x7F 
+timeout /t 1 /nobreak >nul
+
+:: Move up
+.\send.exe COM3 115200 0x03 0x0A 0x00 0x80
+timeout /t 1 /nobreak >nul
+
+:: Move right
+.\send.exe COM3 115200 0x03 0x0A 0x7F 0x00 
+timeout /t 1 /nobreak >nul
+
+:: Move left
+.\send.exe COM3 115200 0x03 0x0A 0x80 0x00 

+ 18 - 5
usbkvm/usbkvm_fw2/mouse_emu.ino

@@ -7,23 +7,29 @@
 uint8_t mouse_button_state = 0x00;
 
 //Move the mouse to given position, range 0 - 4096 for both x and y value
-void mouse_move_absolute(uint8_t x_lsb, uint8_t x_msb, uint8_t y_lsb, uint8_t y_msb) {
-  uint8_t packet[12] = {
+int mouse_move_absolute(uint8_t x_lsb, uint8_t x_msb, uint8_t y_lsb, uint8_t y_msb) {
+  uint8_t packet[13] = {
     0x57, 0xAB, 0x00, 0x04, 0x07, 0x02,
     mouse_button_state,
     x_lsb,  // X LSB
     x_msb,  // X MSB
     y_lsb,  // Y LSB
     y_msb,  // Y MSB
+    0x00,   // Scroll
     0x00    // Checksum placeholder
   };
 
-  packet[11] = calcChecksum(packet, 11);
-  Serial0_writeBuf(packet, 12);
+  packet[12] = calcChecksum(packet, 12);
+  Serial0_writeBuf(packet, 13);
+  return 0;
 }
 
 //Move the mouse to given relative position
-void mouse_move_relative(int8_t dx, int8_t dy, int8_t wheel) {
+int mouse_move_relative(uint8_t dx, uint8_t dy, uint8_t wheel) {
+  //Make sure 0x80 is not used
+  dx = (dx == 0x80)?0x81:dx;
+  dy = (dy == 0x80)?0x81:dy;
+  
   uint8_t packet[11] = {
     0x57, 0xAB, 0x00, 0x05, 0x05, 0x01,
     mouse_button_state,
@@ -35,6 +41,7 @@ void mouse_move_relative(int8_t dx, int8_t dy, int8_t wheel) {
 
   packet[10] = calcChecksum(packet, 10);
   Serial0_writeBuf(packet, 11);
+  return 0;
 }
 
 
@@ -101,4 +108,10 @@ int mouse_button_release(uint8_t opcode) {
   // Send updated button state with no movement
   mouse_move_relative(0, 0, 0);
   return 0;
+}
+
+//Reset all mouse clicks state
+void mouse_reset(){
+  mouse_button_state = 0x00;
+  mouse_move_relative(0, 0, 0);
 }

+ 15 - 2
usbkvm/usbkvm_fw2/usbkvm_fw2.ino

@@ -36,10 +36,14 @@ int keyboard_press_modkey(uint8_t opcode);
 int keyboard_release_modkey(uint8_t opcode);
 
 //mouse_emu.ino
+void mouse_reset();
 int mouse_button_press(uint8_t opcode);
 int mouse_button_release(uint8_t opcode);
 int mouse_scroll_up(uint8_t tilt);
 int mouse_scroll_down(uint8_t tilt);
+int mouse_move_relative(uint8_t dx, uint8_t dy, uint8_t wheel);
+int mouse_move_absolute(uint8_t x_lsb, uint8_t x_msb, uint8_t y_lsb, uint8_t y_msb);
+
 
 // Set the USB descriptor exposed to the slave device
 void setup_keyboard_chip_cfg() {
@@ -105,16 +109,24 @@ void handle_ctrl_cmd() {
       //Mouse scroll down
       ret = mouse_scroll_down(value);
       break;
+    case 0x09:
+      //Mouse move absolute
+      ret = mouse_move_absolute(cmdBuf[2], cmdBuf[3], cmdBuf[4], cmdBuf[5]);
+      break;
+    case 0x0A:
+      //Mouse move relative
+      ret = mouse_move_relative(cmdBuf[2], cmdBuf[3], 0);
+      break;
     default:
       //unknown operation, do nothing
       ret = -1;
       break;
   }
 
-  if (ret < 0){
+  if (ret < 0) {
     //Error
     USBSerial_print(0x01);
-  }else{
+  } else {
     USBSerial_print(0x00);
   }
 }
@@ -133,6 +145,7 @@ void loop() {
     if (c == 0xFF) {
       //Reset
       keyboard_reset();
+      mouse_reset();
       memset(cmdBuf, 0, sizeof(cmdBuf));
       cmdIndex = 0;
       cmdMaxLen = 0;