typedef.go 2.1 KB

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