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. |
||
71 | void dlg_MotorMixer::set_Objects(cConnection *t_Connection, cSettings *t_Settings) |
||
72 | { |
||
73 | o_Connection = t_Connection; |
||
74 | o_Settings = t_Settings; |
||
75 | } |
||
76 | |||
77 | // Motordaten übernehmen. |
||
78 | void dlg_MotorMixer::set_MotorConfig(sRxData RX) |
||
79 | { |
||
80 | int Pos = 0; |
||
81 | |||
82 | MixerName = ToolBox::Data2QString(RX.Decode, 1, 12); |
||
83 | |||
84 | Pos = 13; |
||
85 | |||
86 | for (int z = 0; z < 16; z++) |
||
87 | { |
||
88 | for (int y = 0; y < 4; y++) |
||
89 | { |
||
90 | Motor[z][y] = ToolBox::Data2Char(RX.Decode,Pos); |
||
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 | |||
256 | int dlg_MotorMixer::get_MotorConfig() |
||
257 | { |
||
258 | get_MotorData(); |
||
259 | |||
260 | TX_Data[0] = VERSION_MIXER; |
||
261 | |||
262 | char *Name = MixerName.toLatin1().data(); |
||
263 | |||
264 | int a; |
||
265 | |||
266 | for (a = 0; a < MixerName.length(); a++) |
||
267 | { |
||
268 | TX_Data[1+a] = Name[a]; |
||
269 | } |
||
270 | |||
271 | while(a < 12) |
||
272 | { |
||
273 | TX_Data[1+a] = 0; |
||
274 | a++; |
||
275 | } |
||
276 | |||
277 | int Pos = 13; |
||
278 | |||
279 | for (int z = 0; z < 16; z++) |
||
280 | { |
||
281 | for (int y = 0; y < 4; y++) |
||
282 | { |
||
283 | TX_Data[Pos] = ToolBox::Char2Data(Motor[z][y]); |
||
284 | Pos++; |
||
285 | } |
||
286 | } |
||
287 | |||
288 | return Pos - 1; |
||
289 | } |
||
290 | |||
291 | void dlg_MotorMixer::read_Mixer() |
||
292 | { |
||
293 | TX_Data[0] = 0; |
||
313 | KeyOz | 294 | o_Connection->send_Cmd('n', ADDRESS_FC, TX_Data, 1, true); |
307 | KeyOz | 295 | } |
296 | |||
297 | // Motordaten auslesen |
||
298 | void dlg_MotorMixer::slot_pb_READ() |
||
299 | { |
||
300 | TX_Data[0] = 0; |
||
313 | KeyOz | 301 | o_Connection->send_Cmd('n', ADDRESS_FC, TX_Data, 1, true); |
307 | KeyOz | 302 | } |
303 | |||
304 | void dlg_MotorMixer::slot_pb_WRITE() |
||
305 | { |
||
306 | int Length = get_MotorConfig(); |
||
313 | KeyOz | 307 | o_Connection->send_Cmd('m', ADDRESS_FC, TX_Data, Length, true); |
307 | KeyOz | 308 | } |
309 | |||
310 | void dlg_MotorMixer::slot_pb_LOAD() |
||
311 | { |
||
358 | KeyOz | 312 | QString Filename = QFileDialog::getOpenFileName(this, tr("Mikrokopter MotorMixer laden"), o_Settings->DIR.Parameter + "", tr("MK MotorMixer(*.mkm);;Alle Dateien (*)")); |
307 | KeyOz | 313 | |
314 | if (!Filename.isEmpty()) |
||
315 | { |
||
316 | QSettings Setting(Filename, QSettings::IniFormat); |
||
317 | |||
318 | Setting.beginGroup("Info"); |
||
319 | MixerName = Setting.value("Name", QString("--noname--")).toString(); |
||
320 | MixerVersion = Setting.value("Version", 0).toInt(); |
||
321 | Setting.endGroup(); |
||
322 | |||
323 | Setting.beginGroup("Gas"); |
||
324 | for (int z = 0; z < MAXMOTOR; z++) |
||
325 | { |
||
326 | Motor[z][0] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt(); |
||
327 | } |
||
328 | Setting.endGroup(); |
||
329 | |||
330 | Setting.beginGroup("Nick"); |
||
331 | for (int z = 0; z < MAXMOTOR; z++) |
||
332 | { |
||
333 | Motor[z][1] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt(); |
||
334 | } |
||
335 | Setting.endGroup(); |
||
336 | |||
337 | Setting.beginGroup("Roll"); |
||
338 | for (int z = 0; z < MAXMOTOR; z++) |
||
339 | { |
||
340 | Motor[z][2] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt(); |
||
341 | } |
||
342 | Setting.endGroup(); |
||
343 | |||
344 | Setting.beginGroup("Yaw"); |
||
345 | for (int z = 0; z < MAXMOTOR; z++) |
||
346 | { |
||
347 | Motor[z][3] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt(); |
||
348 | } |
||
349 | Setting.endGroup(); |
||
350 | |||
351 | if (MixerVersion == VERSION_MIXER) |
||
352 | { |
||
353 | set_MotorData(); |
||
354 | } |
||
355 | } |
||
356 | } |
||
357 | |||
358 | void dlg_MotorMixer::slot_pb_SAVE() |
||
359 | { |
||
358 | KeyOz | 360 | QString Filename = QFileDialog::getSaveFileName(this, tr("Mikrokopter MotorMixer speichern"), o_Settings->DIR.Parameter + "/" + le_NAME->text(), tr("MK MotorMixer(*.mkm);;Alle Dateien (*)")); |
307 | KeyOz | 361 | |
362 | if (!Filename.isEmpty()) |
||
363 | { |
||
364 | if (!(Filename.endsWith(".mkm", Qt::CaseInsensitive))) |
||
365 | { |
||
366 | Filename = Filename + QString(".mkm"); |
||
367 | } |
||
368 | |||
369 | get_MotorData(); |
||
370 | |||
371 | QSettings Setting(Filename, QSettings::IniFormat); |
||
372 | |||
373 | Setting.beginGroup("Info"); |
||
374 | Setting.setValue("Name", MixerName); |
||
375 | Setting.setValue("Version", VERSION_MIXER); |
||
376 | Setting.endGroup(); |
||
377 | |||
378 | Setting.beginGroup("Gas"); |
||
379 | for (int z = 0; z < MAXMOTOR; z++) |
||
380 | { |
||
381 | Setting.setValue(QString("Motor%1").arg(z+1), Motor[z][0]); |
||
382 | } |
||
383 | Setting.endGroup(); |
||
384 | |||
385 | Setting.beginGroup("Nick"); |
||
386 | for (int z = 0; z < MAXMOTOR; z++) |
||
387 | { |
||
388 | Setting.setValue(QString("Motor%1").arg(z+1), Motor[z][1]); |
||
389 | } |
||
390 | Setting.endGroup(); |
||
391 | |||
392 | Setting.beginGroup("Roll"); |
||
393 | for (int z = 0; z < MAXMOTOR; z++) |
||
394 | { |
||
395 | Setting.setValue(QString("Motor%1").arg(z+1), Motor[z][2]); |
||
396 | } |
||
397 | Setting.endGroup(); |
||
398 | |||
399 | Setting.beginGroup("Yaw"); |
||
400 | for (int z = 0; z < MAXMOTOR; z++) |
||
401 | { |
||
402 | Setting.setValue(QString("Motor%1").arg(z+1), Motor[z][3]); |
||
403 | } |
||
404 | Setting.endGroup(); |
||
405 | } |
||
406 | } |