2#include "gamepad_driver.h"
9 static const char* gamepad_key_names[] = {
39 "LEFT_STICK_DOWNRIGHT",
40 "LEFT_STICK_DOWNLEFT",
47 "RIGHT_STICK_UPRIGHT",
48 "RIGHT_STICK_DOWNRIGHT",
49 "RIGHT_STICK_DOWNLEFT"
51 int index = key - (int)GPK_UNKNOWN;
52 return index < 33 ? gamepad_key_names[index] :
"";
56 std::string convert_flags_to_string(GamepadButtonStateFlags flags)
58 static const char* flag_names[] = {
74 static const GamepadButtonStateFlags flag_values[] = {
91 for (
unsigned i = 0; i < 14; ++i)
92 if ((flags & flag_values[i]) != 0) {
94 result = flag_names[i];
96 result += std::string(
"+") + flag_names[i];
111 const std::vector<driver_info>& get_driver_infos()
113 return ref_driver_infos();
116 void set_driver_state(
unsigned i,
bool enabled)
118 assert(i < ref_drivers().size());
119 ref_drivers()[i]->set_driver_state(enabled);
120 ref_driver_infos()[i].enabled = enabled;
126 ref_device_infos().clear();
128 driver_ptr->scan_devices(ref_device_infos());
131 const std::vector<device_info>& get_device_infos()
133 return ref_device_infos();
136 const device_info* get_device_info(
void* device_handle)
138 return ref_device_info(device_handle);
141 bool get_driver_index(
void* device_handle,
unsigned& driver_index)
144 auto* dip = get_device_info(device_handle);
147 driver_index = (unsigned)dip->driver_index;
153 bool is_connected(
void* device_handle)
156 unsigned driver_index;
157 if (!get_driver_index(device_handle, driver_index))
159 return ref_drivers()[driver_index]->get_device_state(device_handle, state);
162 bool set_device_state(
void* device_handle,
bool enabled)
164 unsigned driver_index;
165 if (!get_driver_index(device_handle, driver_index))
167 ref_drivers()[driver_index]->set_device_state(device_handle, enabled);
168 ref_device_info(device_handle)->
enabled = enabled;
172 bool get_device_battery_info(
void* device_handle, BatteryType& battery_type,
float& fill_state)
174 unsigned driver_index;
175 if (!get_driver_index(device_handle, driver_index))
177 return ref_drivers()[driver_index]->get_device_battery_info(device_handle, battery_type, fill_state);
179 bool query_key_event(
void* device_handle, GamepadKeys& gk, KeyAction& action)
181 unsigned driver_index;
182 if (!get_driver_index(device_handle, driver_index))
184 return ref_drivers()[driver_index]->query_device_key_event(device_handle, gk, action);
187 bool get_state(
void* device_handle, gamepad_state& state)
189 unsigned driver_index;
190 if (!get_driver_index(device_handle, driver_index))
192 return ref_drivers()[driver_index]->get_device_state(device_handle, state);
195 bool set_vibration(
void* device_handle,
float low_frequency_strength,
float high_frequency_strength)
197 unsigned driver_index;
198 if (!get_driver_index(device_handle, driver_index))
200 return ref_drivers()[driver_index]->set_device_vibration(device_handle, low_frequency_strength, high_frequency_strength);
std::vector< vr_driver * > & ref_drivers()
return registered drivers
std::string get_key_string(unsigned short key)
convert key to string
bool enabled
whether device is enabled
float right_stick_position[2]
x and y position of left thumb in the range [-1,1]
unsigned time_stamp
time stamp can be used whether a change has happened between two states
float left_stick_position[2]
x and y position of left thumb in the range [-1,1]
unsigned button_flags
combination of flags in GamepadButtonStateFlags combined with the OR operation
gamepad_state()
initialize state
float trigger_position[2]
values of left and right triggers in the range [0,1]