mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Serial-Devices - Add udev support (#1246)
This commit is contained in:
parent
9199aa8216
commit
4c2806f966
@ -46,7 +46,7 @@ function createLedPreview(leds, origin) {
|
|||||||
canvas_width = $('#leds_preview').innerWidth();
|
canvas_width = $('#leds_preview').innerWidth();
|
||||||
|
|
||||||
imageCanvasNodeCtx = document.getElementById("image_preview").getContext("2d");
|
imageCanvasNodeCtx = document.getElementById("image_preview").getContext("2d");
|
||||||
$('#image_preview').css({"width":canvas_width, "height":canvas_height});
|
$('#image_preview').css({ "width": canvas_width, "height": canvas_height });
|
||||||
|
|
||||||
var leds_html = "";
|
var leds_html = "";
|
||||||
for (var idx = 0; idx < leds.length; idx++) {
|
for (var idx = 0; idx < leds.length; idx++) {
|
||||||
@ -421,8 +421,8 @@ $(document).ready(function () {
|
|||||||
// translate
|
// translate
|
||||||
performTranslation();
|
performTranslation();
|
||||||
|
|
||||||
// update instance listing
|
// update instance listing
|
||||||
updateHyperionInstanceListing();
|
updateHyperionInstanceListing();
|
||||||
|
|
||||||
//add intros
|
//add intros
|
||||||
if (window.showOptHelp) {
|
if (window.showOptHelp) {
|
||||||
@ -561,30 +561,28 @@ $(document).ready(function () {
|
|||||||
toggleClass('#leds_prev_toggle_num', "btn-danger", "btn-success");
|
toggleClass('#leds_prev_toggle_num', "btn-danger", "btn-success");
|
||||||
});
|
});
|
||||||
|
|
||||||
// toggle live video
|
// toggle live video
|
||||||
$('#leds_prev_toggle_live_video').off().on("click", function() {
|
$('#leds_prev_toggle_live_video').off().on("click", function () {
|
||||||
setClassByBool('#leds_prev_toggle_live_video', window.imageStreamActive, "btn-success", "btn-danger");
|
setClassByBool('#leds_prev_toggle_live_video', window.imageStreamActive, "btn-success", "btn-danger");
|
||||||
if (window.imageStreamActive)
|
if (window.imageStreamActive) {
|
||||||
{
|
requestLedImageStop();
|
||||||
requestLedImageStop();
|
|
||||||
imageCanvasNodeCtx.clear();
|
imageCanvasNodeCtx.clear();
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
requestLedImageStart();
|
||||||
requestLedImageStart();
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
$(window.hyperion).on("cmd-ledcolors-imagestream-update",function(event){
|
$(window.hyperion).on("cmd-ledcolors-imagestream-update", function (event) {
|
||||||
setClassByBool('#leds_prev_toggle_live_video', window.imageStreamActive, "btn-danger", "btn-success");
|
setClassByBool('#leds_prev_toggle_live_video', window.imageStreamActive, "btn-danger", "btn-success");
|
||||||
var imageData = (event.response.result.image);
|
var imageData = (event.response.result.image);
|
||||||
|
|
||||||
var image = new Image();
|
var image = new Image();
|
||||||
image.onload = function() {
|
image.onload = function () {
|
||||||
imageCanvasNodeCtx.drawImage(image, 0, 0, imageCanvasNodeCtx.canvas.width, imageCanvasNodeCtx.canvas.height);
|
imageCanvasNodeCtx.drawImage(image, 0, 0, imageCanvasNodeCtx.canvas.width, imageCanvasNodeCtx.canvas.height);
|
||||||
};
|
};
|
||||||
image.src = imageData;
|
image.src = imageData;
|
||||||
});
|
});
|
||||||
|
|
||||||
// open checklist
|
// open checklist
|
||||||
$('#leds_prev_checklist').off().on("click", function () {
|
$('#leds_prev_checklist').off().on("click", function () {
|
||||||
@ -1366,7 +1364,11 @@ var updateSelectList = function (ledType, discoveryInfo) {
|
|||||||
case "sedu":
|
case "sedu":
|
||||||
case "tpm2":
|
case "tpm2":
|
||||||
for (const device of discoveryInfo.devices) {
|
for (const device of discoveryInfo.devices) {
|
||||||
enumVals.push(device.portName);
|
if (device.udev) {
|
||||||
|
enumVals.push(device.systemLocation);
|
||||||
|
} else {
|
||||||
|
enumVals.push(device.portName);
|
||||||
|
}
|
||||||
enumTitelVals.push(device.portName + " (" + device.vendorIdentifier + "|" + device.productIdentifier + ") - " + device.manufacturer);
|
enumTitelVals.push(device.portName + " (" + device.vendorIdentifier + "|" + device.productIdentifier + ") - " + device.manufacturer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1557,3 +1559,4 @@ function showAllDeviceInputOptions(showForKey, state) {
|
|||||||
showInputOptionsForKey(conf_editor, "generalOptions", showForKey, state);
|
showInputOptionsForKey(conf_editor, "generalOptions", showForKey, state);
|
||||||
showInputOptionsForKey(conf_editor, "specificOptions", showForKey, state);
|
showInputOptionsForKey(conf_editor, "specificOptions", showForKey, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
// qt includes
|
// qt includes
|
||||||
#include <QSerialPortInfo>
|
#include <QSerialPortInfo>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
@ -20,6 +21,10 @@ namespace {
|
|||||||
const int NUM_POWEROFF_WRITE_BLACK = 2; // Number of write "BLACK" during powering off
|
const int NUM_POWEROFF_WRITE_BLACK = 2; // Number of write "BLACK" during powering off
|
||||||
|
|
||||||
constexpr std::chrono::milliseconds DEFAULT_IDENTIFY_TIME{ 500 };
|
constexpr std::chrono::milliseconds DEFAULT_IDENTIFY_TIME{ 500 };
|
||||||
|
|
||||||
|
// tty discovery service
|
||||||
|
const char DISCOVERY_DIRECTORY[] = "/dev/";
|
||||||
|
const char DISCOVERY_FILEPATTERN[] = "tty*";
|
||||||
} //End of constants
|
} //End of constants
|
||||||
|
|
||||||
ProviderRs232::ProviderRs232(const QJsonObject &deviceConfig)
|
ProviderRs232::ProviderRs232(const QJsonObject &deviceConfig)
|
||||||
@ -47,18 +52,26 @@ bool ProviderRs232::init(const QJsonObject &deviceConfig)
|
|||||||
Debug(_log, "LatchTime : %d", this->getLatchTime());
|
Debug(_log, "LatchTime : %d", this->getLatchTime());
|
||||||
|
|
||||||
_deviceName = deviceConfig["output"].toString("auto");
|
_deviceName = deviceConfig["output"].toString("auto");
|
||||||
|
_isAutoDeviceName = _deviceName.toLower() == "auto";
|
||||||
|
|
||||||
// If device name was given as unix /dev/ system-location, get port name
|
// If device name was given as unix /dev/ system-location, get port name
|
||||||
if ( _deviceName.startsWith(QLatin1String("/dev/")) )
|
if ( _deviceName.startsWith(QLatin1String("/dev/")) )
|
||||||
{
|
{
|
||||||
|
_location = _deviceName;
|
||||||
|
//Handle udev devices
|
||||||
|
QFileInfo file_info(_deviceName);
|
||||||
|
if (file_info.isSymLink())
|
||||||
|
{
|
||||||
|
_deviceName = file_info.symLinkTarget();
|
||||||
|
}
|
||||||
_deviceName = _deviceName.mid(5);
|
_deviceName = _deviceName.mid(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
_isAutoDeviceName = _deviceName.toLower() == "auto";
|
|
||||||
_baudRate_Hz = deviceConfig["rate"].toInt();
|
_baudRate_Hz = deviceConfig["rate"].toInt();
|
||||||
_delayAfterConnect_ms = deviceConfig["delayAfterConnect"].toInt(1500);
|
_delayAfterConnect_ms = deviceConfig["delayAfterConnect"].toInt(1500);
|
||||||
|
|
||||||
Debug(_log, "deviceName : %s", QSTRING_CSTR(_deviceName));
|
Debug(_log, "DeviceName : %s", QSTRING_CSTR(_deviceName));
|
||||||
|
DebugIf(!_location.isEmpty(), _log, "Location : %s", QSTRING_CSTR(_location));
|
||||||
Debug(_log, "AutoDevice : %d", _isAutoDeviceName);
|
Debug(_log, "AutoDevice : %d", _isAutoDeviceName);
|
||||||
Debug(_log, "baudRate_Hz : %d", _baudRate_Hz);
|
Debug(_log, "baudRate_Hz : %d", _baudRate_Hz);
|
||||||
Debug(_log, "delayAfCon ms: %d", _delayAfterConnect_ms);
|
Debug(_log, "delayAfCon ms: %d", _delayAfterConnect_ms);
|
||||||
@ -141,7 +154,14 @@ bool ProviderRs232::tryOpen(int delayAfterConnect_ms)
|
|||||||
|
|
||||||
if (!_rs232Port.isOpen())
|
if (!_rs232Port.isOpen())
|
||||||
{
|
{
|
||||||
Info(_log, "Opening UART: %s", QSTRING_CSTR(_deviceName));
|
if (!_location.isEmpty())
|
||||||
|
{
|
||||||
|
Info(_log, "Opening UART: %s (%s)", QSTRING_CSTR(_deviceName), QSTRING_CSTR(_location));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Info(_log, "Opening UART: %s", QSTRING_CSTR(_deviceName));
|
||||||
|
}
|
||||||
|
|
||||||
_frameDropCounter = 0;
|
_frameDropCounter = 0;
|
||||||
|
|
||||||
@ -168,7 +188,7 @@ bool ProviderRs232::tryOpen(int delayAfterConnect_ms)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QString errortext = QString("Invalid serial device name: [%1]!").arg(_deviceName);
|
QString errortext = QString("Invalid serial device name: %1 %2!").arg(_deviceName, _location);
|
||||||
this->setInError( errortext );
|
this->setInError( errortext );
|
||||||
|
|
||||||
// List available device
|
// List available device
|
||||||
@ -300,6 +320,37 @@ QJsonObject ProviderRs232::discover(const QJsonObject& /*params*/)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
//Check all /dev/tty* files, if they are udev-serial devices
|
||||||
|
QDir deviceDirectory (DISCOVERY_DIRECTORY);
|
||||||
|
QStringList deviceFilter(DISCOVERY_FILEPATTERN);
|
||||||
|
deviceDirectory.setNameFilters(deviceFilter);
|
||||||
|
deviceDirectory.setSorting(QDir::Name);
|
||||||
|
QFileInfoList deviceFiles = deviceDirectory.entryInfoList(QDir::AllEntries);
|
||||||
|
|
||||||
|
QFileInfoList::const_iterator deviceFileIterator;
|
||||||
|
for (deviceFileIterator = deviceFiles.constBegin(); deviceFileIterator != deviceFiles.constEnd(); ++deviceFileIterator)
|
||||||
|
{
|
||||||
|
if ((*deviceFileIterator).isSymLink())
|
||||||
|
{
|
||||||
|
QSerialPortInfo port = QSerialPortInfo(QSerialPort((*deviceFileIterator).symLinkTarget()));
|
||||||
|
|
||||||
|
QJsonObject portInfo;
|
||||||
|
portInfo.insert("portName", (*deviceFileIterator).fileName());
|
||||||
|
portInfo.insert("systemLocation", (*deviceFileIterator).absoluteFilePath());
|
||||||
|
portInfo.insert("udev", true);
|
||||||
|
|
||||||
|
portInfo.insert("description", port.description());
|
||||||
|
portInfo.insert("manufacturer", port.manufacturer());
|
||||||
|
portInfo.insert("productIdentifier", QString("0x%1").arg(port.productIdentifier(), 0, 16));
|
||||||
|
portInfo.insert("serialNumber", port.serialNumber());
|
||||||
|
portInfo.insert("vendorIdentifier", QString("0x%1").arg(port.vendorIdentifier(), 0, 16));
|
||||||
|
|
||||||
|
deviceList.append(portInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
devicesDiscovered.insert("devices", deviceList);
|
devicesDiscovered.insert("devices", deviceList);
|
||||||
DebugIf(verbose,_log, "devicesDiscovered: [%s]", QString(QJsonDocument(devicesDiscovered).toJson(QJsonDocument::Compact)).toUtf8().constData());
|
DebugIf(verbose,_log, "devicesDiscovered: [%s]", QString(QJsonDocument(devicesDiscovered).toJson(QJsonDocument::Compact)).toUtf8().constData());
|
||||||
|
|
||||||
|
@ -97,6 +97,8 @@ protected:
|
|||||||
|
|
||||||
/// The name of the output device
|
/// The name of the output device
|
||||||
QString _deviceName;
|
QString _deviceName;
|
||||||
|
/// The system location of the output device
|
||||||
|
QString _location;
|
||||||
/// The RS232 serial-device
|
/// The RS232 serial-device
|
||||||
QSerialPort _rs232Port;
|
QSerialPort _rs232Port;
|
||||||
/// The used baud-rate of the output device
|
/// The used baud-rate of the output device
|
||||||
|
Loading…
x
Reference in New Issue
Block a user