cgv
Loading...
Searching...
No Matches
gamepad_driver.h
1#pragma once
2
3#include "gamepad.h"
4
5#include "lib_begin.h"
6
7namespace gamepad {
11 struct CGV_API gamepad_driver
12 {
14 unsigned driver_index;
16 virtual std::string get_name() = 0;
18 virtual void scan_devices(std::vector<device_info>& infos) = 0;
20 virtual void set_driver_state(bool enabled) = 0;
22 virtual void set_device_state(void* device_handle, bool enabled) = 0;
24 virtual bool get_device_battery_info(void* device_handle, BatteryType& battery_type, float& fill_state) = 0;
26 virtual bool query_device_key_event(void* device_handle, GamepadKeys& gk, KeyAction& action) = 0;
28 virtual bool get_device_state(void* device_handle, gamepad_state& state) = 0;
30 virtual bool set_device_vibration(void* device_handle, float low_frequency_strength, float high_frequency_strength) = 0;
31 };
33 extern CGV_API std::vector<device_info>& ref_device_infos();
35 extern CGV_API device_info* ref_device_info(void* device_handle);
37 extern CGV_API std::vector<driver_info>& ref_driver_infos();
39 extern CGV_API std::vector<gamepad_driver*>& ref_drivers();
41 extern CGV_API void register_driver(gamepad_driver* gpd);
43 template <typename T>
45 {
46 driver_registry(const std::string& options)
47 {
48 register_driver(new T(options));
49 }
50 };
51}
52
53#include <cgv/config/lib_end.h>
information provided per gamepad device
Definition gamepad.h:30
use this template to register your own driver
interface class for gamepad drivers, when implementing your driver, provide a constructor with a sing...
virtual void set_driver_state(bool enabled)=0
set the state to enabled or disabled
virtual bool query_device_key_event(void *device_handle, GamepadKeys &gk, KeyAction &action)=0
query event queue of given device for single gamepad key event
virtual void scan_devices(std::vector< device_info > &infos)=0
scan all connected devices found by driver
virtual std::string get_name()=0
return name of driver
unsigned driver_index
driver index is set during registration
virtual bool get_device_battery_info(void *device_handle, BatteryType &battery_type, float &fill_state)=0
return the battery type and state of a device, fill_state in [0,1] is only given for alkaline or nick...
virtual void set_device_state(void *device_handle, bool enabled)=0
set the state of a device to enabled or disabled
virtual bool set_device_vibration(void *device_handle, float low_frequency_strength, float high_frequency_strength)=0
set the vibration strength between 0 and 1 of low and high frequency motors, return false if device i...
virtual bool get_device_state(void *device_handle, gamepad_state &state)=0
retrieve the current state of gamepad stick and trigger positions
see https://upload.wikimedia.org/wikipedia/commons/2/2c/360_controller.svg for an explanation of the ...
Definition gamepad.h:152