mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Merge.
This commit is contained in:
@@ -131,7 +131,7 @@ public:
|
||||
.write_8(CMD_READ_FLUX)
|
||||
.write_8(cmd.size())
|
||||
.write_le32(0) //ticks default value (guessed)
|
||||
.write_le32(2);//guessed
|
||||
.write_le16(2);//revolutions
|
||||
do_command(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <termios.h>
|
||||
|
||||
#if defined __WIN32__
|
||||
#include <windows.h>
|
||||
@@ -45,8 +47,16 @@
|
||||
COMMTIMEOUTS commtimeouts = {0};
|
||||
commtimeouts.ReadIntervalTimeout = 100;
|
||||
SetCommTimeouts(_handle, &commtimeouts);
|
||||
|
||||
if (!EscapeCommFunction(_handle, CLRDTR))
|
||||
Error() << fmt::format("Couldn't clear DTR: {}",
|
||||
get_last_error_string());
|
||||
Sleep(200);
|
||||
if (!EscapeCommFunction(_handle, SETDTR))
|
||||
Error() << fmt::format("Couldn't set DTR: {}",
|
||||
get_last_error_string());
|
||||
|
||||
PurgeComm(_handle, PURGE_RXABORT|PURGE_RXCLEAR|PURGE_TXABORT|PURGE_TXCLEAR);
|
||||
PurgeComm(_handle, PURGE_RXABORT|PURGE_RXCLEAR|PURGE_TXABORT|PURGE_TXCLEAR);
|
||||
}
|
||||
|
||||
~SerialPortImpl() override
|
||||
@@ -138,6 +148,15 @@
|
||||
t.c_cc[VMIN] = 1;
|
||||
cfsetspeed(&t, 9600);
|
||||
tcsetattr(_fd, TCSANOW, &t);
|
||||
|
||||
/* Toggle DTR to reset the device. */
|
||||
|
||||
int flag = TIOCM_DTR;
|
||||
if (ioctl(_fd, TIOCMBIC, &flag) == -1)
|
||||
Error() << fmt::format("cannot clear DTR on serial port: {}", strerror(errno));
|
||||
usleep(200000);
|
||||
if (ioctl(_fd, TIOCMBIS, &flag) == -1)
|
||||
Error() << fmt::format("cannot set DTR on serial port: {}", strerror(errno));
|
||||
}
|
||||
|
||||
~SerialPortImpl() override
|
||||
|
||||
115
lib/usb/usb.cc
115
lib/usb/usb.cc
@@ -13,70 +13,87 @@
|
||||
|
||||
static USB* usb = NULL;
|
||||
|
||||
USB::~USB()
|
||||
{}
|
||||
USB::~USB() {}
|
||||
|
||||
static std::unique_ptr<CandidateDevice> selectDevice()
|
||||
{
|
||||
auto candidates = findUsbDevices({ FLUXENGINE_ID, GREASEWEAZLE_ID });
|
||||
if (candidates.size() == 0)
|
||||
Error() << "no devices found (is one plugged in? Do you have the appropriate "
|
||||
"permissions?";
|
||||
auto candidates = findUsbDevices({FLUXENGINE_ID, GREASEWEAZLE_ID});
|
||||
if (candidates.size() == 0)
|
||||
Error() << "no devices found (is one plugged in? Do you have the "
|
||||
"appropriate permissions?";
|
||||
|
||||
if (config.usb().has_serial())
|
||||
{
|
||||
auto wantedSerial = config.usb().serial();
|
||||
for (auto& c : candidates)
|
||||
{
|
||||
if (c->serial == wantedSerial)
|
||||
return std::move(c);
|
||||
}
|
||||
Error() << "serial number not found (try without one to list or autodetect devices)";
|
||||
}
|
||||
if (config.usb().has_serial())
|
||||
{
|
||||
auto wantedSerial = config.usb().serial();
|
||||
for (auto& c : candidates)
|
||||
{
|
||||
if (c->serial == wantedSerial)
|
||||
return std::move(c);
|
||||
}
|
||||
Error() << "serial number not found (try without one to list or "
|
||||
"autodetect devices)";
|
||||
}
|
||||
|
||||
if (candidates.size() == 1)
|
||||
return std::move(candidates[0]);
|
||||
if (candidates.size() == 1)
|
||||
return std::move(candidates[0]);
|
||||
|
||||
std::cerr << "More than one device detected; use --usb.serial=<serial> to select one:\n";
|
||||
for (const auto& c : candidates)
|
||||
{
|
||||
std::cerr << " ";
|
||||
switch (c->id)
|
||||
{
|
||||
case FLUXENGINE_ID:
|
||||
std::cerr << fmt::format("FluxEngine: {}\n", c->serial);
|
||||
break;
|
||||
std::cerr << "More than one device detected; use --usb.serial=<serial> to "
|
||||
"select one:\n";
|
||||
for (const auto& c : candidates)
|
||||
{
|
||||
std::cerr << " ";
|
||||
switch (c->id)
|
||||
{
|
||||
case FLUXENGINE_ID:
|
||||
std::cerr << fmt::format("FluxEngine: {}\n", c->serial);
|
||||
break;
|
||||
|
||||
case GREASEWEAZLE_ID:
|
||||
std::cerr << fmt::format("GreaseWeazle: {} on {}\n", c->serial, c->serialPort);
|
||||
break;
|
||||
}
|
||||
}
|
||||
exit(1);
|
||||
case GREASEWEAZLE_ID:
|
||||
std::cerr << fmt::format(
|
||||
"GreaseWeazle: {} on {}\n", c->serial, c->serialPort);
|
||||
break;
|
||||
}
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
USB* get_usb_impl()
|
||||
{
|
||||
auto candidate = selectDevice();
|
||||
switch (candidate->id)
|
||||
{
|
||||
case FLUXENGINE_ID:
|
||||
std::cerr << fmt::format("Using FluxEngine {}\n", candidate->serial);
|
||||
return createFluxengineUsb(candidate->device);
|
||||
/* Special case for certain configurations. */
|
||||
|
||||
case GREASEWEAZLE_ID:
|
||||
std::cerr << fmt::format("Using GreaseWeazle {} on {}\n", candidate->serial, candidate->serialPort);
|
||||
return createGreaseWeazleUsb(candidate->serialPort, config.usb().greaseweazle());
|
||||
if (config.usb().has_greaseweazle() &&
|
||||
config.usb().greaseweazle().has_port())
|
||||
{
|
||||
const auto& conf = config.usb().greaseweazle();
|
||||
std::cerr << fmt::format(
|
||||
"Using GreaseWeazle on serial port {}\n", conf.port());
|
||||
return createGreaseWeazleUsb(conf.port(), conf);
|
||||
}
|
||||
|
||||
default:
|
||||
Error() << "internal";
|
||||
}
|
||||
/* Otherwise, select a device by USB ID. */
|
||||
|
||||
auto candidate = selectDevice();
|
||||
switch (candidate->id)
|
||||
{
|
||||
case FLUXENGINE_ID:
|
||||
std::cerr << fmt::format(
|
||||
"Using FluxEngine {}\n", candidate->serial);
|
||||
return createFluxengineUsb(candidate->device);
|
||||
|
||||
case GREASEWEAZLE_ID:
|
||||
std::cerr << fmt::format("Using GreaseWeazle {} on {}\n",
|
||||
candidate->serial,
|
||||
candidate->serialPort);
|
||||
return createGreaseWeazleUsb(
|
||||
candidate->serialPort, config.usb().greaseweazle());
|
||||
|
||||
default: Error() << "internal";
|
||||
}
|
||||
}
|
||||
|
||||
USB& getUsb()
|
||||
{
|
||||
if (!usb)
|
||||
usb = get_usb_impl();
|
||||
return *usb;
|
||||
if (!usb)
|
||||
usb = get_usb_impl();
|
||||
return *usb;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,9 @@ message GreaseWeazleProto {
|
||||
SHUGART = 2;
|
||||
};
|
||||
|
||||
optional BusType bus_type = 1
|
||||
optional string port = 1
|
||||
[(help) = "GreaseWeazle serial port to use"];
|
||||
optional BusType bus_type = 2
|
||||
[(help) = "which FDD bus type is in use", default = IBMPC];
|
||||
}
|
||||
|
||||
@@ -19,5 +21,7 @@ message UsbProto {
|
||||
[(help) = "serial number of FluxEngine or GreaseWeazle device to use"];
|
||||
}
|
||||
|
||||
optional GreaseWeazleProto greaseweazle = 2 [(help) = "GreaseWeazle-specific options"];
|
||||
oneof config {
|
||||
GreaseWeazleProto greaseweazle = 2 [(help) = "GreaseWeazle-specific options"];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user