Rev 399 | Rev 442 | Go to most recent revision | Details | Compare with Previous | 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 | { |
||
440 | Brean | 80 | //FIXME: put this in libMK/Handler.cpp and fill motor values in KopterData |
81 | /* |
||
307 | KeyOz | 82 | int Pos = 0; |
83 | |||
396 | Brean | 84 | MixerName = ToolBox::dataToQString(RX.decode, 1, 12); |
307 | KeyOz | 85 | |
86 | Pos = 13; |
||
87 | |||
88 | for (int z = 0; z < 16; z++) |
||
89 | { |
||
90 | for (int y = 0; y < 4; y++) |
||
91 | { |
||
396 | Brean | 92 | Motor[z][y] = Parser::dataToChar(RX.decode,Pos); |
307 | KeyOz | 93 | Pos++; |
94 | } |
||
95 | } |
||
96 | |||
97 | set_MotorData(); |
||
440 | Brean | 98 | */ |
307 | KeyOz | 99 | } |
100 | |||
101 | // Motordaten aus GUI übernehmen |
||
102 | void dlg_MotorMixer::get_MotorData() |
||
103 | { |
||
440 | Brean | 104 | //FIXME: add Function in handler to send data |
105 | char * mixerName = le_NAME->text().toAscii().data(); |
||
307 | KeyOz | 106 | |
440 | Brean | 107 | //TODO: use an array in Form |
108 | int motor[16][4] = { |
||
109 | sb_GAS_1->value(), sb_NICK_1->value(), sb_ROLL_1->value(), sb_GIER_1->value(), |
||
110 | sb_GAS_2->value(), sb_NICK_2->value(), sb_ROLL_2->value(), sb_GIER_2->value(), |
||
111 | sb_GAS_3->value(), sb_NICK_3->value(), sb_ROLL_3->value(), sb_GIER_3->value(), |
||
112 | sb_GAS_4->value(), sb_NICK_4->value(), sb_ROLL_4->value(), sb_GIER_4->value(), |
||
113 | sb_GAS_5->value(), sb_NICK_5->value(), sb_ROLL_5->value(), sb_GIER_5->value(), |
||
114 | sb_GAS_6->value(), sb_NICK_6->value(), sb_ROLL_6->value(), sb_GIER_6->value(), |
||
115 | sb_GAS_7->value(), sb_NICK_7->value(), sb_ROLL_7->value(), sb_GIER_7->value(), |
||
116 | sb_GAS_8->value(), sb_NICK_8->value(), sb_ROLL_8->value(), sb_GIER_8->value(), |
||
117 | sb_GAS_9->value(), sb_NICK_9->value(), sb_ROLL_9->value(), sb_GIER_9->value(), |
||
118 | sb_GAS_10->value(), sb_NICK_10->value(), sb_ROLL_10->value(), sb_GIER_10->value(), |
||
119 | sb_GAS_11->value(), sb_NICK_11->value(), sb_ROLL_11->value(), sb_GIER_11->value(), |
||
120 | sb_GAS_12->value(), sb_NICK_12->value(), sb_ROLL_12->value(), sb_GIER_12->value() |
||
121 | }; |
||
307 | KeyOz | 122 | } |
123 | |||
124 | // Motordaten anzeigen |
||
125 | void dlg_MotorMixer::set_MotorData() |
||
126 | { |
||
440 | Brean | 127 | //FIXME: create special struct for mixer - KopterData |
128 | /* |
||
307 | KeyOz | 129 | le_NAME->setText(MixerName); |
130 | |||
131 | sb_GAS_1->setValue(Motor[0][0]); |
||
132 | sb_GAS_2->setValue(Motor[1][0]); |
||
133 | sb_GAS_3->setValue(Motor[2][0]); |
||
134 | sb_GAS_4->setValue(Motor[3][0]); |
||
135 | sb_GAS_5->setValue(Motor[4][0]); |
||
136 | sb_GAS_6->setValue(Motor[5][0]); |
||
137 | sb_GAS_7->setValue(Motor[6][0]); |
||
138 | sb_GAS_8->setValue(Motor[7][0]); |
||
139 | sb_GAS_9->setValue(Motor[8][0]); |
||
140 | sb_GAS_10->setValue(Motor[9][0]); |
||
141 | sb_GAS_11->setValue(Motor[10][0]); |
||
142 | sb_GAS_12->setValue(Motor[11][0]); |
||
143 | |||
144 | sb_NICK_1->setValue(Motor[0][1]); |
||
145 | sb_NICK_2->setValue(Motor[1][1]); |
||
146 | sb_NICK_3->setValue(Motor[2][1]); |
||
147 | sb_NICK_4->setValue(Motor[3][1]); |
||
148 | sb_NICK_5->setValue(Motor[4][1]); |
||
149 | sb_NICK_6->setValue(Motor[5][1]); |
||
150 | sb_NICK_7->setValue(Motor[6][1]); |
||
151 | sb_NICK_8->setValue(Motor[7][1]); |
||
152 | sb_NICK_9->setValue(Motor[8][1]); |
||
153 | sb_NICK_10->setValue(Motor[9][1]); |
||
154 | sb_NICK_11->setValue(Motor[10][1]); |
||
155 | sb_NICK_12->setValue(Motor[11][1]); |
||
156 | |||
157 | sb_ROLL_1->setValue(Motor[0][2]); |
||
158 | sb_ROLL_2->setValue(Motor[1][2]); |
||
159 | sb_ROLL_3->setValue(Motor[2][2]); |
||
160 | sb_ROLL_4->setValue(Motor[3][2]); |
||
161 | sb_ROLL_5->setValue(Motor[4][2]); |
||
162 | sb_ROLL_6->setValue(Motor[5][2]); |
||
163 | sb_ROLL_7->setValue(Motor[6][2]); |
||
164 | sb_ROLL_8->setValue(Motor[7][2]); |
||
165 | sb_ROLL_9->setValue(Motor[8][2]); |
||
166 | sb_ROLL_10->setValue(Motor[9][2]); |
||
167 | sb_ROLL_11->setValue(Motor[10][2]); |
||
168 | sb_ROLL_12->setValue(Motor[11][2]); |
||
169 | |||
170 | sb_GIER_1->setValue(Motor[0][3]); |
||
171 | sb_GIER_2->setValue(Motor[1][3]); |
||
172 | sb_GIER_3->setValue(Motor[2][3]); |
||
173 | sb_GIER_4->setValue(Motor[3][3]); |
||
174 | sb_GIER_5->setValue(Motor[4][3]); |
||
175 | sb_GIER_6->setValue(Motor[5][3]); |
||
176 | sb_GIER_7->setValue(Motor[6][3]); |
||
177 | sb_GIER_8->setValue(Motor[7][3]); |
||
178 | sb_GIER_9->setValue(Motor[8][3]); |
||
179 | sb_GIER_10->setValue(Motor[9][3]); |
||
180 | sb_GIER_11->setValue(Motor[10][3]); |
||
181 | sb_GIER_12->setValue(Motor[11][3]); |
||
440 | Brean | 182 | */ |
307 | KeyOz | 183 | } |
184 | |||
185 | // Prüfen auf vollstaändigkeit |
||
186 | void dlg_MotorMixer::slot_CheckValue(int Wert) |
||
187 | { |
||
188 | Wert = Wert; |
||
189 | |||
190 | 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() + |
||
191 | sb_NICK_7->value() + sb_NICK_8->value() + sb_NICK_9->value() + sb_NICK_10->value() + sb_NICK_11->value() + sb_NICK_12->value(); |
||
192 | |||
193 | 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() + |
||
194 | sb_ROLL_7->value() + sb_ROLL_8->value() + sb_ROLL_9->value() + sb_ROLL_10->value() + sb_ROLL_11->value() + sb_ROLL_12->value(); |
||
195 | |||
196 | 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() + |
||
197 | sb_GIER_7->value() + sb_GIER_8->value() + sb_GIER_9->value() + sb_GIER_10->value() + sb_GIER_11->value() + sb_GIER_12->value(); |
||
198 | |||
199 | if (NICK == 0) |
||
200 | { |
||
201 | lb_NICK->setEnabled(true); |
||
202 | } |
||
203 | else |
||
204 | { |
||
205 | lb_NICK->setEnabled(false); |
||
206 | } |
||
207 | |||
208 | if (ROLL == 0) |
||
209 | { |
||
210 | lb_ROLL->setEnabled(true); |
||
211 | } |
||
212 | else |
||
213 | { |
||
214 | lb_ROLL->setEnabled(false); |
||
215 | } |
||
216 | |||
217 | if (GIER == 0) |
||
218 | { |
||
219 | lb_GIER->setEnabled(true); |
||
220 | } |
||
221 | else |
||
222 | { |
||
223 | lb_GIER->setEnabled(false); |
||
224 | } |
||
225 | } |
||
226 | |||
440 | Brean | 227 | //FIXME: put this in libMK/Handler.cpp |
396 | Brean | 228 | /* |
307 | KeyOz | 229 | int dlg_MotorMixer::get_MotorConfig() |
230 | { |
||
231 | get_MotorData(); |
||
232 | |||
233 | TX_Data[0] = VERSION_MIXER; |
||
234 | |||
235 | char *Name = MixerName.toLatin1().data(); |
||
236 | |||
237 | int a; |
||
238 | |||
239 | for (a = 0; a < MixerName.length(); a++) |
||
240 | { |
||
241 | TX_Data[1+a] = Name[a]; |
||
242 | } |
||
243 | |||
244 | while(a < 12) |
||
245 | { |
||
246 | TX_Data[1+a] = 0; |
||
247 | a++; |
||
248 | } |
||
249 | |||
250 | int Pos = 13; |
||
251 | |||
252 | for (int z = 0; z < 16; z++) |
||
253 | { |
||
254 | for (int y = 0; y < 4; y++) |
||
255 | { |
||
396 | Brean | 256 | TX_Data[Pos] = Parser::charToData(Motor[z][y]); |
307 | KeyOz | 257 | Pos++; |
258 | } |
||
259 | } |
||
260 | |||
261 | return Pos - 1; |
||
262 | } |
||
440 | Brean | 263 | */ |
307 | KeyOz | 264 | |
396 | Brean | 265 | // read motor values |
307 | KeyOz | 266 | void dlg_MotorMixer::slot_pb_READ() |
267 | { |
||
396 | Brean | 268 | //send command to get mixer values |
440 | Brean | 269 | handler->read_motor_mixer(); |
307 | KeyOz | 270 | } |
271 | |||
396 | Brean | 272 | //write motor values |
440 | Brean | 273 | //FIXME: put this in libMK/Handler.cpp |
307 | KeyOz | 274 | void dlg_MotorMixer::slot_pb_WRITE() |
275 | { |
||
440 | Brean | 276 | char tx_data[150]; |
277 | int length = handler->get_motor_config(tx_data); |
||
278 | handler->write_motor_mixer(tx_data, length); |
||
307 | KeyOz | 279 | } |
280 | |||
281 | void dlg_MotorMixer::slot_pb_LOAD() |
||
282 | { |
||
358 | KeyOz | 283 | QString Filename = QFileDialog::getOpenFileName(this, tr("Mikrokopter MotorMixer laden"), o_Settings->DIR.Parameter + "", tr("MK MotorMixer(*.mkm);;Alle Dateien (*)")); |
307 | KeyOz | 284 | |
285 | if (!Filename.isEmpty()) |
||
286 | { |
||
287 | QSettings Setting(Filename, QSettings::IniFormat); |
||
288 | |||
289 | Setting.beginGroup("Info"); |
||
440 | Brean | 290 | //FIXME: Add mixer-struct in kopter.h for kopterdata |
291 | // MixerName = Setting.value("Name", QString("--noname--")).toString(); |
||
292 | // MixerVersion = Setting.value("Version", 0).toInt(); |
||
307 | KeyOz | 293 | Setting.endGroup(); |
294 | |||
440 | Brean | 295 | //FIXME: Add mixer-struct in kopter.h for kopterdata |
296 | /* |
||
307 | KeyOz | 297 | Setting.beginGroup("Gas"); |
298 | for (int z = 0; z < MAXMOTOR; z++) |
||
299 | { |
||
300 | Motor[z][0] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt(); |
||
301 | } |
||
302 | Setting.endGroup(); |
||
303 | |||
304 | Setting.beginGroup("Nick"); |
||
305 | for (int z = 0; z < MAXMOTOR; z++) |
||
306 | { |
||
307 | Motor[z][1] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt(); |
||
308 | } |
||
309 | Setting.endGroup(); |
||
310 | |||
311 | Setting.beginGroup("Roll"); |
||
312 | for (int z = 0; z < MAXMOTOR; z++) |
||
313 | { |
||
314 | Motor[z][2] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt(); |
||
315 | } |
||
316 | Setting.endGroup(); |
||
317 | |||
318 | Setting.beginGroup("Yaw"); |
||
319 | for (int z = 0; z < MAXMOTOR; z++) |
||
320 | { |
||
321 | Motor[z][3] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt(); |
||
322 | } |
||
323 | Setting.endGroup(); |
||
324 | if (MixerVersion == VERSION_MIXER) |
||
325 | { |
||
326 | set_MotorData(); |
||
327 | } |
||
440 | Brean | 328 | */ |
307 | KeyOz | 329 | } |
330 | } |
||
331 | |||
332 | void dlg_MotorMixer::slot_pb_SAVE() |
||
333 | { |
||
358 | KeyOz | 334 | QString Filename = QFileDialog::getSaveFileName(this, tr("Mikrokopter MotorMixer speichern"), o_Settings->DIR.Parameter + "/" + le_NAME->text(), tr("MK MotorMixer(*.mkm);;Alle Dateien (*)")); |
307 | KeyOz | 335 | |
336 | if (!Filename.isEmpty()) |
||
337 | { |
||
338 | if (!(Filename.endsWith(".mkm", Qt::CaseInsensitive))) |
||
339 | { |
||
340 | Filename = Filename + QString(".mkm"); |
||
341 | } |
||
342 | |||
343 | get_MotorData(); |
||
344 | |||
345 | QSettings Setting(Filename, QSettings::IniFormat); |
||
346 | |||
347 | Setting.beginGroup("Info"); |
||
440 | Brean | 348 | //FIXME: Add mixer-struct in kopter.h for kopterdata - doppelter Code!!! |
349 | /* |
||
307 | KeyOz | 350 | Setting.setValue("Name", MixerName); |
351 | Setting.setValue("Version", VERSION_MIXER); |
||
352 | Setting.endGroup(); |
||
353 | |||
354 | Setting.beginGroup("Gas"); |
||
355 | for (int z = 0; z < MAXMOTOR; z++) |
||
356 | { |
||
357 | Setting.setValue(QString("Motor%1").arg(z+1), Motor[z][0]); |
||
358 | } |
||
359 | Setting.endGroup(); |
||
360 | |||
361 | Setting.beginGroup("Nick"); |
||
362 | for (int z = 0; z < MAXMOTOR; z++) |
||
363 | { |
||
364 | Setting.setValue(QString("Motor%1").arg(z+1), Motor[z][1]); |
||
365 | } |
||
366 | Setting.endGroup(); |
||
367 | |||
368 | Setting.beginGroup("Roll"); |
||
369 | for (int z = 0; z < MAXMOTOR; z++) |
||
370 | { |
||
371 | Setting.setValue(QString("Motor%1").arg(z+1), Motor[z][2]); |
||
372 | } |
||
373 | Setting.endGroup(); |
||
374 | |||
375 | Setting.beginGroup("Yaw"); |
||
376 | for (int z = 0; z < MAXMOTOR; z++) |
||
377 | { |
||
378 | Setting.setValue(QString("Motor%1").arg(z+1), Motor[z][3]); |
||
379 | } |
||
380 | Setting.endGroup(); |
||
440 | Brean | 381 | */ |
307 | KeyOz | 382 | } |
383 | } |