typedef.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package remdeshid
  2. import (
  3. "github.com/tarm/serial"
  4. )
  5. type EventType int
  6. const (
  7. EventTypeKeyPress EventType = iota
  8. EventTypeKeyRelease
  9. EventTypeMouseMove
  10. EventTypeMousePress
  11. EventTypeMouseRelease
  12. EventTypeMouseScroll
  13. EventTypeHIDCommand
  14. EventTypeHIDReset = 0xFF
  15. )
  16. const MinCusorEventInterval = 25 // Minimum interval between cursor events in milliseconds
  17. type Config struct {
  18. /* Serial port configs */
  19. PortName string
  20. BaudRate int
  21. ScrollSensitivity uint8 // Mouse scroll sensitivity, range 0x00 to 0x7E
  22. }
  23. type HIDState struct {
  24. /* Keyboard state */
  25. Modkey uint8 // Modifier key state
  26. KeyboardButtons [6]uint8 // Keyboard buttons state
  27. Leds uint8 // LED state
  28. /* Mouse state */
  29. MouseButtons uint8 // Mouse buttons state
  30. MouseX int16 // Mouse X movement
  31. MouseY int16 // Mouse Y movement
  32. }
  33. // Controller is a struct that represents a HID controller
  34. type Controller struct {
  35. Config *Config
  36. /* Internal state */
  37. serialPort *serial.Port
  38. hidState HIDState // Current state of the HID device
  39. serialRunning bool
  40. writeQueue chan []byte
  41. incomingDataQueue chan []byte // Queue for incoming data
  42. lastCursorEventTime int64
  43. }
  44. type HIDCommand struct {
  45. Event EventType `json:"event"`
  46. Keycode int `json:"keycode,omitempty"`
  47. IsRightModKey bool `json:"is_right_modifier_key,omitempty"` // true if the key is a right modifier key (Ctrl, Shift, Alt, GUI)
  48. MouseAbsX int `json:"mouse_x,omitempty"` // Absolute mouse position in X direction
  49. MouseAbsY int `json:"mouse_y,omitempty"` // Absolute mouse position in Y direction
  50. MouseRelX int `json:"mouse_rel_x,omitempty"` // Relative mouse movement in X direction
  51. MouseRelY int `json:"mouse_rel_y,omitempty"` // Relative mouse movement in Y direction
  52. MouseMoveButtonState int `json:"mouse_move_button_state,omitempty"` // Mouse button state during move,
  53. MouseButton int `json:"mouse_button,omitempty"` //0x01 for left click, 0x02 for right click, 0x03 for middle clicks
  54. MouseScroll int `json:"mouse_scroll,omitempty"` // Positive for scroll up, negative for scroll down, max 127
  55. }