Loading...
Searching...
No Matches
SerialWidget.hpp
1#pragma once
2#include <Device/Protocol/ProtocolSettingsWidget.hpp>
3
4#include <ossia/protocols/osc/osc_factory.hpp>
5
6#include <QComboBox>
7#include <QFormLayout>
8#include <QLineEdit>
9#include <QSpinBox>
10namespace Protocols
11{
12
13using framing_type = decltype(ossia::net::osc_protocol_configuration::framing);
14class SerialWidget : public QWidget
15{
16public:
17 SerialWidget(Device::ProtocolSettingsWidget& proto, QWidget* parent)
18 : QWidget{parent}
19 {
20 auto layout = new QFormLayout{this};
21 layout->setContentsMargins(0, 0, 0, 0);
22
23 m_baudRate = new QSpinBox(this);
24 m_baudRate->setRange(0, 115200);
25 m_baudRate->setValue(9600);
26
27 m_host = new QLineEdit(this);
28 m_host->setText("/dev/ttyUSB0");
29
30 m_framing = new QComboBox{this};
31 m_framing->addItems({"Size prefixing", "SLIP"});
32 m_framing->setCurrentIndex(1);
33
34 layout->addRow(tr("Host"), m_host);
35 layout->addRow(tr("Baud rate"), m_baudRate);
36 layout->addRow(tr("Framing"), m_framing);
37 }
38
39 framing_type framing() const noexcept
40 {
41 return (framing_type)m_framing->currentIndex();
42 }
43
44 ossia::net::serial_configuration settings() const noexcept
45 {
46 ossia::net::serial_configuration conf;
47 conf.port = m_host->text().toStdString();
48 conf.baud_rate = m_baudRate->value();
49 return conf;
50 }
51
52 void setSettings(
53 const ossia::net::osc_protocol_configuration& c,
54 const ossia::net::serial_configuration& conf)
55 {
56 m_framing->setCurrentIndex(c.framing);
57 m_host->setText(QString::fromStdString(conf.port));
58 m_baudRate->setValue(conf.baud_rate);
59 }
60
61private:
62 QLineEdit* m_host{};
63 QSpinBox* m_baudRate{};
64 QComboBox* m_framing{};
65};
66
67}
Definition ProtocolSettingsWidget.hpp:22
Definition SerialWidget.hpp:15