1#ifndef SDL3PP_SENSOR_H_
2#define SDL3PP_SENSOR_H_
4#include <SDL3/SDL_sensor.h>
5#include "SDL3pp_error.h"
6#include "SDL3pp_properties.h"
7#include "SDL3pp_stdinc.h"
8#include "SDL3pp_version.h"
129#if SDL_VERSION_ATLEAST(3, 2, 22)
210 void GetData(
float* data,
int num_values);
222 using SensorBase::SensorBase;
287 auto data = SDL_GetSensors(&count);
303 return SDL_GetSensorNameForID(instance_id);
318 return SDL_GetSensorTypeForID(instance_id);
334 return SDL_GetSensorNonPortableTypeForID(instance_id);
349 :
Sensor(SDL_OpenSensor(instance_id))
364 return {SDL_GetSensorFromID(instance_id)};
378 return {
CheckError(SDL_GetSensorProperties(sensor))};
397 return SDL_GetSensorName(sensor);
412 return SDL_GetSensorType(sensor);
427 return SDL_GetSensorNonPortableType(sensor);
465 CheckError(SDL_GetSensorData(sensor, data, num_values));
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:57
friend constexpr void swap(ResourceBaseT &lhs, ResourceBaseT &rhs) noexcept
Definition SDL3pp_resource.h:65
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:54
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
ResourceRefT< PropertiesBase > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:53
void GetSensorData(SensorRef sensor, float *data, int num_values)
Get the current state of an opened sensor.
Definition SDL3pp_sensor.h:463
SensorRef GetSensorFromID(SensorID instance_id)
Return the Sensor associated with an instance ID.
Definition SDL3pp_sensor.h:362
SensorID GetSensorID(SensorRef sensor)
Get the instance ID of a sensor.
Definition SDL3pp_sensor.h:444
constexpr SensorType SENSOR_GYRO
Gyroscope.
Definition SDL3pp_sensor.h:115
Uint32 SensorID
This is a unique ID for a sensor for the time it is connected to the system, and is never reused for ...
Definition SDL3pp_sensor.h:50
OwnArray< SensorID > GetSensors()
Get a list of currently connected sensors.
Definition SDL3pp_sensor.h:284
const char * GetSensorName(SensorRef sensor)
Get the implementation dependent name of a sensor.
Definition SDL3pp_sensor.h:395
SensorID GetID()
Get the instance ID of a sensor.
Definition SDL3pp_sensor.h:449
void UpdateSensors()
Update the current state of the open sensors.
Definition SDL3pp_sensor.h:494
constexpr SensorType SENSOR_ACCEL
Accelerometer.
Definition SDL3pp_sensor.h:113
constexpr SensorType SENSOR_INVALID
Returned for an invalid sensor.
Definition SDL3pp_sensor.h:107
const char * GetName()
Get the implementation dependent name of a sensor.
Definition SDL3pp_sensor.h:400
constexpr SensorType SENSOR_ACCEL_L
Accelerometer for left Joy-Con controller and Wii nunchuk.
Definition SDL3pp_sensor.h:118
SensorType GetSensorType(SensorRef sensor)
Get the type of a sensor.
Definition SDL3pp_sensor.h:410
Sensor OpenSensor(SensorID instance_id)
Open a sensor for use.
Definition SDL3pp_sensor.h:346
SensorType GetType()
Get the type of a sensor.
Definition SDL3pp_sensor.h:415
void Close()
Close a sensor previously opened with OpenSensor().
Definition SDL3pp_sensor.h:482
int GetNonPortableType()
Get the platform dependent type of a sensor.
Definition SDL3pp_sensor.h:430
constexpr SensorType SENSOR_UNKNOWN
Unknown sensor type.
Definition SDL3pp_sensor.h:110
SDL_Sensor * SensorRaw
Alias to raw representation for Sensor.
Definition SDL3pp_sensor.h:33
int GetSensorNonPortableType(SensorRef sensor)
Get the platform dependent type of a sensor.
Definition SDL3pp_sensor.h:425
SensorType GetSensorTypeForID(SensorID instance_id)
Get the type of a sensor.
Definition SDL3pp_sensor.h:316
PropertiesRef GetSensorProperties(SensorRef sensor)
Get the properties associated with a sensor.
Definition SDL3pp_sensor.h:376
SDL_SensorType SensorType
The different sensors defined by SDL.
Definition SDL3pp_sensor.h:105
void CloseSensor(SensorRaw sensor)
Close a sensor previously opened with OpenSensor().
Definition SDL3pp_sensor.h:480
constexpr float STANDARD_GRAVITY
A constant to represent standard gravity for accelerometer sensors.
Definition SDL3pp_sensor.h:274
constexpr SensorType SENSOR_ACCEL_R
Accelerometer for right Joy-Con controller.
Definition SDL3pp_sensor.h:123
void GetData(float *data, int num_values)
Get the current state of an opened sensor.
Definition SDL3pp_sensor.h:468
constexpr SensorType SENSOR_COUNT
SENSOR_COUNT.
Definition SDL3pp_sensor.h:131
PropertiesRef GetProperties()
Get the properties associated with a sensor.
Definition SDL3pp_sensor.h:381
const char * GetSensorNameForID(SensorID instance_id)
Get the implementation dependent name of a sensor.
Definition SDL3pp_sensor.h:301
constexpr SensorType SENSOR_GYRO_R
Gyroscope for right Joy-Con controller.
Definition SDL3pp_sensor.h:126
int GetSensorNonPortableTypeForID(SensorID instance_id)
Get the platform dependent type of a sensor.
Definition SDL3pp_sensor.h:332
constexpr SensorType SENSOR_GYRO_L
Gyroscope for left Joy-Con controller.
Definition SDL3pp_sensor.h:120
ResourceRefT< SensorBase > SensorRef
Reference for Sensor.
Definition SDL3pp_sensor.h:40
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition SDL3pp_stdinc.h:296
Main include header for the SDL3pp library.
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93
Base class to Sensor.
Definition SDL3pp_sensor.h:141
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
The opaque structure used to identify an opened SDL sensor.
Definition SDL3pp_sensor.h:221
constexpr Sensor & operator=(Sensor &&other) noexcept
Assignment operator.
Definition SDL3pp_sensor.h:257
~Sensor()
Destructor.
Definition SDL3pp_sensor.h:254
constexpr Sensor(SensorRaw resource) noexcept
Constructs from raw Sensor.
Definition SDL3pp_sensor.h:231
constexpr Sensor(Sensor &&other) noexcept
Move constructor.
Definition SDL3pp_sensor.h:237