Documentation
¶
Index ¶
- Constants
- func AccelMS2ToRaw(ms2 float64) int16
- func AccelRawToMS2(raw int16) float64
- func DefaultAccelRaw() (x, y, z int16)
- func GyroDpsToRaw(dps float64) int16
- func GyroRawToDps(raw int16) float64
- type DualShock4
- func (d *DualShock4) GetDescriptor() *usb.Descriptor
- func (d *DualShock4) HandleControl(bmRequestType, bRequest uint8, wValue, _, wLength uint16, data []byte) ([]byte, bool)
- func (d *DualShock4) HandleTransfer(ep uint32, dir uint32, out []byte) []byte
- func (d *DualShock4) SetOutputCallback(f func(OutputState))
- func (d *DualShock4) UpdateInputState(state *InputState)
- type InputState
- type OutputState
Constants ¶
const ( DefaultVID = 0x054C DefaultPID = 0x05C4 )
const ( EndpointIn = 0x84 EndpointOut = 0x03 )
const ( ReportIDInput = 0x01 ReportIDOutput = 0x05 ReportIDFeature = 0x02 )
const ( InputReportSize = 64 OutputReportSize = 32 )
const ( ButtonSquare uint16 = 0x0010 ButtonCross uint16 = 0x0020 ButtonCircle uint16 = 0x0040 ButtonTriangle uint16 = 0x0080 DPadMask uint8 = 0x0F )
const ( ButtonL1 uint16 = 0x0100 ButtonR1 uint16 = 0x0200 ButtonL2 uint16 = 0x0400 ButtonR2 uint16 = 0x0800 ButtonOptions uint16 = 0x2000 ButtonL3 uint16 = 0x4000 ButtonR3 uint16 = 0x8000 ButtonPS uint16 = 0x0001 ButtonTouchpadClick uint16 = 0x0002 )
const ( ButtonPSUSB uint8 = 0x01 ButtonTouchpadClickUSB uint8 = 0x02 CounterMask = 0xFC CounterShift = 2 )
const ( DPadUSBUp = 0x00 DPadUSBUpRight = 0x01 DPadUSBRight = 0x02 DPadUSBDownRight = 0x03 DPadUSBDown = 0x04 DPadUSBDownLeft = 0x05 DPadUSBLeft = 0x06 DPadUSBUpLeft = 0x07 DPadUSBNeutral = 0x08 )
const ( DPadUp = 0x01 DPadDown = 0x02 DPadLeft = 0x04 DPadRight = 0x08 )
const ( // GyroCountsPerDps is the fixed-point scale factor for °/s. // resolution is 0.0625 °/s and range is about +-2048 °/s. GyroCountsPerDps = 16.0 // AccelCountsPerMS2 is the fixed-point scale factor for m/s². // resolution is ~0.00195 m/s² and range is about +-64 m/s² (~+-6.5 g). AccelCountsPerMS2 = 512.0 StandardGravityMS2 = 9.81 )
The DS4 USB input report carries gyro/accel as signed int16 values. VIIPER's wire protocol keeps them as int16, but interprets them as fixed-point physical units to avoid float serialization across clients.
Gyro fields (GyroX/Y/Z): °/s scaled by GyroCountsPerDps. Accel fields (AccelX/Y/Z): m/s² scaled by AccelCountsPerMS2.
const ( DefaultAccelXRaw int16 = 0 DefaultAccelYRaw int16 = 0 // -StandardGravityMS2 * AccelCountsPerMS2 = (-9.81 * 512) = -5023 DefaultAccelZRaw int16 = -5023 )
Default accelerometer raw values for a controller lying flat on a table.
const ( TouchpadMinX uint16 = 0 TouchpadMaxX uint16 = 1920 TouchpadMinY uint16 = 0 TouchpadMaxY uint16 = 942 TouchInactiveMask uint8 = 0x80 )
const ( BatteryLevelMask = 0x0F BatteryChargingFlag = 0x10 BatteryFullyCharged = 0x0B BatteryDefault = 0x1B )
const ( OutOffsetReportID = 0 OutOffsetFlags = 1 OutOffsetRumbleSmall = 4 OutOffsetRumbleLarge = 5 OutOffsetLedRed = 6 OutOffsetLedGreen = 7 OutOffsetLedBlue = 8 OutOffsetFlashOn = 9 // Flash on time (units of 2.5ms) OutOffsetFlashOff = 10 // Flash off time (units of 2.5ms) )
const ( DefaultLedRed = 0x00 DefaultLedGreen = 0x00 DefaultLedBlue = 0x40 )
Variables ¶
This section is empty.
Functions ¶
func AccelMS2ToRaw ¶
AccelMS2ToRaw converts an acceleration value in meters/second^2 (m/s²) into the fixed-point raw int16 wire/report representation.
func AccelRawToMS2 ¶
AccelRawToMS2 converts a fixed-point raw accelerometer value into m/s².
func DefaultAccelRaw ¶
func DefaultAccelRaw() (x, y, z int16)
DefaultAccelRaw returns the default ("neutral") accelerometer vector for a controller lying flat on a table.
func GyroDpsToRaw ¶
GyroDpsToRaw converts a gyro angular velocity value in degrees/second (°/s) into the fixed-point raw int16 wire/report representation.
func GyroRawToDps ¶
GyroRawToDps converts a fixed-point raw gyro value into degrees/second (°/s).
Types ¶
type DualShock4 ¶
type DualShock4 struct {
// contains filtered or unexported fields
}
func New ¶
func New(o *device.CreateOptions) *DualShock4
func (*DualShock4) GetDescriptor ¶
func (d *DualShock4) GetDescriptor() *usb.Descriptor
func (*DualShock4) HandleControl ¶
func (*DualShock4) HandleTransfer ¶
func (d *DualShock4) HandleTransfer(ep uint32, dir uint32, out []byte) []byte
func (*DualShock4) SetOutputCallback ¶
func (d *DualShock4) SetOutputCallback(f func(OutputState))
func (*DualShock4) UpdateInputState ¶
func (d *DualShock4) UpdateInputState(state *InputState)
type InputState ¶
type InputState struct {
LX, LY int8
RX, RY int8
Buttons uint16
DPad uint8
L2, R2 uint8
Touch1X, Touch1Y uint16
Touch1Active bool
Touch2X, Touch2Y uint16
Touch2Active bool
GyroX, GyroY, GyroZ int16
AccelX, AccelY, AccelZ int16
}
viiper:wire dualshock4 c2s stickLX:i8 stickLY:i8 stickRX:i8 stickRY:i8 buttons:u16 dpad:u8 triggerL2:u8 triggerR2:u8 touch1X:u16 touch1Y:u16 touch1Active:bool touch2X:u16 touch2Y:u16 touch2Active:bool gyroX:i16 gyroY:i16 gyroZ:i16 accelX:i16 accelY:i16 accelZ:i16
func (*InputState) MarshalBinary ¶
func (s *InputState) MarshalBinary() ([]byte, error)
func (*InputState) UnmarshalBinary ¶
func (s *InputState) UnmarshalBinary(data []byte) error
type OutputState ¶
type OutputState struct {
RumbleSmall uint8 // (0-255)
RumbleLarge uint8 // (0-255)
LedRed uint8 // (0-255)
LedGreen uint8 // (0-255)
LedBlue uint8 // (0-255)
FlashOn uint8 // (units of 2.5ms)
FlashOff uint8 // (units of 2.5ms)
}
viiper:wire dualshock4 s2c rumbleSmall:u8 rumbleLarge:u8 ledRed:u8 ledGreen:u8 ledBlue:u8 flashOn:u8 flashOff:u8
func (*OutputState) MarshalBinary ¶
func (f *OutputState) MarshalBinary() ([]byte, error)
func (*OutputState) UnmarshalBinary ¶
func (f *OutputState) UnmarshalBinary(data []byte) error