Autodetect serial port for AVox-USB adaptor on startup, and set 'avoxport' argument.

This completely automates the discovery of the AVox port when only one such port exists.
If there is more than one, this code selects the first one.  Further work will allow the user to go into the Input dialog and select the correct one, if more than one exists.

On my system, this adds about a 0.02 second delay to startup, so I think we can just leave it enabled.
If it ends up being too slow on some systems, we can introduce an option to disable autodetection.
This commit is contained in:
Stephen Anthony 2020-09-19 19:41:34 -02:30
parent 448df9765a
commit 91db2cdd33
2 changed files with 14 additions and 0 deletions

View File

@ -160,6 +160,12 @@ namespace BSPF
return (val < lower) ? upper : (val > upper) ? lower : val;
}
// Test whether the vector contains the given value
template<typename T>
bool contains(const std::vector<T>& v, const T& elem) {
return !(v.empty() || std::find(v.begin(), v.end(), elem) == v.end());
}
// Convert string to given case
inline const string& toUpperCase(string& s)
{

View File

@ -185,6 +185,14 @@ bool OSystem::create()
myPropSet->load(myPropertiesFile);
// Detect serial port for AtariVox-USB
// If a previously set port is available, use it;
// otherwise use the first one found (if any)
StringList ports = MediaFactory::createSerialPort()->portNames();
bool oldPortFound = BSPF::contains(ports, mySettings->getString("avoxport"));
if(!oldPortFound && ports.size() > 0)
mySettings->setValue("avoxport", ports[0]);
return true;
}