-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollimatorsset.cpp
More file actions
95 lines (79 loc) · 2.2 KB
/
collimatorsset.cpp
File metadata and controls
95 lines (79 loc) · 2.2 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "collimatorsset.h"
#include <QDebug>
const int N_motors = 4;
CollimatorsSet::CollimatorsSet(int setID, QObject *parent) :
QObject(parent)
{
id = setID;
motors = new Encoder*[N_motors];
for (int i = 0; i < N_motors; ++i) {
motors[i] = new Encoder(i);
connect(motors[i], SIGNAL(MotorCoordinateUpdated(int, uint16_t)), this, SLOT(MotorCoordinateChangedSlot(int,uint16_t )));
}
}
CollimatorsSet::~CollimatorsSet()
{
for (int i = 0; i < N_motors; ++i) {
delete motors[i];
}
delete [] motors;
}
int CollimatorsSet::GetID()
{
return id;
}
void CollimatorsSet::MotorCoordinateChangedSlot(int motorID, uint16_t newCoordinate)
{
emit MotorCoordinateChanged(GetID(), motorID, newCoordinate);
}
uint16_t CollimatorsSet::GetMotorOrigin(int motorID)
{
return motors[motorID]->GetOrigin();
}
int CollimatorsSet::GetPosition(int motorID)
{
return motors[motorID]->GetPosition();
}
uint8_t CollimatorsSet::GetSteps2mm(int motorID)
{
return motors[motorID]->GetSteps2mm();
}
void CollimatorsSet::ResetMotorsData()
{
for (int i = 0; i < N_motors; ++i) {
motors[i]->ResetSteps2mm();
}
}
void CollimatorsSet::ResetSteps2mm(int motorID)
{
motors[motorID]->ResetSteps2mm();
}
void CollimatorsSet::Update(QByteArray response)
{
QString motorIdIndicator = "motor_id=";
QString coordIndicator = "coord=";
uint8_t motorID;
uint16_t coord;
int p1 = response.indexOf(motorIdIndicator);
if (p1 != -1) {
motorID = uint8_t(response.at(p1 + motorIdIndicator.length())) - 1;
if (motorID > N_motors) return;
} else return;
p1 = response.indexOf(coordIndicator);
if (p1 != -1) {
coord = (uint8_t(response.at(p1 + coordIndicator.length())))<<8 |
(uint8_t(response.at(p1 + coordIndicator.length() + 1)));
} else return;
if (response.contains("reset")) {
motors[motorID]->UpdateOrigin(coord);
} else {
motors[motorID]->UpdateCoordinate(coord);
}
}
void CollimatorsSet::UpdateAllOrigins(QByteArray response)
{
// for (int i = 0; i < N_motors; ++i) {
// motors[i]->UpdateOrigin(response.mid(2*i, 2));
// qDebug() << motors[i]->GetOrigin();
// }
}