Browse Source

Added soft reset for HID device

TC 1 week ago
parent
commit
92b4c87dd5

+ 26 - 0
remdeskd/mod/remdeshid/ch9329.go

@@ -129,6 +129,30 @@ func (c *Controller) GetChipCurrentConfiguration() ([]byte, error) {
 	return resp, nil
 }
 
+func (c *Controller) ChipSoftReset() error {
+	//Send the command to get chip configuration and info
+	cmd := []byte{0x57, 0xAB,
+		0x00, 0x0F,
+		0x00, //placeholder for checksum
+	}
+
+	cmd[4] = calcChecksum(cmd[:4])
+	err := c.Send(cmd)
+	if err != nil {
+		fmt.Printf("Error sending command: %v\n", err)
+		return errors.New("failed to send command")
+	}
+
+	_, err = c.WaitForReply(0x0F)
+	if err != nil {
+		fmt.Printf("Error waiting for reply: %v\n", err)
+		return errors.New("failed to get reply")
+	}
+
+	fmt.Println("Chip soft reset successfully")
+	return nil
+}
+
 func (c *Controller) IsModifierKeys(keycode int) bool {
 	// Modifier keycodes for JavaScript
 	modifierKeys := []int{16, 17, 18, 91} // Shift, Ctrl, Alt, Meta (Windows/Command key)
@@ -215,6 +239,8 @@ func (c *Controller) ConstructAndSendCmd(HIDCommand *HIDCommand) ([]byte, error)
 		}
 		c.lastCursorEventTime = time.Now().UnixMilli()
 		return c.MouseScroll(HIDCommand.MouseScroll)
+	case EventTypeHIDReset:
+		return []byte{}, c.ChipSoftReset()
 	default:
 		return nil, fmt.Errorf("unsupported HID command event type: %d", HIDCommand.Event)
 	}

+ 0 - 1
remdeskd/mod/remdeshid/handler.go

@@ -32,7 +32,6 @@ func (c *Controller) HIDWebSocketHandler(w http.ResponseWriter, r *http.Request)
 			log.Println("Error reading message:", err)
 			break
 		}
-		//log.Printf("Received: %s", message)
 
 		//Try parsing the message as a HIDCommand
 		var hidCmd HIDCommand

+ 1 - 0
remdeskd/mod/remdeshid/typedef.go

@@ -14,6 +14,7 @@ const (
 	EventTypeMouseRelease
 	EventTypeMouseScroll
 	EventTypeHIDCommand
+	EventTypeHIDReset = 0xFF
 )
 
 const MinCusorEventInterval = 25 // Minimum interval between cursor events in milliseconds

+ 7 - 0
remdeskd/www/kvmevt.js

@@ -228,6 +228,13 @@ function startWebSocket(){
 
     socket.addEventListener('open', function(event) {
         console.log('HID Transport WebSocket is connected.');
+
+        // Send a soft reset command to the server to reset the HID state
+        // that possibly got out of sync from previous session
+        const hidResetCommand = {
+            event: 0xFF
+        };
+        socket.send(JSON.stringify(hidResetCommand));
     });
 
     socket.addEventListener('message', function(event) {

+ 1 - 0
remdeskd/www/main.css

@@ -19,6 +19,7 @@ body {
     display: block;
     margin: auto;
     object-fit: contain;
+    cursor: url('img/cursor_overlay.png') 10 10, pointer;
 }
 
 #menu {

+ 25 - 0
remdeskd/www/ui.js

@@ -44,4 +44,29 @@ function switchMassStorageToKvm(){
             alert('Error switching Mass Storage to KVM: ' + error);
         }
     });
+}
+
+function toggleFullScreen(){
+    let elem = document.documentElement;
+    if (!document.fullscreenElement) {
+        if (elem.requestFullscreen) {
+            elem.requestFullscreen();
+        } else if (elem.mozRequestFullScreen) { // Firefox
+            elem.mozRequestFullScreen();
+        } else if (elem.webkitRequestFullscreen) { // Chrome, Safari, Opera
+            elem.webkitRequestFullscreen();
+        } else if (elem.msRequestFullscreen) { // IE/Edge
+            elem.msRequestFullscreen();
+        }
+    } else {
+        if (document.exitFullscreen) {
+            document.exitFullscreen();
+        } else if (document.mozCancelFullScreen) {
+            document.mozCancelFullScreen();
+        } else if (document.webkitExitFullscreen) {
+            document.webkitExitFullscreen();
+        } else if (document.msExitFullscreen) {
+            document.msExitFullscreen();
+        }
+    }
 }