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"
53 constexpr explicit operator bool()
const {
return !!
value; }
149#if SDL_VERSION_ATLEAST(3, 2, 22)
168 constexpr Sensor(std::nullptr_t =
nullptr) noexcept
181 : m_resource(resource)
210 : m_resource(SDL_OpenSensor(instance_id))
220 std::swap(m_resource, other.m_resource);
236 m_resource =
nullptr;
244 constexpr explicit operator bool() const noexcept {
return !!m_resource; }
247 constexpr operator SensorParam() const noexcept {
return {m_resource}; }
315 void GetData(
float* data,
int num_values);
377 auto data = SDL_GetSensors(&count);
393 return SDL_GetSensorNameForID(instance_id);
408 return SDL_GetSensorTypeForID(instance_id);
424 return SDL_GetSensorNonPortableTypeForID(instance_id);
449 return {SDL_GetSensorFromID(instance_id)};
463 return {
CheckError(SDL_GetSensorProperties(sensor))};
482 return SDL_GetSensorName(sensor);
497 return SDL_GetSensorType(sensor);
512 return SDL_GetSensorNonPortableType(sensor);
531 return SDL_GetSensorID(sensor);
550 CheckError(SDL_GetSensorData(sensor, data, num_values));
Base class for SDL memory allocated array wrap.
Definition: SDL3pp_ownPtr.h:44
The opaque structure used to identify an opened SDL sensor.
Definition: SDL3pp_sensor.h:163
constexpr SensorRaw get() const noexcept
Retrieves underlying SensorRaw.
Definition: SDL3pp_sensor.h:230
constexpr SensorRaw release() noexcept
Retrieves underlying SensorRaw and clear this.
Definition: SDL3pp_sensor.h:233
constexpr Sensor & operator=(Sensor &&other) noexcept
Assignment operator.
Definition: SDL3pp_sensor.h:218
constexpr Sensor & operator=(const Sensor &other) noexcept=default
Assignment operator.
constexpr Sensor(const Sensor &other) noexcept=default
Copy constructor.
constexpr auto operator<=>(const Sensor &other) const noexcept=default
Comparison.
constexpr Sensor(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_sensor.h:168
~Sensor()
Destructor.
Definition: SDL3pp_sensor.h:215
constexpr Sensor(const SensorRaw resource) noexcept
Constructs from SensorParam.
Definition: SDL3pp_sensor.h:180
Sensor(SensorID instance_id)
Open a sensor for use.
Definition: SDL3pp_sensor.h:209
constexpr Sensor(Sensor &&other) noexcept
Move constructor.
Definition: SDL3pp_sensor.h:191
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:197
PropertiesRef GetSensorProperties(SensorParam sensor)
Get the properties associated with a sensor.
Definition: SDL3pp_sensor.h:461
SensorRef GetSensorFromID(SensorID instance_id)
Return the Sensor associated with an instance ID.
Definition: SDL3pp_sensor.h:447
constexpr SensorType SENSOR_GYRO
Gyroscope.
Definition: SDL3pp_sensor.h:135
OwnArray< SensorID > GetSensors()
Get a list of currently connected sensors.
Definition: SDL3pp_sensor.h:374
SensorID GetSensorID(SensorParam sensor)
Get the instance ID of a sensor.
Definition: SDL3pp_sensor.h:529
int GetNonPortableType()
Get the platform dependent type of a sensor.
Definition: SDL3pp_sensor.h:515
void GetData(float *data, int num_values)
Get the current state of an opened sensor.
Definition: SDL3pp_sensor.h:553
const char * GetSensorName(SensorParam sensor)
Get the implementation dependent name of a sensor.
Definition: SDL3pp_sensor.h:480
void UpdateSensors()
Update the current state of the open sensors.
Definition: SDL3pp_sensor.h:579
constexpr SensorType SENSOR_ACCEL
Accelerometer.
Definition: SDL3pp_sensor.h:133
constexpr SensorType SENSOR_INVALID
Returned for an invalid sensor.
Definition: SDL3pp_sensor.h:127
SDL_SensorType SensorType
The different sensors defined by SDL.
Definition: SDL3pp_sensor.h:125
constexpr SensorType SENSOR_ACCEL_L
Accelerometer for left Joy-Con controller and Wii nunchuk.
Definition: SDL3pp_sensor.h:138
Sensor OpenSensor(SensorID instance_id)
Open a sensor for use.
Definition: SDL3pp_sensor.h:436
SensorType GetSensorType(SensorParam sensor)
Get the type of a sensor.
Definition: SDL3pp_sensor.h:495
SensorType GetType()
Get the type of a sensor.
Definition: SDL3pp_sensor.h:500
constexpr SensorType SENSOR_UNKNOWN
Unknown sensor type.
Definition: SDL3pp_sensor.h:130
SensorType GetSensorTypeForID(SensorID instance_id)
Get the type of a sensor.
Definition: SDL3pp_sensor.h:406
SDL_Sensor * SensorRaw
Alias to raw representation for Sensor.
Definition: SDL3pp_sensor.h:30
void CloseSensor(SensorRaw sensor)
Close a sensor previously opened with Sensor.Sensor().
Definition: SDL3pp_sensor.h:565
constexpr float STANDARD_GRAVITY
A constant to represent standard gravity for accelerometer sensors.
Definition: SDL3pp_sensor.h:364
constexpr SensorType SENSOR_ACCEL_R
Accelerometer for right Joy-Con controller.
Definition: SDL3pp_sensor.h:143
int GetSensorNonPortableType(SensorParam sensor)
Get the platform dependent type of a sensor.
Definition: SDL3pp_sensor.h:510
constexpr SensorType SENSOR_COUNT
SENSOR_COUNT.
Definition: SDL3pp_sensor.h:151
void GetSensorData(SensorParam sensor, float *data, int num_values)
Get the current state of an opened sensor.
Definition: SDL3pp_sensor.h:548
SensorID GetID()
Get the instance ID of a sensor.
Definition: SDL3pp_sensor.h:534
const char * GetSensorNameForID(SensorID instance_id)
Get the implementation dependent name of a sensor.
Definition: SDL3pp_sensor.h:391
void Close()
Close a sensor previously opened with Sensor.Sensor().
Definition: SDL3pp_sensor.h:567
constexpr SensorType SENSOR_GYRO_R
Gyroscope for right Joy-Con controller.
Definition: SDL3pp_sensor.h:146
int GetSensorNonPortableTypeForID(SensorID instance_id)
Get the platform dependent type of a sensor.
Definition: SDL3pp_sensor.h:422
const char * GetName()
Get the implementation dependent name of a sensor.
Definition: SDL3pp_sensor.h:485
PropertiesRef GetProperties()
Get the properties associated with a sensor.
Definition: SDL3pp_sensor.h:466
constexpr SensorType SENSOR_GYRO_L
Gyroscope for left Joy-Con controller.
Definition: SDL3pp_sensor.h:140
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:70
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:341
Main include header for the SDL3pp library.
Semi-safe reference for Properties.
Definition: SDL3pp_properties.h:716
Safely wrap Sensor for non owning parameters.
Definition: SDL3pp_sensor.h:37
constexpr auto operator<=>(const SensorParam &other) const =default
Comparison.
constexpr SensorParam(std::nullptr_t=nullptr)
Constructs null/invalid.
Definition: SDL3pp_sensor.h:47
SensorRaw value
parameter's SensorRaw
Definition: SDL3pp_sensor.h:38
constexpr SensorParam(SensorRaw value)
Constructs from SensorRaw.
Definition: SDL3pp_sensor.h:41
Semi-safe reference for Sensor.
Definition: SDL3pp_sensor.h:320
SensorRef(SensorParam resource) noexcept
Constructs from SensorParam.
Definition: SDL3pp_sensor.h:330
constexpr SensorRef(const SensorRef &other) noexcept=default
Copy constructor.
SensorRef(SensorRaw resource) noexcept
Constructs from SensorParam.
Definition: SDL3pp_sensor.h:342
~SensorRef()
Destructor.
Definition: SDL3pp_sensor.h:351