From 0cdd6c4e700645c845c83f00bfd5f774e2a17aca Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 29 Apr 2018 10:13:42 +0100 Subject: [PATCH] Re-init support on HID-event-input To ensure the device-configuration-map is re-read, added a default ctor and moved the config-map creation to init() --- src/Input/FGDeviceConfigurationMap.cxx | 5 +++++ src/Input/FGDeviceConfigurationMap.hxx | 3 +++ src/Input/FGEventInput.cxx | 6 ++++-- src/Input/FGEventInput.hxx | 8 ++++---- src/Input/FGHIDEventInput.cxx | 11 +++++++++++ src/Input/FGHIDEventInput.hxx | 3 +++ src/Input/input.cxx | 6 +++--- 7 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/Input/FGDeviceConfigurationMap.cxx b/src/Input/FGDeviceConfigurationMap.cxx index 95d107e04..a5d597ad1 100644 --- a/src/Input/FGDeviceConfigurationMap.cxx +++ b/src/Input/FGDeviceConfigurationMap.cxx @@ -38,6 +38,11 @@ using simgear::PropertyList; using std::string; +FGDeviceConfigurationMap::FGDeviceConfigurationMap() +{ + +} + FGDeviceConfigurationMap::FGDeviceConfigurationMap( const string& relative_path, SGPropertyNode* nodePath, const std::string& nodeName) diff --git a/src/Input/FGDeviceConfigurationMap.hxx b/src/Input/FGDeviceConfigurationMap.hxx index 8266a466b..ed3a48184 100644 --- a/src/Input/FGDeviceConfigurationMap.hxx +++ b/src/Input/FGDeviceConfigurationMap.hxx @@ -37,6 +37,8 @@ class FGDeviceConfigurationMap { public: + FGDeviceConfigurationMap(); + FGDeviceConfigurationMap ( const std::string& relative_path, SGPropertyNode* nodePath, const std::string& nodeName); @@ -45,6 +47,7 @@ public: SGPropertyNode_ptr configurationForDeviceName(const std::string& name); bool hasConfiguration(const std::string& name) const; + private: void scan_dir(const SGPath & path); diff --git a/src/Input/FGEventInput.cxx b/src/Input/FGEventInput.cxx index e34f09bf6..f86fa3e1e 100644 --- a/src/Input/FGEventInput.cxx +++ b/src/Input/FGEventInput.cxx @@ -327,8 +327,7 @@ void FGInputDevice::SendFeatureReport(unsigned int reportId, const std::string& const char * FGEventInput::PROPERTY_ROOT = "/input/event"; -FGEventInput::FGEventInput() : - configMap( "Input/Event", fgGetNode(PROPERTY_ROOT, true), "device-named") +FGEventInput::FGEventInput() { } @@ -348,6 +347,9 @@ void FGEventInput::shutdown() void FGEventInput::init( ) { + configMap = FGDeviceConfigurationMap( "Input/Event", + fgGetNode(PROPERTY_ROOT, true), + "device-named"); } void FGEventInput::postinit () diff --git a/src/Input/FGEventInput.hxx b/src/Input/FGEventInput.hxx index 055611a9d..f5bf9462f 100644 --- a/src/Input/FGEventInput.hxx +++ b/src/Input/FGEventInput.hxx @@ -292,10 +292,10 @@ class FGEventInput : public SGSubsystem,FGCommonInput { public: FGEventInput(); virtual ~FGEventInput(); - virtual void init(); - virtual void postinit(); - virtual void update( double dt ); - virtual void shutdown() override; + void init() override; + void postinit() override; + void update( double dt ) override; + void shutdown() override; const static unsigned MAX_DEVICES = 1000; const static unsigned INVALID_DEVICE_INDEX = MAX_DEVICES + 1; diff --git a/src/Input/FGHIDEventInput.cxx b/src/Input/FGHIDEventInput.cxx index 3b2c96a1b..7bda1494b 100644 --- a/src/Input/FGHIDEventInput.cxx +++ b/src/Input/FGHIDEventInput.cxx @@ -711,8 +711,18 @@ void FGHIDEventInput::init() // requires Nasal to be running } +void FGHIDEventInput::reinit() +{ + SG_LOG(SG_INPUT, SG_INFO, "Re-Initializing HID input bindings"); + FGHIDEventInput::shutdown(); + FGHIDEventInput::init(); + FGHIDEventInput::postinit(); +} + void FGHIDEventInput::postinit() { + SG_LOG(SG_INPUT, SG_INFO, "HID event input starting up"); + hid_init(); hid_device_info* devices = hid_enumerate(0 /* vendor ID */, 0 /* product ID */); @@ -726,6 +736,7 @@ void FGHIDEventInput::postinit() void FGHIDEventInput::shutdown() { + SG_LOG(SG_INPUT, SG_INFO, "HID event input shutting down"); FGEventInput::shutdown(); hid_exit(); diff --git a/src/Input/FGHIDEventInput.hxx b/src/Input/FGHIDEventInput.hxx index 92d66fd1e..8d755619e 100644 --- a/src/Input/FGHIDEventInput.hxx +++ b/src/Input/FGHIDEventInput.hxx @@ -35,8 +35,11 @@ public: void update(double dt) override; void init() override; + void reinit() override; void postinit(); void shutdown() override; + + static const char* subsystemName() { return "input-hid"; } private: class FGHIDEventInputPrivate; diff --git a/src/Input/input.cxx b/src/Input/input.cxx index 8992f260f..88f011423 100644 --- a/src/Input/input.cxx +++ b/src/Input/input.cxx @@ -85,10 +85,10 @@ FGInput::FGInput () #endif #if defined(ENABLE_HID_INPUT) && defined(WITH_EVENTINPUT) - if (fgGetBool("/sim/input/enable-hid", true)) { - set_subsystem( "input-event-hid", new FGHIDEventInput() ); - } else { + if (fgGetBool("/sim/input/no-hid-input", false)) { SG_LOG(SG_INPUT, SG_WARN, "HID-based event input disabled"); + } else { + set_subsystem( "input-event-hid", new FGHIDEventInput() ); } #endif }