Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
307 | KeyOz | 1 | /*************************************************************************** |
2 | * Copyright (C) 2009 by Manuel Schrape * |
||
3 | * manuel.schrape@gmx.de * |
||
4 | * * |
||
5 | * This program is free software; you can redistribute it and/or modify * |
||
6 | * it under the terms of the GNU General Public License as published by * |
||
7 | * the Free Software Foundation; either version 2 of the License. * |
||
8 | * * |
||
9 | * This program is distributed in the hope that it will be useful, * |
||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
12 | * GNU General Public License for more details. * |
||
13 | * * |
||
14 | * You should have received a copy of the GNU General Public License * |
||
15 | * along with this program; if not, write to the * |
||
16 | * Free Software Foundation, Inc., * |
||
17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
||
18 | ***************************************************************************/ |
||
19 | #include "dlg_MotorMixer.h" |
||
20 | |||
21 | dlg_MotorMixer::dlg_MotorMixer(QWidget *parent) : QDialog(parent) |
||
22 | { |
||
23 | setupUi(this); |
||
24 | connect(pb_READ, SIGNAL(clicked()), this, SLOT(slot_pb_READ())); |
||
25 | connect(pb_LOAD, SIGNAL(clicked()), this, SLOT(slot_pb_LOAD())); |
||
26 | connect(pb_SAVE, SIGNAL(clicked()), this, SLOT(slot_pb_SAVE())); |
||
27 | connect(pb_WRITE, SIGNAL(clicked()), this, SLOT(slot_pb_WRITE())); |
||
28 | |||
29 | connect(sb_NICK_1, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
30 | connect(sb_NICK_2, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
31 | connect(sb_NICK_3, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
32 | connect(sb_NICK_4, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
33 | connect(sb_NICK_5, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
34 | connect(sb_NICK_6, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
35 | connect(sb_NICK_7, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
36 | connect(sb_NICK_8, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
37 | connect(sb_NICK_9, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
38 | connect(sb_NICK_10, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
39 | connect(sb_NICK_11, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
40 | connect(sb_NICK_12, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
41 | |||
42 | connect(sb_ROLL_1, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
43 | connect(sb_ROLL_2, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
44 | connect(sb_ROLL_3, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
45 | connect(sb_ROLL_4, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
46 | connect(sb_ROLL_5, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
47 | connect(sb_ROLL_6, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
48 | connect(sb_ROLL_7, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
49 | connect(sb_ROLL_8, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
50 | connect(sb_ROLL_9, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
51 | connect(sb_ROLL_10, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
52 | connect(sb_ROLL_11, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
53 | connect(sb_ROLL_12, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
54 | |||
55 | connect(sb_GIER_1, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
56 | connect(sb_GIER_2, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
57 | connect(sb_GIER_3, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
58 | connect(sb_GIER_4, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
59 | connect(sb_GIER_5, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
60 | connect(sb_GIER_6, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
61 | connect(sb_GIER_7, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
62 | connect(sb_GIER_8, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
63 | connect(sb_GIER_9, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
64 | connect(sb_GIER_10, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
65 | connect(sb_GIER_11, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
66 | connect(sb_GIER_12, SIGNAL(valueChanged(int)), this, SLOT(slot_CheckValue(int))); |
||
67 | |||
68 | } |
||
69 | |||
70 | // Connection-Object übergeben. |
||
396 | Brean | 71 | void dlg_MotorMixer::set_Objects(Handler *handler, cSettings *t_Settings) |
307 | KeyOz | 72 | { |
396 | Brean | 73 | this->handler = handler; |
307 | KeyOz | 74 | o_Settings = t_Settings; |
75 | } |
||
76 | |||
77 | // Motordaten übernehmen. |
||
78 | void dlg_MotorMixer::set_MotorConfig(sRxData RX) |
||
79 | { |
||
80 | int Pos = 0; |
||
81 | |||
396 | Brean | 82 | MixerName = ToolBox::dataToQString(RX.decode, 1, 12); |
307 | KeyOz | 83 | |
84 | Pos = 13; |
||
85 | |||
86 | for (int z = 0; z < 16; z++) |
||
87 | { |
||
88 | for (int y = 0; y < 4; y++) |
||
89 | { |
||
396 | Brean | 90 | Motor[z][y] = Parser::dataToChar(RX.decode,Pos); |
307 | KeyOz | 91 | Pos++; |
92 | } |
||
93 | } |
||
94 | |||
95 | set_MotorData(); |
||
96 | } |
||
97 | |||
98 | // Motordaten aus GUI übernehmen |
||
99 | void dlg_MotorMixer::get_MotorData() |
||
100 | { |
||
101 | MixerName = le_NAME->text(); |
||
102 | |||
103 | Motor[0][0] = sb_GAS_1->value(); |
||
104 | Motor[1][0] = sb_GAS_2->value(); |
||
105 | Motor[2][0] = sb_GAS_3->value(); |
||
106 | Motor[3][0] = sb_GAS_4->value(); |
||
107 | Motor[4][0] = sb_GAS_5->value(); |
||
108 | Motor[5][0] = sb_GAS_6->value(); |
||
109 | Motor[6][0] = sb_GAS_7->value(); |
||
110 | Motor[7][0] = sb_GAS_8->value(); |
||
111 | Motor[8][0] = sb_GAS_9->value(); |
||
112 | Motor[9][0] = sb_GAS_10->value(); |
||
113 | Motor[10][0] = sb_GAS_11->value(); |
||
114 | Motor[11][0] = sb_GAS_12->value(); |
||
115 | |||
116 | Motor[0][1] = sb_NICK_1->value(); |
||
117 | Motor[1][1] = sb_NICK_2->value(); |
||
118 | Motor[2][1] = sb_NICK_3->value(); |
||
119 | Motor[3][1] = sb_NICK_4->value(); |
||
120 | Motor[4][1] = sb_NICK_5->value(); |
||
121 | Motor[5][1] = sb_NICK_6->value(); |
||
122 | Motor[6][1] = sb_NICK_7->value(); |
||
123 | Motor[7][1] = sb_NICK_8->value(); |
||
124 | Motor[8][1] = sb_NICK_9->value(); |
||
125 | Motor[9][1] = sb_NICK_10->value(); |
||
126 | Motor[10][1] = sb_NICK_11->value(); |
||
127 | Motor[11][1] = sb_NICK_12->value(); |
||
128 | |||
129 | Motor[0][2] = sb_ROLL_1->value(); |
||
130 | Motor[1][2] = sb_ROLL_2->value(); |
||
131 | Motor[2][2] = sb_ROLL_3->value(); |
||
132 | Motor[3][2] = sb_ROLL_4->value(); |
||
133 | Motor[4][2] = sb_ROLL_5->value(); |
||
134 | Motor[5][2] = sb_ROLL_6->value(); |
||
135 | Motor[6][2] = sb_ROLL_7->value(); |
||
136 | Motor[7][2] = sb_ROLL_8->value(); |
||
137 | Motor[8][2] = sb_ROLL_9->value(); |
||
138 | Motor[9][2] = sb_ROLL_10->value(); |
||
139 | Motor[10][2] = sb_ROLL_11->value(); |
||
140 | Motor[11][2] = sb_ROLL_12->value(); |
||
141 | |||
142 | Motor[0][3] = sb_GIER_1->value(); |
||
143 | Motor[1][3] = sb_GIER_2->value(); |
||
144 | Motor[2][3] = sb_GIER_3->value(); |
||
145 | Motor[3][3] = sb_GIER_4->value(); |
||
146 | Motor[4][3] = sb_GIER_5->value(); |
||
147 | Motor[5][3] = sb_GIER_6->value(); |
||
148 | Motor[6][3] = sb_GIER_7->value(); |
||
149 | Motor[7][3] = sb_GIER_8->value(); |
||
150 | Motor[8][3] = sb_GIER_9->value(); |
||
151 | Motor[9][3] = sb_GIER_10->value(); |
||
152 | Motor[10][3] = sb_GIER_11->value(); |
||
153 | Motor[11][3] = sb_GIER_12->value(); |
||
154 | } |
||
155 | |||
156 | // Motordaten anzeigen |
||
157 | void dlg_MotorMixer::set_MotorData() |
||
158 | { |
||
159 | le_NAME->setText(MixerName); |
||
160 | |||
161 | sb_GAS_1->setValue(Motor[0][0]); |
||
162 | sb_GAS_2->setValue(Motor[1][0]); |
||
163 | sb_GAS_3->setValue(Motor[2][0]); |
||
164 | sb_GAS_4->setValue(Motor[3][0]); |
||
165 | sb_GAS_5->setValue(Motor[4][0]); |
||
166 | sb_GAS_6->setValue(Motor[5][0]); |
||
167 | sb_GAS_7->setValue(Motor[6][0]); |
||
168 | sb_GAS_8->setValue(Motor[7][0]); |
||
169 | sb_GAS_9->setValue(Motor[8][0]); |
||
170 | sb_GAS_10->setValue(Motor[9][0]); |
||
171 | sb_GAS_11->setValue(Motor[10][0]); |
||
172 | sb_GAS_12->setValue(Motor[11][0]); |
||
173 | |||
174 | sb_NICK_1->setValue(Motor[0][1]); |
||
175 | sb_NICK_2->setValue(Motor[1][1]); |
||
176 | sb_NICK_3->setValue(Motor[2][1]); |
||
177 | sb_NICK_4->setValue(Motor[3][1]); |
||
178 | sb_NICK_5->setValue(Motor[4][1]); |
||
179 | sb_NICK_6->setValue(Motor[5][1]); |
||
180 | sb_NICK_7->setValue(Motor[6][1]); |
||
181 | sb_NICK_8->setValue(Motor[7][1]); |
||
182 | sb_NICK_9->setValue(Motor[8][1]); |
||
183 | sb_NICK_10->setValue(Motor[9][1]); |
||
184 | sb_NICK_11->setValue(Motor[10][1]); |
||
185 | sb_NICK_12->setValue(Motor[11][1]); |
||
186 | |||
187 | sb_ROLL_1->setValue(Motor[0][2]); |
||
188 | sb_ROLL_2->setValue(Motor[1][2]); |
||
189 | sb_ROLL_3->setValue(Motor[2][2]); |
||
190 | sb_ROLL_4->setValue(Motor[3][2]); |
||
191 | sb_ROLL_5->setValue(Motor[4][2]); |
||
192 | sb_ROLL_6->setValue(Motor[5][2]); |
||
193 | sb_ROLL_7->setValue(Motor[6][2]); |
||
194 | sb_ROLL_8->setValue(Motor[7][2]); |
||
195 | sb_ROLL_9->setValue(Motor[8][2]); |
||
196 | sb_ROLL_10->setValue(Motor[9][2]); |
||
197 | sb_ROLL_11->setValue(Motor[10][2]); |
||
198 | sb_ROLL_12->setValue(Motor[11][2]); |
||
199 | |||
200 | sb_GIER_1->setValue(Motor[0][3]); |
||
201 | sb_GIER_2->setValue(Motor[1][3]); |
||
202 | sb_GIER_3->setValue(Motor[2][3]); |
||
203 | sb_GIER_4->setValue(Motor[3][3]); |
||
204 | sb_GIER_5->setValue(Motor[4][3]); |
||
205 | sb_GIER_6->setValue(Motor[5][3]); |
||
206 | sb_GIER_7->setValue(Motor[6][3]); |
||
207 | sb_GIER_8->setValue(Motor[7][3]); |
||
208 | sb_GIER_9->setValue(Motor[8][3]); |
||
209 | sb_GIER_10->setValue(Motor[9][3]); |
||
210 | sb_GIER_11->setValue(Motor[10][3]); |
||
211 | sb_GIER_12->setValue(Motor[11][3]); |
||
212 | } |
||
213 | |||
214 | // Prüfen auf vollstaändigkeit |
||
215 | void dlg_MotorMixer::slot_CheckValue(int Wert) |
||
216 | { |
||
217 | Wert = Wert; |
||
218 | |||
219 | int NICK = sb_NICK_1->value() + sb_NICK_2->value() + sb_NICK_3->value() + sb_NICK_4->value() + sb_NICK_5->value() + sb_NICK_6->value() + |
||
220 | sb_NICK_7->value() + sb_NICK_8->value() + sb_NICK_9->value() + sb_NICK_10->value() + sb_NICK_11->value() + sb_NICK_12->value(); |
||
221 | |||
222 | int ROLL = sb_ROLL_1->value() + sb_ROLL_2->value() + sb_ROLL_3->value() + sb_ROLL_4->value() + sb_ROLL_5->value() + sb_ROLL_6->value() + |
||
223 | sb_ROLL_7->value() + sb_ROLL_8->value() + sb_ROLL_9->value() + sb_ROLL_10->value() + sb_ROLL_11->value() + sb_ROLL_12->value(); |
||
224 | |||
225 | int GIER = sb_GIER_1->value() + sb_GIER_2->value() + sb_GIER_3->value() + sb_GIER_4->value() + sb_GIER_5->value() + sb_GIER_6->value() + |
||
226 | sb_GIER_7->value() + sb_GIER_8->value() + sb_GIER_9->value() + sb_GIER_10->value() + sb_GIER_11->value() + sb_GIER_12->value(); |
||
227 | |||
228 | if (NICK == 0) |
||
229 | { |
||
230 | lb_NICK->setEnabled(true); |
||
231 | } |
||
232 | else |
||
233 | { |
||
234 | lb_NICK->setEnabled(false); |
||
235 | } |
||
236 | |||
237 | if (ROLL == 0) |
||
238 | { |
||
239 | lb_ROLL->setEnabled(true); |
||
240 | } |
||
241 | else |
||
242 | { |
||
243 | lb_ROLL->setEnabled(false); |
||
244 | } |
||
245 | |||
246 | if (GIER == 0) |
||
247 | { |
||
248 | lb_GIER->setEnabled(true); |
||
249 | } |
||
250 | else |
||
251 | { |
||
252 | lb_GIER->setEnabled(false); |
||
253 | } |
||
254 | } |
||
255 | |||
396 | Brean | 256 | //FIXME: put this in com/Handler.cpp |
257 | /* |
||
307 | KeyOz | 258 | int dlg_MotorMixer::get_MotorConfig() |
259 | { |
||
260 | get_MotorData(); |
||
261 | |||
262 | TX_Data[0] = VERSION_MIXER; |
||
263 | |||
264 | char *Name = MixerName.toLatin1().data(); |
||
265 | |||
266 | int a; |
||
267 | |||
268 | for (a = 0; a < MixerName.length(); a++) |
||
269 | { |
||
270 | TX_Data[1+a] = Name[a]; |
||
271 | } |
||
272 | |||
273 | while(a < 12) |
||
274 | { |
||
275 | TX_Data[1+a] = 0; |
||
276 | a++; |
||
277 | } |
||
278 | |||
279 | int Pos = 13; |
||
280 | |||
281 | for (int z = 0; z < 16; z++) |
||
282 | { |
||
283 | for (int y = 0; y < 4; y++) |
||
284 | { |
||
396 | Brean | 285 | TX_Data[Pos] = Parser::charToData(Motor[z][y]); |
307 | KeyOz | 286 | Pos++; |
287 | } |
||
288 | } |
||
289 | |||
290 | return Pos - 1; |
||
291 | } |
||
292 | |||
293 | void dlg_MotorMixer::read_Mixer() |
||
294 | { |
||
295 | TX_Data[0] = 0; |
||
313 | KeyOz | 296 | o_Connection->send_Cmd('n', ADDRESS_FC, TX_Data, 1, true); |
396 | Brean | 297 | }*/ |
307 | KeyOz | 298 | |
396 | Brean | 299 | // read motor values |
307 | KeyOz | 300 | void dlg_MotorMixer::slot_pb_READ() |
301 | { |
||
396 | Brean | 302 | //send command to get mixer values |
303 | handler->read_mixer(); |
||
307 | KeyOz | 304 | } |
305 | |||
396 | Brean | 306 | //write motor values |
307 | //FIXME: put this in com/Handler.cpp |
||
308 | |||
307 | KeyOz | 309 | void dlg_MotorMixer::slot_pb_WRITE() |
310 | { |
||
396 | Brean | 311 | /* int Length = get_MotorConfig(); |
312 | o_Connection->send_Cmd('m', ADDRESS_FC, TX_Data, Length, true);*/ |
||
307 | KeyOz | 313 | } |
314 | |||
315 | void dlg_MotorMixer::slot_pb_LOAD() |
||
316 | { |
||
358 | KeyOz | 317 | QString Filename = QFileDialog::getOpenFileName(this, tr("Mikrokopter MotorMixer laden"), o_Settings->DIR.Parameter + "", tr("MK MotorMixer(*.mkm);;Alle Dateien (*)")); |
307 | KeyOz | 318 | |
319 | if (!Filename.isEmpty()) |
||
320 | { |
||
321 | QSettings Setting(Filename, QSettings::IniFormat); |
||
322 | |||
323 | Setting.beginGroup("Info"); |
||
324 | MixerName = Setting.value("Name", QString("--noname--")).toString(); |
||
325 | MixerVersion = Setting.value("Version", 0).toInt(); |
||
326 | Setting.endGroup(); |
||
327 | |||
328 | Setting.beginGroup("Gas"); |
||
329 | for (int z = 0; z < MAXMOTOR; z++) |
||
330 | { |
||
331 | Motor[z][0] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt(); |
||
332 | } |
||
333 | Setting.endGroup(); |
||
334 | |||
335 | Setting.beginGroup("Nick"); |
||
336 | for (int z = 0; z < MAXMOTOR; z++) |
||
337 | { |
||
338 | Motor[z][1] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt(); |
||
339 | } |
||
340 | Setting.endGroup(); |
||
341 | |||
342 | Setting.beginGroup("Roll"); |
||
343 | for (int z = 0; z < MAXMOTOR; z++) |
||
344 | { |
||
345 | Motor[z][2] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt(); |
||
346 | } |
||
347 | Setting.endGroup(); |
||
348 | |||
349 | Setting.beginGroup("Yaw"); |
||
350 | for (int z = 0; z < MAXMOTOR; z++) |
||
351 | { |
||
352 | Motor[z][3] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt(); |
||
353 | } |
||
354 | Setting.endGroup(); |
||
355 | |||
356 | if (MixerVersion == VERSION_MIXER) |
||
357 | { |
||
358 | set_MotorData(); |
||
359 | } |
||
360 | } |
||
361 | } |
||
362 | |||
363 | void dlg_MotorMixer::slot_pb_SAVE() |
||
364 | { |
||
358 | KeyOz | 365 | QString Filename = QFileDialog::getSaveFileName(this, tr("Mikrokopter MotorMixer speichern"), o_Settings->DIR.Parameter + "/" + le_NAME->text(), tr("MK MotorMixer(*.mkm);;Alle Dateien (*)")); |
307 | KeyOz | 366 | |
367 | if (!Filename.isEmpty()) |
||
368 | { |
||
369 | if (!(Filename.endsWith(".mkm", Qt::CaseInsensitive))) |
||
370 | { |
||
371 | Filename = Filename + QString(".mkm"); |
||
372 | } |
||
373 | |||
374 | get_MotorData(); |
||
375 | |||
376 | QSettings Setting(Filename, QSettings::IniFormat); |
||
377 | |||
378 | Setting.beginGroup("Info"); |
||
379 | Setting.setValue("Name", MixerName); |
||
380 | Setting.setValue("Version", VERSION_MIXER); |
||
381 | Setting.endGroup(); |
||
382 | |||
383 | Setting.beginGroup("Gas"); |
||
384 | for (int z = 0; z < MAXMOTOR; z++) |
||
385 | { |
||
386 | Setting.setValue(QString("Motor%1").arg(z+1), Motor[z][0]); |
||
387 | } |
||
388 | Setting.endGroup(); |
||
389 | |||
390 | Setting.beginGroup("Nick"); |
||
391 | for (int z = 0; z < MAXMOTOR; z++) |
||
392 | { |
||
393 | Setting.setValue(QString("Motor%1").arg(z+1), Motor[z][1]); |
||
394 | } |
||
395 | Setting.endGroup(); |
||
396 | |||
397 | Setting.beginGroup("Roll"); |
||
398 | for (int z = 0; z < MAXMOTOR; z++) |
||
399 | { |
||
400 | Setting.setValue(QString("Motor%1").arg(z+1), Motor[z][2]); |
||
401 | } |
||
402 | Setting.endGroup(); |
||
403 | |||
404 | Setting.beginGroup("Yaw"); |
||
405 | for (int z = 0; z < MAXMOTOR; z++) |
||
406 | { |
||
407 | Setting.setValue(QString("Motor%1").arg(z+1), Motor[z][3]); |
||
408 | } |
||
409 | Setting.endGroup(); |
||
410 | } |
||
411 | } |