Browse Source

Final ver of v2 fw driver

TC 1 day ago
parent
commit
af4c98c31c

+ 2 - 2
remdeskd/main.go

@@ -17,7 +17,7 @@ import (
 const development = true
 
 var (
-	usbKVMDeviceName  = flag.String("usbkvm", "/dev/ttyUSB0", "USB KVM device file path")
+	usbKVMDeviceName  = flag.String("usbkvm", "/dev/ttyACM0", "USB KVM device file path")
 	usbKVMBaudRate    = flag.Int("baudrate", 115200, "USB KVM baud rate")
 	captureDeviceName = flag.String("capture", "/dev/video0", "Video capture device file path")
 	usbKVM            *remdeshid.Controller
@@ -74,7 +74,7 @@ func main() {
 	err = videoCapture.StartVideoCapture(&usbcapture.CaptureResolution{
 		Width:  1920,
 		Height: 1080,
-		FPS:    25,
+		FPS:    10,
 	})
 	if err != nil {
 		log.Fatal(err)

+ 151 - 14
remdeskd/mod/remdeshid/handler.go

@@ -10,12 +10,30 @@ import (
 	"github.com/gorilla/websocket"
 )
 
+type EventType int
+
+const (
+	EventTypeKeyPress EventType = iota
+	EventTypeKeyRelease
+	EventTypeMouseMove
+	EventTypeMousePress
+	EventTypeMouseRelease
+	EventTypeMouseScroll
+	EventTypeHIDCommand
+)
+
+const MinCusrorEventInterval = 1 //ms
+
 type HIDCommand struct {
-	EventType    string `json:"t"`
-	EventSubType string `json:"s"`
-	Data         string `json:"d"`
-	PosX         int    `json:"x"` //Only used for mouse events
-	PosY         int    `json:"y"` //Only used for mouse events
+	Event         EventType `json:"event"`
+	Keycode       int       `json:"keycode,omitempty"`
+	IsRightModKey bool      `json:"is_right_modifier_key,omitempty"` // true if the key is a right modifier key (Ctrl, Shift, Alt, GUI)
+	MouseAbsX     int       `json:"mouse_x,omitempty"`               // Absolute mouse position in X direction
+	MouseAbsY     int       `json:"mouse_y,omitempty"`               // Absolute mouse position in Y direction
+	MouseRelX     int       `json:"mouse_rel_x,omitempty"`           // Relative mouse movement in X direction
+	MouseRelY     int       `json:"mouse_rel_y,omitempty"`           // Relative mouse movement in Y direction
+	MouseButton   int       `json:"mouse_button,omitempty"`          //0x01 for left click, 0x02 for right click, 0x03 for middle clicks
+	MouseScroll   int       `json:"mouse_scroll,omitempty"`          // Positive for scroll up, negative for scroll down, max 127
 }
 
 // HIDWebSocketHandler is a handler for the HID WebSocket connection
@@ -27,6 +45,127 @@ var upgrader = websocket.Upgrader{
 	},
 }
 
+func (c *Controller) IsModifierKeys(keycode int) bool {
+	// Modifier keycodes for JavaScript
+	modifierKeys := []int{16, 17, 18, 91} // Shift, Ctrl, Alt, Meta (Windows/Command key)
+	for _, key := range modifierKeys {
+		if keycode == key {
+			return true
+		}
+	}
+	return false
+}
+
+// Convert a keycode to the corresponding HID opcode for modifier keys
+func (c *Controller) GetModkeyOpcode(keycode int, isRight bool) int {
+	switch keycode {
+	case 17: // Ctrl
+		if isRight {
+			return 0x05 // Right Ctrl
+		}
+		return 0x01 // Left Ctrl
+	case 16: // Shift
+		if isRight {
+			return 0x06 // Right Shift
+		}
+		return 0x02 // Left Shift
+	case 18: // Alt
+		if isRight {
+			return 0x07 // Right Alt
+		}
+		return 0x03 // Left Alt
+	case 91: // Meta (Windows/Command key)
+		if isRight {
+			return 0x08 // Right GUI (Windows)
+		}
+		return 0x04 // Left GUI (Windows)
+	default:
+		return 0x00 // Unknown or unmapped key
+	}
+}
+
+// Generate the required LTV (length, type, value) bytes for the HID command
+func (c *Controller) GenerateUARTCmd(HIDCommand *HIDCommand) ([]byte, error) {
+	switch HIDCommand.Event {
+	case EventTypeKeyPress:
+		if c.IsModifierKeys(HIDCommand.Keycode) {
+			// If it's a modifier key, we need to return the appropriate opcode
+			opcode := c.GetModkeyOpcode(HIDCommand.Keycode, HIDCommand.IsRightModKey)
+			if opcode == 0x00 {
+				return nil, fmt.Errorf("unsupported modifier key: %d", HIDCommand.Keycode)
+			}
+			return []byte{0x02, 0x03, byte(opcode)}, nil
+		} else if HIDCommand.Keycode == 13 && HIDCommand.IsRightModKey {
+			//Special case for right Enter key
+			return []byte{0x02, 0x01, 0x92}, nil
+		}
+		return []byte{0x02, 0x01, byte(HIDCommand.Keycode)}, nil
+	case EventTypeKeyRelease:
+		if c.IsModifierKeys(HIDCommand.Keycode) {
+			// If it's a modifier key, we need to return the appropriate opcode
+			opcode := c.GetModkeyOpcode(HIDCommand.Keycode, HIDCommand.IsRightModKey)
+			if opcode == 0x00 {
+				return nil, fmt.Errorf("unsupported modifier key: %d", HIDCommand.Keycode)
+			}
+			return []byte{0x02, 0x04, byte(opcode)}, nil
+		} else if HIDCommand.Keycode == 13 && HIDCommand.IsRightModKey {
+			//Special case for right Enter key
+			return []byte{0x02, 0x02, 0x92}, nil
+		}
+		return []byte{0x02, 0x02, byte(HIDCommand.Keycode)}, nil
+	case EventTypeMouseMove:
+		if (time.Now().UnixMilli() - c.lastCursorEventTime) < MinCusrorEventInterval {
+			// If the last cursor event was too recent, we skip sending this one
+			return []byte{}, nil
+		}
+		c.lastCursorEventTime = time.Now().UnixMilli()
+		if HIDCommand.MouseAbsX != 0 || HIDCommand.MouseAbsY != 0 {
+			// If absolute mouse movement is specified, we send it as a single command
+			xLSB := byte(HIDCommand.MouseAbsX & 0xFF)
+			xMSB := byte((HIDCommand.MouseAbsX >> 8) & 0xFF)
+			yLSB := byte(HIDCommand.MouseAbsY & 0xFF)
+			yMSB := byte((HIDCommand.MouseAbsY >> 8) & 0xFF)
+			return []byte{0x05, 0x09, xLSB, xMSB, yLSB, yMSB}, nil
+		} else if HIDCommand.MouseRelX != 0 || HIDCommand.MouseRelY != 0 {
+			// If relative mouse movement is specified, we send it as a single command
+			//TODO
+			return []byte{0x03, 0x0A, byte(HIDCommand.MouseRelX), byte(HIDCommand.MouseRelY)}, nil
+		}
+		return nil, fmt.Errorf("no mouse movement specified")
+	case EventTypeMousePress:
+		if HIDCommand.MouseButton < 1 || HIDCommand.MouseButton > 3 {
+			return nil, fmt.Errorf("invalid mouse button: %d", HIDCommand.MouseButton)
+		}
+		// Mouse button click event
+		return []byte{0x02, 0x05, byte(HIDCommand.MouseButton)}, nil
+	case EventTypeMouseRelease:
+		if HIDCommand.MouseButton < 1 || HIDCommand.MouseButton > 3 {
+			return nil, fmt.Errorf("invalid mouse button: %d", HIDCommand.MouseButton)
+		}
+		// Mouse button release event
+		return []byte{0x02, 0x06, byte(HIDCommand.MouseButton)}, nil
+	case EventTypeMouseScroll:
+		if (time.Now().UnixMilli() - c.lastCursorEventTime) < MinCusrorEventInterval {
+			// If the last cursor event was too recent, we skip sending this one
+			return []byte{}, nil
+		}
+		c.lastCursorEventTime = time.Now().UnixMilli()
+
+		if HIDCommand.MouseScroll < -127 || HIDCommand.MouseScroll > 127 {
+			return nil, fmt.Errorf("invalid mouse scroll value: %d", HIDCommand.MouseScroll)
+		}
+		// Mouse scroll event
+		if HIDCommand.MouseScroll < 0 {
+			return []byte{0x02, 0x07, byte(HIDCommand.MouseScroll * -1)}, nil
+		} else {
+			return []byte{0x02, 0x08, byte(HIDCommand.MouseScroll)}, nil
+		}
+
+	default:
+		return nil, fmt.Errorf("unsupported HID command event type: %d", HIDCommand.Event)
+	}
+}
+
 func (c *Controller) HIDWebSocketHandler(w http.ResponseWriter, r *http.Request) {
 	conn, err := upgrader.Upgrade(w, r, nil)
 	if err != nil {
@@ -50,24 +189,22 @@ func (c *Controller) HIDWebSocketHandler(w http.ResponseWriter, r *http.Request)
 			continue
 		}
 
-		//Send the command to the HID controller
-		bytes, err := ConvHIDCommandToBytes(hidCmd)
+		bytes, err := c.GenerateUARTCmd(&hidCmd)
 		if err != nil {
 			errmsg := map[string]string{"error": err.Error()}
 			if err := conn.WriteJSON(errmsg); err != nil {
 				log.Println("Error writing message:", err)
+				continue
 			}
+			log.Println("Error generating UART command:", err)
 			continue
 		}
 
-		if bytes[0] == OPR_TYPE_MOUSE_SCROLL {
-			currentTime := time.Now().UnixMilli()
-			//Sending scroll too fast will cause the HID controller to glitch
-			if currentTime-c.lastScrollTime < 20 {
-				log.Println("Ignoring scroll event due to rate limiting")
-				continue
+		if len(bytes) == 0 {
+			if err := conn.WriteMessage(websocket.TextMessage, []byte("ok")); err != nil {
+				log.Println("Error writing message:", err)
 			}
-			c.lastScrollTime = currentTime
+			continue
 		}
 
 		fmt.Println("Sending bytes:", bytes)

+ 0 - 263
remdeskd/mod/remdeshid/hidcomm.go

@@ -1,263 +0,0 @@
-package remdeshid
-
-/*
-	hidcomm.go
-
-	This file contains functions to convert HID commands to bytes
-	that can be sent over the USBKVM device
-
-*/
-import (
-	"errors"
-	"fmt"
-)
-
-// Append the keyboard event subtypes to the data
-func appendKeyboardEventSubtypes(data []byte, cmd HIDCommand) ([]byte, error) {
-	/* Keyboard Subtypes */
-	if len(cmd.Data) == 1 && cmd.Data[0] >= 32 && cmd.Data[0] <= 127 {
-		//Valid ASCII character
-		if cmd.EventSubType == FRONTEND_SUBTYPE_KEYBOARD_KEY_DOWN {
-			data = append(data, SUBTYPE_KEYBOARD_ASCII_PRESS)
-		} else if cmd.EventSubType == FRONTEND_SUBTYPE_KEYBOARD_KEY_UP {
-			data = append(data, SUBTYPE_KEYBOARD_ASCII_RELEASE)
-		} else {
-			//Key Click
-			data = append(data, SUBTYPE_KEYBOARD_ASCII_WRITE)
-		}
-		data = append(data, cmd.Data[0])
-		return data, nil
-	} else if isFuncKey(cmd.Data) {
-		//Function Key
-		if cmd.EventSubType == FRONTEND_SUBTYPE_KEYBOARD_KEY_DOWN {
-			data = append(data, SUBTYPE_KEYBOARD_FUNCTKEY_PRESS)
-		} else {
-			data = append(data, SUBTYPE_KEYBOARD_FUNCTKEY_RELEASE)
-		}
-		data = append(data, funcKeyToByte(cmd.Data))
-		if data[0] == 0xFF {
-			return nil, fmt.Errorf("invalid function key: %v", cmd.Data)
-		}
-		return data, nil
-	} else if isModifierKey(cmd.Data) {
-		//Modifier Key
-		if cmd.EventSubType == FRONTEND_SUBTYPE_KEYBOARD_KEY_DOWN {
-			data = append(data, SUBTYPE_KEYBOARD_MODIFIER_PRESS)
-		} else {
-			data = append(data, SUBTYPE_KEYBOARD_MODIFIER_RELEASE)
-		}
-		data = append(data, modifierKeyToByte(cmd.Data))
-		if data[0] == 0xFF {
-			return nil, fmt.Errorf("invalid modifier key: %v", cmd.Data)
-		}
-		return data, nil
-	} else if isOtherKeys(cmd.Data) {
-		//Other Keys
-		if cmd.EventSubType == FRONTEND_SUBTYPE_KEYBOARD_KEY_DOWN {
-			data = append(data, SUBTYPE_KEYBOARD_OTHERKEY_PRESS)
-		} else if cmd.EventSubType == FRONTEND_SUBTYPE_KEYBOARD_KEY_UP {
-			data = append(data, SUBTYPE_KEYBOARD_OTHERKEY_RELEASE)
-		} else {
-			return nil, fmt.Errorf("invalid HID command subtype: %v", cmd.Data)
-		}
-		data = append(data, nonAsciiKeysToBytes(cmd.Data)...)
-		return data, nil
-	} else if isNumpadKey(cmd.Data) {
-		//Numpad Keys
-		if cmd.EventSubType == FRONTEND_SUBTYPE_KEYBOARD_KEY_DOWN {
-			data = append(data, SUBTYPE_KEYBOARD_NUMPAD_PRESS)
-		} else if cmd.EventSubType == FRONTEND_SUBTYPE_KEYBOARD_KEY_UP {
-			data = append(data, SUBTYPE_KEYBOARD_NUMPAD_RELEASE)
-		} else {
-			return nil, fmt.Errorf("invalid HID command subtype: %v", cmd.Data)
-		}
-		data = append(data, numpadKeyToByte(string(cmd.Data)))
-		return data, nil
-	} else if cmd.Data == "NumLock" {
-		if cmd.EventSubType == FRONTEND_SUBTYPE_KEYBOARD_KEY_DOWN {
-			data = append(data, SUBTYPE_KEYBOARD_SPECIAL_NUMLOCK)
-			data = append(data, 0x00)
-			return data, nil
-		}
-		return nil, fmt.Errorf("numLock do not support key up")
-	} else if cmd.Data == "Pause" {
-		if cmd.EventSubType == FRONTEND_SUBTYPE_KEYBOARD_KEY_DOWN {
-			data = append(data, SUBTYPE_KEYBOARD_SPECIAL_PAUSE)
-			data = append(data, 0x00)
-			return data, nil
-		}
-
-		return nil, fmt.Errorf("pause do not support key up")
-	} else if cmd.Data == "PrintScreen" {
-		if cmd.EventSubType == FRONTEND_SUBTYPE_KEYBOARD_KEY_UP {
-			data = append(data, SUBTYPE_KEYBOARD_SPECIAL_PRINT_SCREEN)
-			data = append(data, 0x00)
-			return data, nil
-		}
-
-		return nil, fmt.Errorf("printScreen do not support key down")
-	} else if cmd.Data == "ScrollLock" {
-		if cmd.EventSubType == FRONTEND_SUBTYPE_KEYBOARD_KEY_DOWN {
-			data = append(data, SUBTYPE_KEYBOARD_SPECIAL_SCROLL_LOCK)
-			data = append(data, 0x00)
-			return data, nil
-		}
-
-		return nil, fmt.Errorf("scrollLock do not support key up")
-	} else if cmd.Data == "ContextMenu" {
-		//Special Key: ContextMenu
-		//TODO: Implement ContextMenu
-		return nil, fmt.Errorf("ContextMenu not implemented")
-	} else if cmd.Data == "Ctrl+Alt+Del" {
-		//Special Key: Ctrl+Alt+Del
-		data = append(data, SUBTYPE_KEYBOARD_SPECIAL_CTRLALTDEL)
-		data = append(data, 0x00)
-		return data, nil
-	} else {
-		return nil, fmt.Errorf("invalid HID command subtype: %v", cmd.Data)
-	}
-}
-
-// Append the mouse click event subtypes to the data
-func appendMouseClickEventSubtypes(data []byte, cmd HIDCommand) ([]byte, error) {
-	/* Mouse Click Subtypes */
-	isPress := cmd.EventSubType == FRONTEND_MOUSE_PRESS
-	if isPress {
-		//Mouse Button Press
-		data = append(data, 0x02)
-	} else {
-		//Mouse Button Release
-		data = append(data, 0x03)
-	}
-
-	if cmd.Data == FRONTEND_MOUSE_BTN_LEFT {
-		data = append(data, PAYLOAD_MOUSE_BTN_LEFT)
-	} else if cmd.Data == FRONTEND_MOUSE_BTN_MIDDLE {
-		data = append(data, PAYLOAD_MOUSE_BTN_MID)
-	} else if cmd.Data == FRONTEND_MOUSE_BTN_RIGHT {
-		data = append(data, PAYLOAD_MOUSE_BTN_RIGHT)
-	} else {
-		return nil, fmt.Errorf("invalid HID command subtype: %v", cmd.Data)
-	}
-	return data, nil
-}
-
-// Append the mouse move event subtypes to the data
-func appendMouseMoveEventSubtypes(data []byte, cmd HIDCommand) ([]byte, error) {
-	//The mouse move command requires x_pos, y_pos, x_sign, y_sign
-	x_pos := cmd.PosX
-	y_pos := cmd.PosY
-	xIsNegative := x_pos < 0
-	yIsNegative := y_pos < 0
-	x_sign := 0
-	y_sign := 0
-	if xIsNegative {
-		x_pos = -x_pos
-		x_sign = 1
-	}
-
-	if yIsNegative {
-		y_pos = -y_pos
-		y_sign = 1
-	}
-
-	//The max value for x_pos and y_pos are 0xFE, make sure they are within the range
-	if x_pos > 0xFE {
-		x_pos = 0xFE
-	}
-
-	if y_pos > 0xFE {
-		y_pos = 0xFE
-	}
-
-	data = append(data, byte(x_pos), byte(y_pos), byte(x_sign), byte(y_sign))
-	return data, nil
-
-}
-
-// Append the mouse scroll event subtypes to the data
-func appendMouseScrollEventSubtypes(data []byte, cmd HIDCommand) ([]byte, error) {
-	//The mouse scroll command PosY contains the scroll value
-	//The scroll command require a direction byte and a scroll value byte
-	scrollValue := cmd.PosY
-	var sensitivity byte = 0x02
-	if scrollValue < 0 {
-		//Scroll up
-		data = append(data, 0x00)        //Up
-		data = append(data, sensitivity) //Sensitive
-	} else {
-		//Scroll down
-		data = append(data, 0x01)        //Down
-		data = append(data, sensitivity) //Sensitive
-	}
-
-	return data, nil
-}
-
-// Append the switch subtypes to the data
-func appendSwitchOperationsEventSubtypes(data []byte, cmd HIDCommand) ([]byte, error) {
-	if cmd.EventSubType == "hid" {
-		data = append(data, SUBTYPE_SWITCH_USB_HID)
-		if cmd.Data == "connect" {
-			//Set switch state to 0x00
-			data = append(data, 0x00)
-			return data, nil
-		} else if cmd.Data == "disconnect" {
-			//Set switch state to 0x01
-			data = append(data, 0x01)
-			return data, nil
-		} else if cmd.Data == "reset" {
-			data = append(data, 0x02)
-			return data, nil
-		}
-		return []byte{}, errors.New("unknown value: only support 'connect' and 'disconnect'")
-	} else if cmd.EventSubType == "mass-storage" {
-		data = append(data, SUBTYPE_SWITCH_USB_MASS)
-		if cmd.Data == "host" {
-			//Set switch state to 0x00
-			data = append(data, 0x00)
-			return data, nil
-		} else if cmd.Data == "slave" {
-			//Set switch state to 0x01
-			data = append(data, 0x01)
-			return data, nil
-		}
-		return []byte{}, errors.New("unknown value: only support 'host' and 'slave'")
-	}
-	//Unknown operatuins
-	return []byte{}, errors.New("unknown switch subtypes")
-}
-
-// Entry function for converting a HIDCommand to bytes that can be sent over the USBKVM device
-func ConvHIDCommandToBytes(cmd HIDCommand) ([]byte, error) {
-	// Convert the HID command to bytes
-	var data []byte
-	if cmd.EventType == FRONTEND_OPR_TYPE_KEYBOARD_WRITE {
-		/* Keyboard Write Event */
-		data = []byte{OPR_TYPE_KEYBOARD_WRITE}
-		return appendKeyboardEventSubtypes(data, cmd)
-	} else if cmd.EventType == FRONTEND_OPR_TYPE_MOUSE_WRITE {
-		/* Mouse Write Event */
-		data = []byte{OPR_TYPE_MOUSE_WRITE}
-		return appendMouseClickEventSubtypes(data, cmd)
-	} else if cmd.EventType == FRONTEND_OPR_TYPE_MOUSE_MOVE {
-		/* Mouse Move Event */
-		data = []byte{OPR_TYPE_MOUSE_MOVE}
-		return appendMouseMoveEventSubtypes(data, cmd)
-	} else if cmd.EventType == FRONTEND_OPR_TYPE_MOUSE_SCROLL {
-		/* Mouse Scroll Event */
-		data = []byte{OPR_TYPE_MOUSE_SCROLL}
-		return appendMouseScrollEventSubtypes(data, cmd)
-	} else if cmd.EventType == FRONTEND_OPR_TYPE_SWITCH {
-		data = []byte{OPR_TYPE_SWITCH_SET}
-		return appendSwitchOperationsEventSubtypes(data, cmd)
-	} else if cmd.EventType == FRONT_END_OPR_RESET {
-		/* Reset Event */
-		data = []byte{OPR_TYPE_DATA_RESET, //Reset the data queue
-			OPR_TYPE_KEYBOARD_WRITE, SUBTYPE_KEYBOARD_SPECIAL_RESET, 0x00, //Reset the keyboard press state
-			OPR_TYPE_MOUSE_WRITE, SUBTYPE_MOUSE_RESET, 0x00} //Reset the mouse press state
-		return data, nil
-	}
-
-	return nil, fmt.Errorf("invalid HID command type: %s", cmd.EventType)
-}

+ 0 - 319
remdeskd/mod/remdeshid/hidconv.go

@@ -1,319 +0,0 @@
-package remdeshid
-
-/*
-	hidconv.go
-
-	This file contains functions to convert HID commands to bytes
-	that can be sent over the USBKVM device
-*/
-
-// Operation Types
-const (
-	// Frontend Opr Types
-	FRONTEND_OPR_TYPE_KEYBOARD_WRITE = "kw"
-	FRONTEND_OPR_TYPE_MOUSE_WRITE    = "mw"
-	FRONTEND_OPR_TYPE_MOUSE_MOVE     = "mm"
-	FRONTEND_OPR_TYPE_MOUSE_SCROLL   = "ms"
-	FRONTEND_OPR_TYPE_SWITCH         = "sw"
-
-	// USBKVM Operation Types
-	OPR_TYPE_RESERVED       = 0x00
-	OPR_TYPE_KEYBOARD_WRITE = 0x01
-	OPR_TYPE_MOUSE_WRITE    = 0x02
-	OPR_TYPE_MOUSE_MOVE     = 0x03
-	OPR_TYPE_MOUSE_SCROLL   = 0x04
-	OPR_TYPE_SWITCH_SET     = 0x05
-	OPR_TYPE_DATA_RESET     = 0xFF
-)
-
-// Operation Sub-types
-const (
-	SUBTYPE_RESERVED = 0x00
-)
-
-// Keyboard Subtypes
-const (
-	// Frontend Keyboard Opr Types
-	FRONTEND_SUBTYPE_KEYBOARD_KEY_DOWN  = "kd"
-	FRONTEND_SUBTYPE_KEYBOARD_KEY_UP    = "ku"
-	FRONTEND_SUBTYPE_KEYBOARD_KEY_CLICK = "kc"
-
-	// USBKVM Keyboard Subtypes
-	SUBTYPE_KEYBOARD_ASCII_WRITE          = 0x01
-	SUBTYPE_KEYBOARD_ASCII_PRESS          = 0x02
-	SUBTYPE_KEYBOARD_ASCII_RELEASE        = 0x03
-	SUBTYPE_KEYBOARD_MODIFIER_PRESS       = 0x04
-	SUBTYPE_KEYBOARD_MODIFIER_RELEASE     = 0x05
-	SUBTYPE_KEYBOARD_FUNCTKEY_PRESS       = 0x06
-	SUBTYPE_KEYBOARD_FUNCTKEY_RELEASE     = 0x07
-	SUBTYPE_KEYBOARD_OTHERKEY_PRESS       = 0x08
-	SUBTYPE_KEYBOARD_OTHERKEY_RELEASE     = 0x09
-	SUBTYPE_KEYBOARD_NUMPAD_PRESS         = 0x0A
-	SUBTYPE_KEYBOARD_NUMPAD_RELEASE       = 0x0B
-	SUBTYPE_KEYBOARD_SPECIAL_PAUSE        = 0xF9
-	SUBTYPE_KEYBOARD_SPECIAL_PRINT_SCREEN = 0xFA
-	SUBTYPE_KEYBOARD_SPECIAL_SCROLL_LOCK  = 0xFB
-	SUBTYPE_KEYBOARD_SPECIAL_NUMLOCK      = 0xFC
-	SUBTYPE_KEYBOARD_SPECIAL_CTRLALTDEL   = 0xFD
-	SUBTYPE_KEYBOARD_SPECIAL_RESET        = 0xFE
-	SUBTYPE_KEYBOARD_SPECIAL_RESERVED     = 0xFF
-
-	// Numpad Buttons IDs
-	PAYLOAD_KEYBOARD_NUMPAD_0       = 0x00
-	PAYLOAD_KEYBOARD_NUMPAD_1       = 0x01
-	PAYLOAD_KEYBOARD_NUMPAD_2       = 0x02
-	PAYLOAD_KEYBOARD_NUMPAD_3       = 0x03
-	PAYLOAD_KEYBOARD_NUMPAD_4       = 0x04
-	PAYLOAD_KEYBOARD_NUMPAD_5       = 0x05
-	PAYLOAD_KEYBOARD_NUMPAD_6       = 0x06
-	PAYLOAD_KEYBOARD_NUMPAD_7       = 0x07
-	PAYLOAD_KEYBOARD_NUMPAD_8       = 0x08
-	PAYLOAD_KEYBOARD_NUMPAD_9       = 0x09
-	PAYLOAD_KEYBOARD_NUMPAD_DOT     = 0x0A
-	PAYLOAD_KEYBOARD_NUMPAD_TIMES   = 0x0B
-	PAYLOAD_KEYBOARD_NUMPAD_DIV     = 0x0C
-	PAYLOAD_KEYBOARD_NUMPAD_PLUS    = 0x0D
-	PAYLOAD_KEYBOARD_NUMPAD_MINUS   = 0x0E
-	PAYLOAD_KEYBOARD_NUMPAD_ENTER   = 0x0F
-	PAYLOAD_KEYBOARD_NUMPAD_NUMLOCK = 0x10
-
-	// Modifier Keys IDs
-	PAYLOAD_KEY_LEFT_CTRL   = 0x00
-	PAYLOAD_KEY_LEFT_SHIFT  = 0x01
-	PAYLOAD_KEY_LEFT_ALT    = 0x02
-	PAYLOAD_KEY_LEFT_GUI    = 0x03
-	PAYLOAD_KEY_RIGHT_CTRL  = 0x04
-	PAYLOAD_KEY_RIGHT_SHIFT = 0x05
-	PAYLOAD_KEY_RIGHT_ALT   = 0x06
-	PAYLOAD_KEY_RIGHT_GUI   = 0x07
-)
-
-const (
-	//Frontend Mouse Opr Types
-	FRONTEND_MOUSE_CLICK   = "mc"
-	FRONTEND_MOUSE_PRESS   = "md"
-	FRONTEND_MOUSE_RELEASE = "mu"
-
-	FRONTEND_MOUSE_BTN_LEFT   = "0"
-	FRONTEND_MOUSE_BTN_MIDDLE = "1"
-	FRONTEND_MOUSE_BTN_RIGHT  = "2"
-
-	// Mouse Subtypes
-	SUBTYPE_MOUSE_CLICK   = 0x01 // Mouse button click
-	SUBTYPE_MOUSE_PRESS   = 0x02 // Mouse button press
-	SUBTYPE_MOUSE_RELEASE = 0x03 // Mouse button release
-	SUBTYPE_MOUSE_SETPOS  = 0x04 // Mouse presets position
-	SUBTYPE_MOUSE_RESET   = 0x05 // Reset all mouse button states
-
-	// Mouse Buttons IDs
-	PAYLOAD_MOUSE_BTN_LEFT  = 0x01
-	PAYLOAD_MOUSE_BTN_RIGHT = 0x02
-	PAYLOAD_MOUSE_BTN_MID   = 0x03
-)
-
-// Switch Subtypes
-const (
-	SUBTYPE_SWITCH_USB_HID  = 0x01
-	SUBTYPE_SWITCH_USB_MASS = 0x02
-)
-
-// Control Code
-const (
-	FRONT_END_OPR_RESET = "reset" // Reset all the mouse and keyboard states
-)
-
-// Response Codes
-const (
-	RESP_OK                = 0x00
-	RESP_UNKNOWN_OPR       = 0x01
-	RESP_INVALID_OPR_TYPE  = 0x02
-	RESP_INVALID_KEY_VALUE = 0x03
-	RESP_NOT_IMPLEMENTED   = 0x04
-)
-
-//isModifierKey checks if a key is a modifier key
-func isModifierKey(key string) bool {
-	switch key {
-	case "LEFT_Shift", "RIGHT_Shift", "LEFT_Control", "RIGHT_Control", "LEFT_Alt", "RIGHT_Alt", "Meta", "ContextMenu":
-		return true
-	default:
-		return false
-	}
-}
-
-//Convert modifier key string to byte
-func modifierKeyToByte(key string) byte {
-	switch key {
-	case "LEFT_Shift":
-		return PAYLOAD_KEY_LEFT_SHIFT
-	case "RIGHT_Shift":
-		return PAYLOAD_KEY_RIGHT_SHIFT
-	case "LEFT_Control":
-		return PAYLOAD_KEY_LEFT_CTRL
-	case "RIGHT_Control":
-		return PAYLOAD_KEY_RIGHT_CTRL
-	case "LEFT_Alt":
-		return PAYLOAD_KEY_LEFT_ALT
-	case "RIGHT_Alt":
-		return PAYLOAD_KEY_RIGHT_ALT
-	case "Meta":
-		return PAYLOAD_KEY_LEFT_GUI
-	case "ContextMenu":
-		return PAYLOAD_KEY_RIGHT_GUI
-	default:
-		return 0xFF
-	}
-}
-
-//Is a key a function key
-func isFuncKey(key string) bool {
-	switch key {
-	case "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12",
-		"F13", "F14", "F15", "F16", "F17", "F18", "F19", "F20", "F21", "F22", "F23", "F24":
-		return true
-	default:
-		return false
-	}
-}
-
-//Convert function key string to byte
-func funcKeyToByte(key string) byte {
-	switch key {
-	case "F1":
-		return 0xC2
-	case "F2":
-		return 0xC3
-	case "F3":
-		return 0xC4
-	case "F4":
-		return 0xC5
-	case "F5":
-		return 0xC6
-	case "F6":
-		return 0xC7
-	case "F7":
-		return 0xC8
-	case "F8":
-		return 0xC9
-	case "F9":
-		return 0xCA
-	case "F10":
-		return 0xCB
-	case "F11":
-		return 0xCC
-	case "F12":
-		return 0xCD
-	case "F13":
-		return 0xF0
-	case "F14":
-		return 0xF1
-	case "F15":
-		return 0xF2
-	case "F16":
-		return 0xF3
-	case "F17":
-		return 0xF4
-	case "F18":
-		return 0xF5
-	case "F19":
-		return 0xF6
-	case "F20":
-		return 0xF7
-	case "F21":
-		return 0xF8
-	case "F22":
-		return 0xF9
-	case "F23":
-		return 0xFA
-	case "F24":
-		return 0xFB
-	default:
-		return 0xFF
-	}
-}
-
-/* Check for other keys */
-func isOtherKeys(key string) bool {
-	return nonAsciiKeysToBytes(key)[0] != 0xFF
-}
-
-func nonAsciiKeysToBytes(key string) []byte {
-	switch key {
-	case "ArrowUp":
-		return []byte{0xDA}
-	case "ArrowDown":
-		return []byte{0xD9}
-	case "ArrowLeft":
-		return []byte{0xD8}
-	case "ArrowRight":
-		return []byte{0xD7}
-	case "Backspace":
-		return []byte{0xB2}
-	case "Tab":
-		return []byte{0xB3}
-	case "Enter":
-		return []byte{0xB0}
-	case "Escape":
-		return []byte{0xB1}
-	case "Insert":
-		return []byte{0xD1}
-	case "Delete":
-		return []byte{0xD4}
-	case "PageUp":
-		return []byte{0xD3}
-	case "PageDown":
-		return []byte{0xD6}
-	case "Home":
-		return []byte{0xD2}
-	case "End":
-		return []byte{0xD5}
-	case "CapsLock":
-		return []byte{0xC1}
-	default:
-		return []byte{0xFF}
-	}
-}
-
-/* Numpad keys */
-func isNumpadKey(key string) bool {
-	return len(key) > 7 && key[:7] == "NUMPAD_"
-}
-
-func numpadKeyToByte(key string) byte {
-	switch key {
-	case "NUMPAD_0":
-		return PAYLOAD_KEYBOARD_NUMPAD_0
-	case "NUMPAD_1":
-		return PAYLOAD_KEYBOARD_NUMPAD_1
-	case "NUMPAD_2":
-		return PAYLOAD_KEYBOARD_NUMPAD_2
-	case "NUMPAD_3":
-		return PAYLOAD_KEYBOARD_NUMPAD_3
-	case "NUMPAD_4":
-		return PAYLOAD_KEYBOARD_NUMPAD_4
-	case "NUMPAD_5":
-		return PAYLOAD_KEYBOARD_NUMPAD_5
-	case "NUMPAD_6":
-		return PAYLOAD_KEYBOARD_NUMPAD_6
-	case "NUMPAD_7":
-		return PAYLOAD_KEYBOARD_NUMPAD_7
-	case "NUMPAD_8":
-		return PAYLOAD_KEYBOARD_NUMPAD_8
-	case "NUMPAD_9":
-		return PAYLOAD_KEYBOARD_NUMPAD_9
-	case "NUMPAD_.":
-		return PAYLOAD_KEYBOARD_NUMPAD_DOT
-	case "NUMPAD_*":
-		return PAYLOAD_KEYBOARD_NUMPAD_TIMES
-	case "NUMPAD_/":
-		return PAYLOAD_KEYBOARD_NUMPAD_DIV
-	case "NUMPAD_+":
-		return PAYLOAD_KEYBOARD_NUMPAD_PLUS
-	case "NUMPAD_-":
-		return PAYLOAD_KEYBOARD_NUMPAD_MINUS
-	case "NUMPAD_Enter":
-		return PAYLOAD_KEYBOARD_NUMPAD_ENTER
-	default:
-		return 0xFF
-	}
-}

+ 7 - 18
remdeskd/mod/remdeshid/remdeshid.go

@@ -20,11 +20,11 @@ type Config struct {
 
 // Controller is a struct that represents a HID controller
 type Controller struct {
-	Config         *Config
-	serialPort     *serial.Port
-	serialRunning  bool
-	writeQueue     chan []byte
-	lastScrollTime int64
+	Config              *Config
+	serialPort          *serial.Port
+	serialRunning       bool
+	writeQueue          chan []byte
+	lastCursorEventTime int64
 }
 
 func NewHIDController(config *Config) *Controller {
@@ -52,7 +52,7 @@ func (c *Controller) Connect() error {
 	c.serialPort = port
 	//Start reading from the serial port
 	go func() {
-		buf := make([]byte, 128)
+		buf := make([]byte, 1024)
 		for {
 			n, err := port.Read(buf)
 			if err != nil {
@@ -96,22 +96,11 @@ func (c *Controller) Connect() error {
 	}()
 
 	//Send over an opr queue reset signal
-	err = c.Send([]byte{OPR_TYPE_DATA_RESET})
+	err = c.Send([]byte{0xFF})
 	if err != nil {
 		return err
 	}
 
-	//Reset keyboard press state
-	err = c.Send([]byte{OPR_TYPE_KEYBOARD_WRITE, SUBTYPE_KEYBOARD_SPECIAL_RESET, 0x00})
-	if err != nil {
-		return err
-	}
-
-	//Reset mouse press state
-	err = c.Send([]byte{OPR_TYPE_MOUSE_WRITE, SUBTYPE_MOUSE_RESET, 0x00})
-	if err != nil {
-		return err
-	}
 	return nil
 }
 

+ 150 - 132
remdeskd/www/index.html

@@ -18,112 +18,142 @@
         body{
             margin: 0;
         }
+
         #remoteCapture{
             width: 100%;
-            pointer-events: none;
-            user-select: none;
         }
 
-        #remoteCaptureWrapper{
-            box-shadow: none !important;
-            border: 0px solid transparent !important;
-            background: none !important;
-        }
     </style>
 </head>
 <body>
-    <button id="remoteCaptureWrapper" onclick="startCapture();">
-        <img id="remoteCapture" src="/stream"></img>
-    </button>
-    <p>Click start to start connection to backend and start Capture to start KVM-ing</p>
-    <!-- <button id="startButton">Start</button>
-    <button id="stopButton">Stop</button> -->
-    <button id="capture">Capture</button>
-    <button id="screenshot">Win + Shift + S</button>
-    <button id="reconnect">Reset HID</button>
+
+    <img id="remoteCapture" src="/stream" oncontextmenu="return false;"></img>
+   
     <script>
         let socket;
         let protocol = window.location.protocol === 'https:' ? 'wss' : 'ws';
         let port = window.location.port ? window.location.port : (protocol === 'wss' ? 443 : 80);
         let socketURL = `${protocol}://${window.location.hostname}:${port}/hid`;
-        
-        function isPointerLocked() {
-            return document.pointerLockElement === document.body;
-        }
+        let mouseMoveAbsolte = true; // Set to true for absolute mouse coordinates, false for relativeZ
+        let mouseScrollSensitivity = 0.01; // Adjust this value to change scroll sensitivity
+        let mouseIsOutside = false;
 
-        function startCapture(){
-            if (!socket) {
-                alert("control websocket is not opened");
-                return;
+        /* Mouse events */
+        function handleMouseMove(event) {
+            const hidCommand = {
+                event: 2,
+                mouse_x: event.clientX,
+                mouse_y: event.clientY
+            };
+
+
+            const rect = event.target.getBoundingClientRect();
+            const relativeX = event.clientX - rect.left;
+            const relativeY = event.clientY - rect.top;
+            
+            if (relativeX < 0 || relativeY < 0 || relativeX > rect.width || relativeY > rect.height) {
+                mouseIsOutside = true;
+                return; // Mouse is outside the client rect
+            }
+            mouseIsOutside = false;
+            const percentageX = (relativeX / rect.width) * 4096;
+            const percentageY = (relativeY / rect.height) * 4096;
+
+            hidCommand.mouse_x = Math.round(percentageX);
+            hidCommand.mouse_y = Math.round(percentageY);
+
+            console.log(`Mouse move: (${event.clientX}, ${event.clientY})`);
+            console.log(`Mouse move relative: (${relativeX}, ${relativeY})`);
+            console.log(`Mouse move percentage: (${hidCommand.mouse_x}, ${hidCommand.mouse_y})`);
+
+            if (socket && socket.readyState === WebSocket.OPEN) {
+                socket.send(JSON.stringify(hidCommand));
+            } else {
+                console.error("WebSocket is not open.");
             }
-            console.log("Start capture called");
-
-            // Remove old listeners if they exist
-            document.removeEventListener('mousemove', handleMouseMove);
-            document.removeEventListener('mousedown', handleMouseDown);
-            document.removeEventListener('mouseup', handleMouseUp);
-            document.removeEventListener('wheel', handleScroll);
-
-            // Add new listeners
-            document.body.requestPointerLock();
-            document.addEventListener('mousemove', handleMouseMove);
-            document.addEventListener('mousedown', handleMouseDown);
-            document.addEventListener('mouseup', handleMouseUp);
-            document.addEventListener('wheel', handleScroll);
-
-            // Reset USBKVM state to avoid stuck keys
-            socket.send(JSON.stringify({ t: 'reset'}));
         }
 
-        document.getElementById('capture').addEventListener('click', function(event) {
+        function handleMousePress(event) {
             event.preventDefault();
-            event.stopPropagation();
-            startCapture();
-        });
+            event.stopImmediatePropagation();
+            if (mouseIsOutside) {
+                console.warn("Mouse is outside the capture area, ignoring mouse press.");
+                return;
+            }
+            const buttonMap = {
+                0: 1, 
+                1: 3,
+                2: 2
+            }; //Map javascript mouse buttons to HID buttons
 
-        $("#remoteCapture").on("click", function(){
-            startCapture();
-        });
+            const hidCommand = {
+                event: 3,
+                mouse_button: buttonMap[event.button] || 0
+            };
 
+            console.log(`Mouse down: ${hidCommand.mouse_button}`);
 
-        /* Mouse */
-        function handleMouseDown(event) {
-            console.log(`Mouse button pressed: Button=${event.button}`);
-            if (socket && isPointerLocked()) {
-                socket.send(JSON.stringify({ t: 'mw', s: 'md', d: event.button+"" }));
+            if (socket && socket.readyState === WebSocket.OPEN) {
+                socket.send(JSON.stringify(hidCommand));
+            } else {
+                console.error("WebSocket is not open.");
             }
         }
 
-        function handleMouseUp(event) {
-            console.log(`Mouse button released: Button=${event.button}`);
-            if (socket && isPointerLocked()) {
-                socket.send(JSON.stringify({ t: 'mw', s: 'mu', d: event.button+"" }));
+        function handleMouseRelease(event) {
+            event.preventDefault();
+            event.stopImmediatePropagation();
+            if (mouseIsOutside) {
+                console.warn("Mouse is outside the capture area, ignoring mouse press.");
+                return;
             }
-        }
+            const buttonMap = {
+                0: 1, 
+                1: 3,
+                2: 2
+            }; //Map javascript mouse buttons to HID buttons
+
+            const hidCommand = {
+                event: 4,
+                mouse_button: buttonMap[event.button] || 0
+            };
+
+            console.log(`Mouse release: ${hidCommand.mouse_button}`);
 
-        function handleScroll(event) {
-            console.log(`Mouse scrolled: DeltaX=${event.deltaX}, DeltaY=${event.deltaY}`);
-            if (socket && isPointerLocked()) {
-                socket.send(JSON.stringify({ t: 'ms', y: event.deltaY }));
+            if (socket && socket.readyState === WebSocket.OPEN) {
+                socket.send(JSON.stringify(hidCommand));
+            } else {
+                console.error("WebSocket is not open.");
             }
         }
 
-        document.addEventListener('pointerlockchange', function() {
-            if (document.pointerLockElement === document.body) {
-                console.log('Pointer locked');
-            } else {
-                console.log('Pointer unlocked');
-                document.removeEventListener('mousemove', handleMouseMove);
+        function handleMouseScroll(event) {
+            const hidCommand = {
+                event: 5,
+                mouse_scroll: parseInt(event.deltaY * mouseScrollSensitivity)
+            };
+            if (mouseIsOutside) {
+                console.warn("Mouse is outside the capture area, ignoring mouse press.");
+                return;
             }
-        });
 
-        function handleMouseMove(event) {
-            console.log(`Mouse moved: X=${event.movementX}, Y=${event.movementY}`);
-            if (socket && isPointerLocked()) {
-                socket.send(JSON.stringify({ t: 'mm', x: event.movementX, y: event.movementY }));
+
+            console.log(`Mouse scroll: mouse_scroll=${event.deltaY} (scaled: ${hidCommand.mouse_scroll})`);
+
+            if (socket && socket.readyState === WebSocket.OPEN) {
+                socket.send(JSON.stringify(hidCommand));
+            } else {
+                console.error("WebSocket is not open.");
             }
         }
-        
+
+        // Attach mouse event listeners
+        document.addEventListener('mousemove', handleMouseMove);
+        document.addEventListener('mousedown', handleMousePress);
+        document.addEventListener('mouseup', handleMouseRelease);
+        document.addEventListener('wheel', handleMouseScroll);
+
+
         /* Keyboard */
         function isNumpadEvent(event) {
             return event.location === 3;
@@ -133,20 +163,28 @@
             event.preventDefault();
             event.stopImmediatePropagation();
             const key = event.key;
-            if (socket && isPointerLocked()){
-                if (key == "Shift" || key == "Control" || key == "Alt"){
-                    if (event.location == 1){
-                        socket.send(JSON.stringify({ t: 'kw', s: 'kd', d: "LEFT_" + key }));
-                    } else {
-                        socket.send(JSON.stringify({ t: 'kw', s: 'kd', d:  "RIGHT_" + key }));
-                    }
-                }else if (isNumpadEvent(event)){
-                    socket.send(JSON.stringify({ t: 'kw', s: 'kd', d: "NUMPAD_" + key }));
-                }else if (key == "PrintScreen"){
-                    //Do nothing, press is hardware offloaded
-                }else{
-                    socket.send(JSON.stringify({ t: 'kw', s: 'kd', d: key }));
-                }
+            let hidCommand = {
+                event: 0,
+                keycode: event.keyCode
+            };
+
+            console.log(`Key down: ${key} (code: ${event.keyCode})`);
+
+            // Check if the key is a modkey on the right side of the keyboard
+            const rightModKeys = ['Control', 'Alt', 'Shift', 'Meta'];
+            if (rightModKeys.includes(key) && event.location === 2) {
+                hidCommand.is_right_modifier_key = true;
+            }else if (key === 'Enter' && isNumpadEvent(event)) {
+                //Special case for Numpad Enter
+                hidCommand.is_right_modifier_key = true;
+            }else{
+                hidCommand.is_right_modifier_key = false;
+            }
+
+            if (socket && socket.readyState === WebSocket.OPEN) {
+                socket.send(JSON.stringify(hidCommand));
+            } else {
+                console.error("WebSocket is not open.");
             }
         }
 
@@ -154,20 +192,30 @@
             event.preventDefault();
             event.stopImmediatePropagation();
             const key = event.key;
-            if (socket && isPointerLocked()) {
-                if (key == "Shift" || key == "Control" || key == "Alt") {
-                    if (event.location == 1) {
-                        socket.send(JSON.stringify({ t: 'kw', s: 'ku', d: "LEFT_" + key }));
-                    } else {
-                        socket.send(JSON.stringify({ t: 'kw', s: 'ku', d: "RIGHT_" + key }));
-                    }
-                }else if (isNumpadEvent(event)){
-                    socket.send(JSON.stringify({ t: 'kw', s: 'ku', d: "NUMPAD_" + key }));
-                }else if (key == "NumLock" || key == "Pause"){
-                   //Do nothing, release is hardware offloaded
-                } else {
-                    socket.send(JSON.stringify({ t: 'kw', s: 'ku', d: key }));
-                }
+            
+            let hidCommand = {
+                event: 1,
+                keycode: event.keyCode
+            };
+
+            console.log(`Key up: ${key} (code: ${event.keyCode})`);
+
+            // Check if the key is a modkey on the right side of the keyboard
+            const rightModKeys = ['Control', 'Alt', 'Shift', 'Meta'];
+            if (rightModKeys.includes(key) && event.location === 2) {
+                hidCommand.is_right_modifier_key = true;
+            } else if (key === 'Enter' && isNumpadEvent(event)) {
+                //Special case for Numpad Enter
+                hidCommand.is_right_modifier_key = true;
+            }else{
+                hidCommand.is_right_modifier_key = false;
+            }
+
+
+            if (socket && socket.readyState === WebSocket.OPEN) {
+                socket.send(JSON.stringify(hidCommand));
+            } else {
+                console.error("WebSocket is not open.");
             }
         }
 
@@ -205,36 +253,6 @@
             document.removeEventListener('keyup', handleKeyUp);
         }
 
-        document.getElementById('screenshot').addEventListener('click', function() {
-            if (socket) {
-                // Send keydown for Shift
-                socket.send(JSON.stringify({ t: 'kw', s: 'kd', d: 'LEFT_Shift' }));
-                // Send keydown for Windows key
-                socket.send(JSON.stringify({ t: 'kw', s: 'kd', d: 'Meta' }));
-                // Send keydown for S
-                socket.send(JSON.stringify({ t: 'kw', s: 'kd', d: 's' }));
-                
-                setTimeout(function() {
-                    // Send keyup for S
-                    socket.send(JSON.stringify({ t: 'kw', s: 'ku', d: 's' }));
-                    // Send keyup for Windows key
-                    socket.send(JSON.stringify({ t: 'kw', s: 'ku', d: 'Meta' }));
-                    // Send keyup for Shift
-                    socket.send(JSON.stringify({ t: 'kw', s: 'ku', d: 'LEFT_Shift' }));
-                }, 1000);
-            }
-        });
-
-        /* Reconnect USB HID to slave device */
-        $("#reconnect").on("click", function(){
-            if (socket) {   
-                socket.send(JSON.stringify({ t: 'sw', s: 'hid', d: "reset"}));
-            }else{
-                alert("Websocket conn not established");
-            }
-        });
-
-        
 
         $(document).ready(function(){
             startWebSocket();