mirror of https://github.com/stella-emu/stella.git
Added code to detect valid serial ports.
Next we have to tie this into the UI, so AtariVox port can be more easily detected.
This commit is contained in:
parent
0703606c89
commit
67db826bc5
|
@ -65,6 +65,13 @@ class SerialPort
|
|||
*/
|
||||
virtual bool isCTS() { return true; }
|
||||
|
||||
/**
|
||||
Get all valid serial ports detected on this system.
|
||||
|
||||
@return The (possibly empty) list of detected serial ports
|
||||
*/
|
||||
virtual StringList portNames() { return StringList{}; }
|
||||
|
||||
private:
|
||||
// Following constructors and assignment operators not supported
|
||||
SerialPort(const SerialPort&) = delete;
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <sys/filio.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "FSNode.hxx"
|
||||
#include "SerialPortMACOS.hxx"
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -92,3 +93,26 @@ bool SerialPortMACOS::isCTS()
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
StringList SerialPortMACOS::portNames()
|
||||
{
|
||||
StringList ports;
|
||||
|
||||
// Get all possible devices in the '/dev' directory
|
||||
FilesystemNode::NameFilter filter = [](const FilesystemNode& node) {
|
||||
return BSPF::startsWithIgnoreCase(node.getPath(), "/dev/tty.usb");
|
||||
};
|
||||
FSList portList;
|
||||
portList.reserve(16);
|
||||
|
||||
FilesystemNode dev("/dev/");
|
||||
dev.getChildren(portList, FilesystemNode::ListMode::All, filter, false);
|
||||
|
||||
// Add only those that can be opened
|
||||
for(const auto& port: portList)
|
||||
if(openPort(port.getPath()))
|
||||
ports.emplace_back(port.getPath());
|
||||
|
||||
return ports;
|
||||
}
|
||||
|
|
|
@ -21,8 +21,7 @@
|
|||
#include "SerialPort.hxx"
|
||||
|
||||
/**
|
||||
Implement reading and writing from a serial port under macOS. For now,
|
||||
reading isn't actually supported at all.
|
||||
Implement reading and writing from a serial port under macOS.
|
||||
|
||||
@author Stephen Anthony & D. Spice
|
||||
*/
|
||||
|
@ -56,12 +55,19 @@ class SerialPortMACOS : public SerialPort
|
|||
*/
|
||||
bool writeByte(uInt8 data) override;
|
||||
|
||||
/**
|
||||
Test for 'Clear To Send' enabled.
|
||||
/**
|
||||
Test for 'Clear To Send' enabled.
|
||||
|
||||
@return True if CTS signal enabled, else false
|
||||
*/
|
||||
bool isCTS() override;
|
||||
@return True if CTS signal enabled, else false
|
||||
*/
|
||||
bool isCTS() override;
|
||||
|
||||
/**
|
||||
Get all valid serial ports detected on this system.
|
||||
|
||||
@return The (possibly empty) list of detected serial ports
|
||||
*/
|
||||
StringList portNames() override;
|
||||
|
||||
private:
|
||||
// File descriptor for serial connection
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <sys/ioctl.h>
|
||||
#include <cstring>
|
||||
|
||||
#include "FSNode.hxx"
|
||||
#include "SerialPortUNIX.hxx"
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -95,3 +96,28 @@ bool SerialPortUNIX::isCTS()
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
StringList SerialPortUNIX::portNames()
|
||||
{
|
||||
StringList ports;
|
||||
|
||||
// Get all possible devices in the '/dev' directory
|
||||
FilesystemNode::NameFilter filter = [](const FilesystemNode& node) {
|
||||
return BSPF::startsWithIgnoreCase(node.getPath(), "/dev/ttyACM") ||
|
||||
BSPF::startsWithIgnoreCase(node.getPath(), "/dev/ttyS") ||
|
||||
BSPF::startsWithIgnoreCase(node.getPath(), "/dev/ttyUSB");
|
||||
};
|
||||
FSList portList;
|
||||
portList.reserve(16);
|
||||
|
||||
FilesystemNode dev("/dev/");
|
||||
dev.getChildren(portList, FilesystemNode::ListMode::All, filter, false);
|
||||
|
||||
// Add only those that can be opened
|
||||
for(const auto& port: portList)
|
||||
if(openPort(port.getPath()))
|
||||
ports.emplace_back(port.getPath());
|
||||
|
||||
return ports;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
/**
|
||||
Implement reading and writing from a serial port under UNIX. For now,
|
||||
it seems to be Linux-only, and reading isn't actually supported at all.
|
||||
it seems to be Linux-only.
|
||||
|
||||
@author Stephen Anthony
|
||||
*/
|
||||
|
@ -63,6 +63,13 @@ class SerialPortUNIX : public SerialPort
|
|||
*/
|
||||
bool isCTS() override;
|
||||
|
||||
/**
|
||||
Get all valid serial ports detected on this system.
|
||||
|
||||
@return The (possibly empty) list of detected serial ports
|
||||
*/
|
||||
StringList portNames() override;
|
||||
|
||||
private:
|
||||
// File descriptor for serial connection
|
||||
int myHandle{0};
|
||||
|
|
|
@ -112,3 +112,39 @@ bool SerialPortWINDOWS::isCTS()
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
StringList SerialPortWINDOWS::portNames()
|
||||
{
|
||||
StringList ports;
|
||||
|
||||
HKEY hKey = NULL;
|
||||
LSTATUS result = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
||||
L"HARDWARE\\DEVICEMAP\\SERIALCOMM", 0, KEY_READ, &hKey);
|
||||
if (result == ERROR_SUCCESS)
|
||||
{
|
||||
TCHAR deviceName[2048], friendlyName[32];
|
||||
DWORD numValues = 0;
|
||||
|
||||
result = RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
&numValues, NULL, NULL, NULL, NULL);
|
||||
if (result == ERROR_SUCCESS)
|
||||
{
|
||||
DWORD type = 0;
|
||||
DWORD deviceNameLen = 2047;
|
||||
DWORD friendlyNameLen = 31;
|
||||
|
||||
for (DWORD i = 0; i < numValues; ++i)
|
||||
{
|
||||
result = RegEnumValue(hKey, i, deviceName, &deviceNameLen,
|
||||
NULL, &type, (LPBYTE)friendlyName, &friendlyNameLen);
|
||||
|
||||
if (result == ERROR_SUCCESS && type == REG_SZ)
|
||||
ports.emplace_back(friendlyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
|
||||
return ports;
|
||||
}
|
||||
|
|
|
@ -63,6 +63,13 @@ class SerialPortWINDOWS : public SerialPort
|
|||
*/
|
||||
bool isCTS() override;
|
||||
|
||||
/**
|
||||
Get all valid serial ports detected on this system.
|
||||
|
||||
@return The (possibly empty) list of detected serial ports
|
||||
*/
|
||||
StringList portNames() override;
|
||||
|
||||
private:
|
||||
// Handle to serial port
|
||||
HANDLE myHandle{0};
|
||||
|
|
|
@ -1742,7 +1742,6 @@
|
|||
<ClInclude Include="..\emucore\AmigaMouse.hxx" />
|
||||
<ClInclude Include="..\emucore\AtariMouse.hxx" />
|
||||
<ClInclude Include="..\emucore\Bankswitch.hxx" />
|
||||
<ClInclude Include="..\emucore\BSType.hxx" />
|
||||
<ClInclude Include="..\emucore\Cart3EPlus.hxx" />
|
||||
<ClInclude Include="..\emucore\Cart3EX.hxx" />
|
||||
<ClInclude Include="..\emucore\Cart4KSC.hxx" />
|
||||
|
|
|
@ -1829,9 +1829,6 @@
|
|||
<ClInclude Include="..\common\tv_filters\AtariNTSC.hxx">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\emucore\BSType.hxx">
|
||||
<Filter>Header Files\emucore</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\emucore\CartDetector.hxx">
|
||||
<Filter>Header Files\emucore</Filter>
|
||||
</ClInclude>
|
||||
|
|
Loading…
Reference in New Issue