typedef.go 2.3 KB

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