diff --git a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -52,10 +52,18 @@ else ()
find_package(QtColorWidgets REQUIRED)
endif ()
+set(BUILD_LEDWIDGET true CACHE BOOL "Download and build LedWidget automatically.")
+if (BUILD_LEDWIDGET)
+ include(BuildLedWidget)
+else (BUILD_LEDWIDGET)
+ include(FindLedWidget)
+endif (BUILD_LEDWIDGET)
+
# includes
include_directories("./src"
${QWT_INCLUDE_DIR}
${QTCOLORWIDGETS_INCLUDE_DIRS}
+ ${LEDWIDGET_INCLUDE_DIR}
)
# flags
@@ -139,6 +147,7 @@ add_executable(${PROGRAM_NAME} WIN32
target_link_libraries(${PROGRAM_NAME}
${QWT_LIBRARY}
${QTCOLORWIDGETS_LIBRARIES}
+ ${LEDWIDGET_LIBRARY}
)
qt5_use_modules(${PROGRAM_NAME} Widgets SerialPort Network)
@@ -150,6 +159,11 @@ if (BUILD_QTCOLORWIDGETS)
add_dependencies(${PROGRAM_NAME} QCW)
endif ()
+if (BUILD_LEDWIDGET)
+ add_dependencies(${PROGRAM_NAME} LEDW)
+endif (BUILD_LEDWIDGET)
+
+
# set compiler flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
diff --git a/cmake/modules/BuildLedWidget.cmake b/cmake/modules/BuildLedWidget.cmake
new file mode 100644
--- /dev/null
+++ b/cmake/modules/BuildLedWidget.cmake
@@ -0,0 +1,30 @@
+#
+# Copyright © 2017 Hasan Yavuz Özderya
+#
+# This file is part of serialplot.
+#
+# serialplot is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# serialplot is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with serialplot. If not, see .
+#
+
+include(ExternalProject)
+
+ExternalProject_Add(LEDW
+ PREFIX ledw
+ HG_REPOSITORY https://bitbucket.org/hyOzd/ledwidget
+ UPDATE_COMMAND ""
+ INSTALL_COMMAND "")
+
+ExternalProject_Get_Property(LEDW binary_dir source_dir)
+set(LEDWIDGET_INCLUDE_DIR ${source_dir}/src)
+set(LEDWIDGET_LIBRARY ${binary_dir}/libledwidget.a)
diff --git a/cmake/modules/FindLedWidget.cmake b/cmake/modules/FindLedWidget.cmake
new file mode 100644
--- /dev/null
+++ b/cmake/modules/FindLedWidget.cmake
@@ -0,0 +1,25 @@
+#
+# Copyright © 2017 Hasan Yavuz Özderya
+#
+# This file is part of serialplot.
+#
+# serialplot is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# serialplot is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with serialplot. If not, see .
+#
+
+find_library(LEDWIDGET_LIBRARY "ledwidget")
+find_path(LEDWIDGET_INCLUDE_DIR "ledwidget.h" PATH_SUFFIXES "ledwidget")
+
+mark_as_advanced(LEDWIDGET_LIBRARY LEDWIDGET_INCLUDE_DIR)
+
+find_package_handle_standard_args(LedWidget DEFAULT_MSG LEDWIDGET_LIBRARY LEDWIDGET_INCLUDE_DIR)
diff --git a/src/portcontrol.cpp b/src/portcontrol.cpp
--- a/src/portcontrol.cpp
+++ b/src/portcontrol.cpp
@@ -1,5 +1,5 @@
/*
- Copyright © 2016 Hasan Yavuz Özderya
+ Copyright © 2017 Hasan Yavuz Özderya
This file is part of serialplot.
@@ -130,6 +130,40 @@ PortControl::PortControl(QSerialPort* po
SELECT::OVERLOAD_OF(&QButtonGroup::buttonClicked),
this, &PortControl::selectFlowControl);
+ // initialize signal leds
+ ui->ledDTR->setOn(true);
+ ui->ledRTS->setOn(true);
+
+ // connect output signals
+ connect(ui->pbDTR, &QPushButton::clicked, [this]()
+ {
+ // toggle DTR
+ ui->ledDTR->toggle();
+ if (serialPort->isOpen())
+ {
+ serialPort->setDataTerminalReady(ui->ledDTR->isOn());
+ }
+ });
+
+ connect(ui->pbRTS, &QPushButton::clicked, [this]()
+ {
+ // toggle RTS
+ ui->ledRTS->toggle();
+ if (serialPort->isOpen())
+ {
+ serialPort->setRequestToSend(ui->ledRTS->isOn());
+ }
+ });
+
+ // setup pin update leds
+ ui->ledDCD->setColor(Qt::yellow);
+ ui->ledDSR->setColor(Qt::yellow);
+ ui->ledRI->setColor(Qt::yellow);
+ ui->ledCTS->setColor(Qt::yellow);
+
+ pinUpdateTimer.setInterval(1000); // ms
+ connect(&pinUpdateTimer, &QTimer::timeout, this, &PortControl::updatePinLeds);
+
loadPortList();
loadBaudRateList();
ui->cbBaudRate->setCurrentIndex(ui->cbBaudRate->findText("9600"));
@@ -221,6 +255,7 @@ void PortControl::togglePort()
{
if (serialPort->isOpen())
{
+ pinUpdateTimer.stop();
serialPort->close();
qDebug() << "Closed port:" << serialPort->portName();
emit portToggled(false);
@@ -258,6 +293,14 @@ void PortControl::togglePort()
selectStopBits((QSerialPort::StopBits) stopBitsButtons.checkedId());
selectFlowControl((QSerialPort::FlowControl) flowControlButtons.checkedId());
+ // set output signals
+ serialPort->setDataTerminalReady(ui->ledDTR->isOn());
+ serialPort->setRequestToSend(ui->ledRTS->isOn());
+
+ // update pin signals
+ updatePinLeds();
+ pinUpdateTimer.start();
+
qDebug() << "Opened port:" << serialPort->portName();
emit portToggled(true);
}
@@ -319,6 +362,15 @@ void PortControl::onTbPortListActivated(
ui->cbPortList->setCurrentIndex(index);
}
+void PortControl::updatePinLeds(void)
+{
+ auto pins = serialPort->pinoutSignals();
+ ui->ledDCD->setOn(pins & QSerialPort::DataCarrierDetectSignal);
+ ui->ledDSR->setOn(pins & QSerialPort::DataSetReadySignal);
+ ui->ledRI->setOn(pins & QSerialPort::RingIndicatorSignal);
+ ui->ledCTS->setOn(pins & QSerialPort::ClearToSendSignal);
+}
+
QString PortControl::currentParityText()
{
return paritySettingMap.value(
diff --git a/src/portcontrol.h b/src/portcontrol.h
--- a/src/portcontrol.h
+++ b/src/portcontrol.h
@@ -1,5 +1,5 @@
/*
- Copyright © 2016 Hasan Yavuz Özderya
+ Copyright © 2017 Hasan Yavuz Özderya
This file is part of serialplot.
@@ -28,6 +28,7 @@
#include
#include
#include
+#include
#include "portlist.h"
@@ -65,6 +66,9 @@ private:
QComboBox tbPortList;
PortList portList;
+ /// Used to refresh pinout signal leds periodically
+ QTimer pinUpdateTimer;
+
/// Returns the currently selected (entered) "portName" in the UI
QString selectedPortName();
/// Returns currently selected parity as text to be saved in settings
@@ -86,9 +90,9 @@ public slots:
private slots:
void openActionTriggered(bool checked);
-
void onCbPortListActivated(int index);
void onTbPortListActivated(int index);
+ void updatePinLeds(void);
signals:
void portToggled(bool open);
diff --git a/src/portcontrol.ui b/src/portcontrol.ui
--- a/src/portcontrol.ui
+++ b/src/portcontrol.ui
@@ -301,6 +301,224 @@
-
+
+
+ 2
+
+
-
+
+
+
+ 15
+ 15
+
+
+
+
+ 15
+ 15
+
+
+
+ Request To Send
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+
+ 40
+ 20
+
+
+
+ Data Terminal Ready
+
+
+ DTR
+
+
+
+ -
+
+
+
+ 15
+ 15
+
+
+
+
+ 15
+ 15
+
+
+
+ Data Terminal Ready
+
+
+
+ -
+
+
+
+ 15
+ 15
+
+
+
+
+ 15
+ 15
+
+
+
+ Data Set Ready
+
+
+
+ -
+
+
+ Data Set Ready
+
+
+ DSR
+
+
+ Qt::AlignCenter
+
+
+
+ -
+
+
+
+ 40
+ 20
+
+
+
+ Request To Send
+
+
+ RTS
+
+
+
+ -
+
+
+ Data Carrier Detect
+
+
+ DCD
+
+
+ Qt::AlignCenter
+
+
+
+ -
+
+
+
+ 15
+ 15
+
+
+
+
+ 15
+ 15
+
+
+
+ Data Carrier Detect
+
+
+
+ -
+
+
+ Ring Indicator
+
+
+ RI
+
+
+ Qt::AlignCenter
+
+
+
+ -
+
+
+
+ 15
+ 15
+
+
+
+
+ 15
+ 15
+
+
+
+ Ring Indicator
+
+
+
+ -
+
+
+
+ 15
+ 15
+
+
+
+
+ 15
+ 15
+
+
+
+ Clear To Send
+
+
+
+ -
+
+
+ Clear To Send
+
+
+ CTS
+
+
+ Qt::AlignCenter
+
+
+
+
+
+ -
Qt::Vertical
@@ -308,7 +526,7 @@
20
- 40
+ 1
@@ -317,6 +535,14 @@
+
+
+ LedWidget
+ QWidget
+
+ 1
+
+
cbPortList
pbReloadPorts