forked from BastianGschrey/PowerTune
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeedo.cpp
50 lines (44 loc) · 1.48 KB
/
speedo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "speedo.h"
#include "dashboard.h"
#include "connect.h"
#include <QDebug>
Speedo::Speedo(QObject *parent)
: QObject(parent)
, m_dashboard(Q_NULLPTR)
{
}
Speedo::Speedo(DashBoard *dashboard, QObject *parent)
: QObject(parent)
, m_dashboard(dashboard)
{
}
void Speedo::initSerialPort()
{
m_serialport = new SerialPort(this);
connect(this->m_serialport,SIGNAL(readyRead()),this,SLOT(readyToRead()));
// connect(m_serialport, static_cast<void (QSerialPort::*)(QSerialPort::SerialPortError)>(&QSerialPort::error),
// this, &Speedo::handleError);
// connect(m_serialport, &QSerialPort::bytesWritten, this, &Apexi::handleBytesWritten);
// connect(&m_timer, &QTimer::timeout, this, &Apexi::handleTimeout);
m_readData.clear();
qDebug() << "initialized";
}
void Speedo::openConnection(const QString &portName)
{
initSerialPort();
m_serialport->setPortName("COM16");
m_serialport->setBaudRate(QSerialPort::Baud57600);
m_serialport->setParity(QSerialPort::NoParity);
m_serialport->setDataBits(QSerialPort::Data8);
m_serialport->setStopBits(QSerialPort::OneStop);
m_serialport->setFlowControl(QSerialPort::NoFlowControl);
// m_dashboard->setSpeed(200);
qDebug() << "connected";
}
void Speedo::readyToRead()
{
qDebug() << "data available";
m_readData = m_serialport->readLine();
qDebug() << "test" << m_readData.toInt();
m_dashboard->setSpeed(m_readData.toInt());
}