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"
52 constexpr explicit operator bool()
const {
return !!
value; }
174 : m_resource(resource)
201 : m_resource(SDL_OpenSensor(instance_id))
211 std::swap(m_resource, other.m_resource);
222 m_resource =
nullptr;
230 constexpr bool operator==(std::nullptr_t _)
const {
return !m_resource; }
233 constexpr explicit operator bool()
const {
return !!m_resource; }
306 void GetData(
float* data,
int num_values);
357 auto data = SDL_GetSensors(&count);
373 return SDL_GetSensorNameForID(instance_id);
389 return SDL_GetSensorTypeForID(instance_id);
405 return SDL_GetSensorNonPortableTypeForID(instance_id);
430 return {SDL_GetSensorFromID(instance_id)};
444 return {
CheckError(SDL_GetSensorProperties(sensor))};
463 return SDL_GetSensorName(sensor);
479 return SDL_GetSensorType(sensor);
494 return SDL_GetSensorNonPortableType(sensor);
513 return SDL_GetSensorID(sensor);
532 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:159
constexpr Sensor(const Sensor &other)=delete
Copy constructor.
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_sensor.h:230
constexpr Sensor(Sensor &&other)
Move constructor.
Definition: SDL3pp_sensor.h:182
constexpr Sensor(const SensorRaw resource)
Constructs from SensorParam.
Definition: SDL3pp_sensor.h:173
Sensor & operator=(Sensor other)
Assignment operator.
Definition: SDL3pp_sensor.h:209
constexpr auto operator<=>(const Sensor &other) const =default
Comparison.
constexpr Sensor()=default
Default ctor.
constexpr SensorRaw get() const
Retrieves underlying SensorRaw.
Definition: SDL3pp_sensor.h:216
~Sensor()
Destructor.
Definition: SDL3pp_sensor.h:206
Sensor(SensorID instance_id)
Open a sensor for use.
Definition: SDL3pp_sensor.h:200
constexpr SensorRaw release()
Retrieves underlying SensorRaw and clear this.
Definition: SDL3pp_sensor.h:219
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:198
PropertiesRef GetSensorProperties(SensorParam sensor)
Get the properties associated with a sensor.
Definition: SDL3pp_sensor.h:442
SensorRef GetSensorFromID(SensorID instance_id)
Return the Sensor associated with an instance ID.
Definition: SDL3pp_sensor.h:428
constexpr SensorType SENSOR_GYRO
Gyroscope.
Definition: SDL3pp_sensor.h:135
OwnArray< SensorID > GetSensors()
Get a list of currently connected sensors.
Definition: SDL3pp_sensor.h:354
SensorID GetSensorID(SensorParam sensor)
Get the instance ID of a sensor.
Definition: SDL3pp_sensor.h:511
int GetNonPortableType()
Get the platform dependent type of a sensor.
Definition: SDL3pp_sensor.h:497
void GetData(float *data, int num_values)
Get the current state of an opened sensor.
Definition: SDL3pp_sensor.h:535
const char * GetSensorName(SensorParam sensor)
Get the implementation dependent name of a sensor.
Definition: SDL3pp_sensor.h:461
void UpdateSensors()
Update the current state of the open sensors.
Definition: SDL3pp_sensor.h:562
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:417
SensorType GetSensorType(SensorParam sensor)
Get the type of a sensor.
Definition: SDL3pp_sensor.h:477
SensorType GetType()
Get the type of a sensor.
Definition: SDL3pp_sensor.h:482
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:387
SDL_Sensor * SensorRaw
Alias to raw representation for Sensor.
Definition: SDL3pp_sensor.h:29
void CloseSensor(SensorRaw sensor)
Close a sensor previously opened with Sensor.Sensor().
Definition: SDL3pp_sensor.h:547
constexpr float STANDARD_GRAVITY
A constant to represent standard gravity for accelerometer sensors.
Definition: SDL3pp_sensor.h:344
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:492
constexpr SensorType SENSOR_COUNT
SENSOR_COUNT.
Definition: SDL3pp_sensor.h:149
void GetSensorData(SensorParam sensor, float *data, int num_values)
Get the current state of an opened sensor.
Definition: SDL3pp_sensor.h:530
SensorID GetID()
Get the instance ID of a sensor.
Definition: SDL3pp_sensor.h:516
const char * GetSensorNameForID(SensorID instance_id)
Get the implementation dependent name of a sensor.
Definition: SDL3pp_sensor.h:371
void Close()
Close a sensor previously opened with Sensor.Sensor().
Definition: SDL3pp_sensor.h:549
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:403
const char * GetName()
Get the implementation dependent name of a sensor.
Definition: SDL3pp_sensor.h:466
PropertiesRef GetProperties()
Get the properties associated with a sensor.
Definition: SDL3pp_sensor.h:447
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:69
Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:325
Main include header for the SDL3pp library.
Semi-safe reference for Properties.
Definition: SDL3pp_properties.h:569
Safely wrap Sensor for non owning parameters.
Definition: SDL3pp_sensor.h:36
constexpr SensorParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_sensor.h:46
constexpr auto operator<=>(const SensorParam &other) const =default
Comparison.
SensorRaw value
parameter's SensorRaw
Definition: SDL3pp_sensor.h:37
constexpr SensorParam(SensorRaw value)
Constructs from SensorRaw.
Definition: SDL3pp_sensor.h:40
Semi-safe reference for Sensor.
Definition: SDL3pp_sensor.h:311
SensorRef(SensorParam resource)
Constructs from SensorParam.
Definition: SDL3pp_sensor.h:319
SensorRef(const SensorRef &other)
Copy constructor.
Definition: SDL3pp_sensor.h:325
~SensorRef()
Destructor.
Definition: SDL3pp_sensor.h:331