-
Notifications
You must be signed in to change notification settings - Fork 23
/
formgps_sections.cpp
168 lines (148 loc) · 5.3 KB
/
formgps_sections.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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include "formgps.h"
#include "qmlutil.h"
#include "common.h"
#include "cpgn.h"
/* SectionSetPosition(), SectionCalcWidths(), and SectionCalcMulti() are all in CTool */
void FormGPS::BuildMachineByte()
{
if (tool.isSectionsNotZones)
{
p_254.pgn[p_254.sc1to8] = 0;
p_254.pgn[p_254.sc9to16] = 0;
int number = 0;
for (int j = 0; j < 8; j++)
{
if (tool.section[j].isSectionOn)
number |= 1 << j;
}
p_254.pgn[p_254.sc1to8] = (char)number;
number = 0;
for (int j = 8; j < 16; j++)
{
if (tool.section[j].isSectionOn)
number |= 1 << (j-8);
}
p_254.pgn[p_254.sc9to16] = (char)number;
//machine pgn
p_239.pgn[p_239.sc9to16] = p_254.pgn[p_254.sc9to16];
p_239.pgn[p_239.sc1to8] = p_254.pgn[p_254.sc1to8];
}
else
{
//zero all the bytes - set only if on
for (int i = 5; i < 13; i++)
{
p_229.pgn[i] = 0;
}
int number = 0;
for (int k = 0; k < 8; k++)
{
for (int j = 0; j < 8; j++)
{
if (tool.section[j + k * 8].isSectionOn)
number |= 1 << j;
}
p_229.pgn[5 + k] = (char)number;
number = 0;
}
//tool speed to calc ramp
p_229.pgn[p_229.toolLSpeed] = (char)(tool.farLeftSpeed * 10);
p_229.pgn[p_229.toolRSpeed] = (char)(tool.farRightSpeed * 10);
}
p_239.pgn[p_239.speed] = (char)(vehicle.avgSpeed * 10);
p_239.pgn[p_239.tram] = (char)tram.controlByte;
}
void FormGPS::DoRemoteSwitches()
{
//MTZ8302 Feb 2020
if (isJobStarted)
{
//MainSW was used
if (mc.ss[mc.swMain] != mc.ssP[mc.swMain])
{
//Main SW pressed
if ((mc.ss[mc.swMain] & 1) == 1)
{
autoBtnState = btnStates::Off;
} // if Main SW ON
//if Main SW in Arduino is pressed OFF
if ((mc.ss[mc.swMain] & 2) == 2)
{
autoBtnState = btnStates::Auto;
} // if Main SW OFF
mc.ssP[mc.swMain] = mc.ss[mc.swMain];
} //Main or Rate SW
if (mc.ss[mc.swOnGr0] != 0)
{
// ON Signal from Arduino
for (int s=0; s < 8; s++){
if((mc.ss[mc.swOnGr0] & (1 << s)) && tool.numOfSections > s) {
tool.sectionButtonState.set(s,btnStates::On);
}
}
mc.ssP[mc.swOnGr0] = mc.ss[mc.swOnGr0];
} //if swONLo != 0
else { if (mc.ssP[mc.swOnGr0] != 0) { mc.ssP[mc.swOnGr0] = 0; } }
if (mc.ss[mc.swOnGr1] != 0)
{
for (int s=0; s<8; s++) {
if ((mc.ss[mc.swOnGr1] & (1 << s)) && tool.numOfSections > (s+8))
{
tool.sectionButtonState.set(s+8, btnStates::On);
}
}
mc.ssP[mc.swOnGr1] = mc.ss[mc.swOnGr1];
} //if swONHi != 0
else { if (mc.ssP[mc.swOnGr1] != 0) { mc.ssP[mc.swOnGr1] = 0; } }
// Switches have changed
if (mc.ss[mc.swOffGr0] != mc.ssP[mc.swOffGr0])
{
//if Main = Auto then change section to Auto if Off signal from Arduino stopped
if (autoBtnState == btnStates::Auto)
{
for(int s=0; s< 8; s++) {
if ((mc.ssP[mc.swOffGr0] & (1 << s)) && (mc.ss[mc.swOffGr0] & (1 << s)) && (tool.sectionButtonState.get(s) == btnStates::Off))
{
tool.sectionButtonState.set(s,btnStates::Auto);
}
}
}
mc.ssP[mc.swOffGr0] = mc.ss[mc.swOffGr0];
}
if (mc.ss[mc.swOffGr1] != mc.ssP[mc.swOffGr1])
{
//if Main = Auto then change section to Auto if Off signal from Arduino stopped
if (autoBtnState == btnStates::Auto)
{
for(int s=8; s< 16; s++) {
if ((mc.ssP[mc.swOffGr1] & (1 << s)) && (mc.ss[mc.swOffGr1] & (1 << s)) && (tool.sectionButtonState.get(s+8) == btnStates::Off))
{
tool.sectionButtonState.set(s+8,btnStates::Auto);
}
}
}
mc.ssP[mc.swOffGr1] = mc.ss[mc.swOffGr1];
}
// OFF Signal from Arduino
if (mc.ss[mc.swOffGr0] != 0)
{
//if section SW in Arduino is switched to OFF; check always, if switch is locked to off GUI should not change
for(int s=0; s< 8; s++) {
if ((mc.ss[mc.swOffGr0] & (1 << s)) && tool.sectionButtonState.get(s) != btnStates::Off)
{
tool.sectionButtonState.set(s,btnStates::Off);
}
}
} // if swOFFLo !=0
if (mc.ss[mc.swOffGr1] != 0)
{
//if section SW in Arduino is switched to OFF; check always, if switch is locked to off GUI should not change
for (int s=0; s<8; s++) {
if ((mc.ss[mc.swOffGr0] & (1 << s)) && tool.sectionButtonState.get(s+8) != btnStates::Off)
{
tool.sectionButtonState.set(s,btnStates::Off);
}
}
} // if swOFFHi !=0
}//if serial or udp port open
}