-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuartinterface.cpp
More file actions
64 lines (47 loc) · 1.47 KB
/
uartinterface.cpp
File metadata and controls
64 lines (47 loc) · 1.47 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "uartinterface.h"
UARTInterface::UARTInterface()
{
connected = false;
serialPort.setPortName("COM5");
serialPort.setBaudRate(QSerialPort::Baud19200);
serialPort.setDataBits(QSerialPort::Data8);
serialPort.setParity(QSerialPort::NoParity);
serialPort.setStopBits(QSerialPort::OneStop);
serialPort.setFlowControl(QSerialPort::NoFlowControl);
if(serialPort.open(QSerialPort::ReadWrite))
{
connected = true;
}
}
UARTInterface::~UARTInterface()
{
serialPort.close();
}
void UARTInterface::updateObserver(QRectF minMaxAngles, QPointF angles, LaserMode laserMode, std::vector<QPointF> calibrationAngles)
{
if(connected == false)
{
return;
}
//Invert the angles
angles = -angles;
//Send the correct values over the UART Interface
unsigned int x = 1000 + ((angles.x()-minMaxAngles.left())/(minMaxAngles.width())*1000.0f);
unsigned int y = 1000 + ((angles.y()-minMaxAngles.top())/(minMaxAngles.height())*1000.0f);
char msg[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
msg[0] = y >> 8;
msg[1] = y & 0xFF;
msg[2] = x >> 8;
msg[3] = x & 0xFF;
if(laserMode == LASER_ON)
msg[4] = 0x01;
else if(laserMode == LASER_OFF)
msg[4] = 0x02;
int sendCount = serialPort.write(msg, 5);
if(sendCount != 5)
{
QMessageBox messageBox;
messageBox.critical(0,"Error","Data was not completely send!");
messageBox.setFixedSize(500,200);
}
}