Fix crash if gc configured but adapter not connected
This commit is contained in:
parent
393cdb15f5
commit
ab65de2f96
|
@ -100,6 +100,9 @@ public:
|
||||||
void BeginConfiguration();
|
void BeginConfiguration();
|
||||||
void EndConfiguration();
|
void EndConfiguration();
|
||||||
|
|
||||||
|
/// Returns true if there is a device connected to port
|
||||||
|
bool DeviceConnected(std::size_t port);
|
||||||
|
|
||||||
std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue();
|
std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue();
|
||||||
const std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue() const;
|
const std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue() const;
|
||||||
|
|
||||||
|
@ -119,9 +122,6 @@ private:
|
||||||
/// Stop scanning for the adapter
|
/// Stop scanning for the adapter
|
||||||
void StopScanThread();
|
void StopScanThread();
|
||||||
|
|
||||||
/// Returns true if there is a device connected to port
|
|
||||||
bool DeviceConnected(std::size_t port);
|
|
||||||
|
|
||||||
/// Resets status of device connected to port
|
/// Resets status of device connected to port
|
||||||
void ResetDeviceType(std::size_t port);
|
void ResetDeviceType(std::size_t port);
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,11 @@ public:
|
||||||
~GCButton() override;
|
~GCButton() override;
|
||||||
|
|
||||||
bool GetStatus() const override {
|
bool GetStatus() const override {
|
||||||
|
if (gcadapter->DeviceConnected(port)) {
|
||||||
return gcadapter->GetPadState()[port].buttons.at(button);
|
return gcadapter->GetPadState()[port].buttons.at(button);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const int port;
|
const int port;
|
||||||
|
@ -44,14 +47,18 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetStatus() const override {
|
bool GetStatus() const override {
|
||||||
const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f;
|
if (gcadapter->DeviceConnected(port)) {
|
||||||
|
const float axis_value =
|
||||||
|
(gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f;
|
||||||
if (trigger_if_greater) {
|
if (trigger_if_greater) {
|
||||||
// TODO: Might be worthwile to set a slider for the trigger threshold. It is currently
|
// TODO: Might be worthwile to set a slider for the trigger threshold. It is
|
||||||
// always set to 0.5 in configure_input_player.cpp ZL/ZR HandleClick
|
// currently always set to 0.5 in configure_input_player.cpp ZL/ZR HandleClick
|
||||||
return axis_value > threshold;
|
return axis_value > threshold;
|
||||||
}
|
}
|
||||||
return axis_value < -threshold;
|
return axis_value < -threshold;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const int port;
|
const int port;
|
||||||
|
@ -151,12 +158,15 @@ public:
|
||||||
: port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter) {}
|
: port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter) {}
|
||||||
|
|
||||||
float GetAxis(int axis) const {
|
float GetAxis(int axis) const {
|
||||||
|
if (gcadapter->DeviceConnected(port)) {
|
||||||
std::lock_guard lock{mutex};
|
std::lock_guard lock{mutex};
|
||||||
// division is not by a perfect 128 to account for some variance in center location
|
// division is not by a perfect 128 to account for some variance in center location
|
||||||
// e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range
|
// e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range
|
||||||
// [20-230]
|
// [20-230]
|
||||||
return (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 95.0f;
|
return (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 95.0f;
|
||||||
}
|
}
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
std::pair<float, float> GetAnalog(int axis_x, int axis_y) const {
|
std::pair<float, float> GetAnalog(int axis_x, int axis_y) const {
|
||||||
float x = GetAxis(axis_x);
|
float x = GetAxis(axis_x);
|
||||||
|
|
Loading…
Reference in New Issue