Indexed-device config files for event-input layer
This allows multiple identical devices with event-input, using the same syntax as for PLIB JS
This commit is contained in:
parent
2ce4bcb666
commit
0762af76c2
2 changed files with 29 additions and 1 deletions
|
@ -363,6 +363,21 @@ void FGEventInput::update( double dt )
|
|||
}
|
||||
}
|
||||
|
||||
std::string FGEventInput::computeDeviceIndexName(FGInputDevice* dev) const
|
||||
{
|
||||
int count = 0;
|
||||
const auto devName = dev->GetName();
|
||||
for (auto it : input_devices) {
|
||||
if (it.second->GetName() == devName) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostringstream os;
|
||||
os << devName << "_" << count;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
unsigned FGEventInput::AddDevice( FGInputDevice * inputDevice )
|
||||
{
|
||||
SGPropertyNode_ptr baseNode = fgGetNode( PROPERTY_ROOT, true );
|
||||
|
@ -371,7 +386,7 @@ unsigned FGEventInput::AddDevice( FGInputDevice * inputDevice )
|
|||
const string deviceName = inputDevice->GetName();
|
||||
SGPropertyNode_ptr configNode;
|
||||
|
||||
// if we have a serial number set, tru using that to select a specfic configuration
|
||||
// if we have a serial number set, try using that to select a specfic configuration
|
||||
if (!inputDevice->GetSerialNumber().empty()) {
|
||||
const string nameWithSerial = deviceName + "::" + inputDevice->GetSerialNumber();
|
||||
if (configMap.hasConfiguration(nameWithSerial)) {
|
||||
|
@ -380,6 +395,16 @@ unsigned FGEventInput::AddDevice( FGInputDevice * inputDevice )
|
|||
<< nameWithSerial << " : " << configNode->getStringValue("source"));
|
||||
}
|
||||
}
|
||||
|
||||
// try instanced (counted) name
|
||||
if (configNode == nullptr) {
|
||||
const auto nameWithIndex = computeDeviceIndexName(inputDevice);
|
||||
if (configMap.hasConfiguration(nameWithIndex)) {
|
||||
configNode = configMap.configurationForDeviceName(nameWithIndex);
|
||||
SG_LOG(SG_INPUT, SG_INFO, "using instance-specific configuration for device "
|
||||
<< nameWithIndex << " : " << configNode->getStringValue("source"));
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise try the unmodifed name for the device
|
||||
if (configNode == nullptr) {
|
||||
|
|
|
@ -309,6 +309,9 @@ protected:
|
|||
FGDeviceConfigurationMap configMap;
|
||||
|
||||
SGPropertyNode_ptr nasalClose;
|
||||
|
||||
private:
|
||||
std::string computeDeviceIndexName(FGInputDevice *dev) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue