Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
touchUtils.h File Reference

Go to the source code of this file.

Data Structures

struct  touchSpinState_t
 

Enumerations

enum  touchJoystick_t {
  TB_CENTER = 0x0100 , TB_RIGHT = 0x0200 , TB_UP = 0x0400 , TB_LEFT = 0x0800 ,
  TB_DOWN = 0x1000 , TB_UP_RIGHT = 0x0600 , TB_UP_LEFT = 0x0C00 , TB_DOWN_LEFT = 0x1800 ,
  TB_DOWN_RIGHT = 0x1200
}
 Bitmask values for all the virtual joystick positions of getTouchJoystickZones() More...
 

Functions

void getTouchCartesian (int32_t angle, int32_t radius, int32_t *x, int32_t *y)
 Convert touchpad angle and radius to cartesian coordinates.
 
touchJoystick_t getTouchJoystickZones (int32_t angle, int32_t radius, bool useCenter, bool useDiagonals)
 Convert touchpad angle and radius to a joystick enum, with either 4 or 8 directions and an optional center dead-zone.
 
void getTouchSpins (touchSpinState_t *state, int32_t angle, int32_t radius)
 Calculate the number of times the touchpad was circled.
 

Data Structure Documentation

◆ touchSpinState_t

struct touchSpinState_t
Data Fields
bool startSet
int32_t startAngle
int32_t startRadius
int32_t lastAngle
int32_t lastRadius
int32_t spins The number of complete CCW spins made. Negative indicates clockwise spins.
int32_t remainder The angle of the partial CCW spin, or negative for a CW spin.

Enumeration Type Documentation

◆ touchJoystick_t

Bitmask values for all the virtual joystick positions of getTouchJoystickZones()

Enumerator
TB_CENTER 
TB_RIGHT 
TB_UP 
TB_LEFT 
TB_DOWN 
TB_UP_RIGHT 
TB_UP_LEFT 
TB_DOWN_LEFT 
TB_DOWN_RIGHT 

Function Documentation

◆ getTouchCartesian()

void getTouchCartesian ( int32_t angle,
int32_t radius,
int32_t * x,
int32_t * y )

Convert touchpad angle and radius to cartesian coordinates.

Parameters
angleThe touchpad angle to convert
radiusThe touchpad radius to convert
[out]xA pointer to be set to the X touch coordinate, from 0 to 1023
[out]yA pointer to be set to the Y touch coordinate, from 0 to 1023

◆ getTouchJoystickZones()

touchJoystick_t getTouchJoystickZones ( int32_t angle,
int32_t radius,
bool useCenter,
bool useDiagonals )

Convert touchpad angle and radius to a joystick enum, with either 4 or 8 directions and an optional center dead-zone.

Parameters
angleThe touch angle reported by getTouchJoystick()
radiusThe touch radius reported by getTouchJoystick()
useCenterIf true, TB_CENTER will be returned if the stick is touched but inside the dead-zone
useDiagonalsIf true, diagonal directions will be returned as the bitwise OR of two directions
Returns
touchJoystick_t The joystick direction, or 0 if no direction could be determined.

◆ getTouchSpins()

void getTouchSpins ( touchSpinState_t * state,
int32_t angle,
int32_t radius )

Calculate the number of times the touchpad was circled.

When the touch is done, reset startSet to 0

Parameters
[in,out]stateA pointer to a touchSpinState_t to use for state.
angleThe current angle of the touch
radiusThe current radius of the touch