mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
Added friendly names to serial ports, added automatic selection of Prusa's printers in the firmware updater dialog
This commit is contained in:
parent
7f8265e2be
commit
33f21422e6
8 changed files with 187 additions and 94 deletions
|
@ -4,7 +4,6 @@
|
|||
#include <assert.h>
|
||||
#include <cmath>
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
|
@ -25,7 +24,6 @@
|
|||
#undef max
|
||||
#endif
|
||||
#include "boost/nowide/convert.hpp"
|
||||
#pragma comment(lib, "user32.lib")
|
||||
#endif
|
||||
|
||||
#include <wx/app.h>
|
||||
|
@ -88,83 +86,6 @@ void enable_screensaver()
|
|||
#endif
|
||||
}
|
||||
|
||||
std::vector<std::string> scan_serial_ports()
|
||||
{
|
||||
std::vector<std::string> out;
|
||||
#ifdef _WIN32
|
||||
// 1) Open the registry key SERIALCOM.
|
||||
HKEY hKey;
|
||||
LONG lRes = ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"HARDWARE\\DEVICEMAP\\SERIALCOMM", 0, KEY_READ, &hKey);
|
||||
assert(lRes == ERROR_SUCCESS);
|
||||
if (lRes == ERROR_SUCCESS) {
|
||||
// 2) Get number of values of SERIALCOM key.
|
||||
DWORD cValues; // number of values for key
|
||||
{
|
||||
TCHAR achKey[255]; // buffer for subkey name
|
||||
DWORD cbName; // size of name string
|
||||
TCHAR achClass[MAX_PATH] = TEXT(""); // buffer for class name
|
||||
DWORD cchClassName = MAX_PATH; // size of class string
|
||||
DWORD cSubKeys=0; // number of subkeys
|
||||
DWORD cbMaxSubKey; // longest subkey size
|
||||
DWORD cchMaxClass; // longest class string
|
||||
DWORD cchMaxValue; // longest value name
|
||||
DWORD cbMaxValueData; // longest value data
|
||||
DWORD cbSecurityDescriptor; // size of security descriptor
|
||||
FILETIME ftLastWriteTime; // last write time
|
||||
// Get the class name and the value count.
|
||||
lRes = RegQueryInfoKey(
|
||||
hKey, // key handle
|
||||
achClass, // buffer for class name
|
||||
&cchClassName, // size of class string
|
||||
NULL, // reserved
|
||||
&cSubKeys, // number of subkeys
|
||||
&cbMaxSubKey, // longest subkey size
|
||||
&cchMaxClass, // longest class string
|
||||
&cValues, // number of values for this key
|
||||
&cchMaxValue, // longest value name
|
||||
&cbMaxValueData, // longest value data
|
||||
&cbSecurityDescriptor, // security descriptor
|
||||
&ftLastWriteTime); // last write time
|
||||
assert(lRes == ERROR_SUCCESS);
|
||||
}
|
||||
// 3) Read the SERIALCOM values.
|
||||
{
|
||||
DWORD dwIndex = 0;
|
||||
for (int i = 0; i < cValues; ++ i, ++ dwIndex) {
|
||||
wchar_t valueName[2048];
|
||||
DWORD valNameLen = 2048;
|
||||
DWORD dataType;
|
||||
wchar_t data[2048];
|
||||
DWORD dataSize = 4096;
|
||||
lRes = ::RegEnumValueW(hKey, dwIndex, valueName, &valNameLen, nullptr, &dataType, (BYTE*)&data, &dataSize);
|
||||
if (lRes == ERROR_SUCCESS && dataType == REG_SZ && valueName[0] != 0)
|
||||
out.emplace_back(boost::nowide::narrow(data));
|
||||
}
|
||||
}
|
||||
::RegCloseKey(hKey);
|
||||
}
|
||||
#else
|
||||
// UNIX and OS X
|
||||
std::initializer_list<const char*> prefixes { "ttyUSB" , "ttyACM", "tty.", "cu.", "rfcomm" };
|
||||
for (auto &dir_entry : boost::filesystem::directory_iterator(boost::filesystem::path("/dev"))) {
|
||||
std::string name = dir_entry.path().filename().string();
|
||||
for (const char *prefix : prefixes) {
|
||||
if (boost::starts_with(name, prefix)) {
|
||||
out.emplace_back(dir_entry.path().string());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
out.erase(std::remove_if(out.begin(), out.end(),
|
||||
[](const std::string &key){
|
||||
return boost::starts_with(key, "Bluetooth") || boost::starts_with(key, "FireFly");
|
||||
}),
|
||||
out.end());
|
||||
return out;
|
||||
}
|
||||
|
||||
bool debugged()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue