Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
801 - 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(cSettings *t_Settings, s_Directorys t_Dir)
72
{
73
    o_Settings = t_Settings;
74
    s_Dir      = t_Dir;
75
}
76
 
77
// Motordaten übernehmen.
78
void dlg_MotorMixer::set_MotorConfig(s_MK_Mixer t_Mixer)
79
{  
80
    MK_Mixer = t_Mixer;
81
 
82
    set_MotorData();
83
}
84
 
85
// Motordaten aus GUI übernehmen
86
void dlg_MotorMixer::get_MotorData()
87
{
88
    memcpy(MK_Mixer.Name, le_NAME->text().toLatin1().data(), 12);
89
 
90
    MK_Mixer.Motor[0][0]  = sb_GAS_1->value();
91
    MK_Mixer.Motor[1][0]  = sb_GAS_2->value();
92
    MK_Mixer.Motor[2][0]  = sb_GAS_3->value();
93
    MK_Mixer.Motor[3][0]  = sb_GAS_4->value();
94
    MK_Mixer.Motor[4][0]  = sb_GAS_5->value();
95
    MK_Mixer.Motor[5][0]  = sb_GAS_6->value();
96
    MK_Mixer.Motor[6][0]  = sb_GAS_7->value();
97
    MK_Mixer.Motor[7][0]  = sb_GAS_8->value();
98
    MK_Mixer.Motor[8][0]  = sb_GAS_9->value();
99
    MK_Mixer.Motor[9][0]  = sb_GAS_10->value();
100
    MK_Mixer.Motor[10][0] = sb_GAS_11->value();
101
    MK_Mixer.Motor[11][0] = sb_GAS_12->value();
102
 
103
    MK_Mixer.Motor[0][1]  = sb_NICK_1->value();
104
    MK_Mixer.Motor[1][1]  = sb_NICK_2->value();
105
    MK_Mixer.Motor[2][1]  = sb_NICK_3->value();
106
    MK_Mixer.Motor[3][1]  = sb_NICK_4->value();
107
    MK_Mixer.Motor[4][1]  = sb_NICK_5->value();
108
    MK_Mixer.Motor[5][1]  = sb_NICK_6->value();
109
    MK_Mixer.Motor[6][1]  = sb_NICK_7->value();
110
    MK_Mixer.Motor[7][1]  = sb_NICK_8->value();
111
    MK_Mixer.Motor[8][1]  = sb_NICK_9->value();
112
    MK_Mixer.Motor[9][1]  = sb_NICK_10->value();
113
    MK_Mixer.Motor[10][1] = sb_NICK_11->value();
114
    MK_Mixer.Motor[11][1] = sb_NICK_12->value();
115
 
116
    MK_Mixer.Motor[0][2]  = sb_ROLL_1->value();
117
    MK_Mixer.Motor[1][2]  = sb_ROLL_2->value();
118
    MK_Mixer.Motor[2][2]  = sb_ROLL_3->value();
119
    MK_Mixer.Motor[3][2]  = sb_ROLL_4->value();
120
    MK_Mixer.Motor[4][2]  = sb_ROLL_5->value();
121
    MK_Mixer.Motor[5][2]  = sb_ROLL_6->value();
122
    MK_Mixer.Motor[6][2]  = sb_ROLL_7->value();
123
    MK_Mixer.Motor[7][2]  = sb_ROLL_8->value();
124
    MK_Mixer.Motor[8][2]  = sb_ROLL_9->value();
125
    MK_Mixer.Motor[9][2]  = sb_ROLL_10->value();
126
    MK_Mixer.Motor[10][2] = sb_ROLL_11->value();
127
    MK_Mixer.Motor[11][2] = sb_ROLL_12->value();
128
 
129
    MK_Mixer.Motor[0][3]  = sb_GIER_1->value();
130
    MK_Mixer.Motor[1][3]  = sb_GIER_2->value();
131
    MK_Mixer.Motor[2][3]  = sb_GIER_3->value();
132
    MK_Mixer.Motor[3][3]  = sb_GIER_4->value();
133
    MK_Mixer.Motor[4][3]  = sb_GIER_5->value();
134
    MK_Mixer.Motor[5][3]  = sb_GIER_6->value();
135
    MK_Mixer.Motor[6][3]  = sb_GIER_7->value();
136
    MK_Mixer.Motor[7][3]  = sb_GIER_8->value();
137
    MK_Mixer.Motor[8][3]  = sb_GIER_9->value();
138
    MK_Mixer.Motor[9][3]  = sb_GIER_10->value();
139
    MK_Mixer.Motor[10][3] = sb_GIER_11->value();
140
    MK_Mixer.Motor[11][3] = sb_GIER_12->value();
141
}
142
 
143
// Motordaten anzeigen
144
void dlg_MotorMixer::set_MotorData()
145
{
146
    le_NAME->setText(QString(MK_Mixer.Name));
147
 
148
    sb_GAS_1->setValue(MK_Mixer.Motor[0][0]);
149
    sb_GAS_2->setValue(MK_Mixer.Motor[1][0]);
150
    sb_GAS_3->setValue(MK_Mixer.Motor[2][0]);
151
    sb_GAS_4->setValue(MK_Mixer.Motor[3][0]);
152
    sb_GAS_5->setValue(MK_Mixer.Motor[4][0]);
153
    sb_GAS_6->setValue(MK_Mixer.Motor[5][0]);
154
    sb_GAS_7->setValue(MK_Mixer.Motor[6][0]);
155
    sb_GAS_8->setValue(MK_Mixer.Motor[7][0]);
156
    sb_GAS_9->setValue(MK_Mixer.Motor[8][0]);
157
    sb_GAS_10->setValue(MK_Mixer.Motor[9][0]);
158
    sb_GAS_11->setValue(MK_Mixer.Motor[10][0]);
159
    sb_GAS_12->setValue(MK_Mixer.Motor[11][0]);
160
 
161
    sb_NICK_1->setValue(MK_Mixer.Motor[0][1]);
162
    sb_NICK_2->setValue(MK_Mixer.Motor[1][1]);
163
    sb_NICK_3->setValue(MK_Mixer.Motor[2][1]);
164
    sb_NICK_4->setValue(MK_Mixer.Motor[3][1]);
165
    sb_NICK_5->setValue(MK_Mixer.Motor[4][1]);
166
    sb_NICK_6->setValue(MK_Mixer.Motor[5][1]);
167
    sb_NICK_7->setValue(MK_Mixer.Motor[6][1]);
168
    sb_NICK_8->setValue(MK_Mixer.Motor[7][1]);
169
    sb_NICK_9->setValue(MK_Mixer.Motor[8][1]);
170
    sb_NICK_10->setValue(MK_Mixer.Motor[9][1]);
171
    sb_NICK_11->setValue(MK_Mixer.Motor[10][1]);
172
    sb_NICK_12->setValue(MK_Mixer.Motor[11][1]);
173
 
174
    sb_ROLL_1->setValue(MK_Mixer.Motor[0][2]);
175
    sb_ROLL_2->setValue(MK_Mixer.Motor[1][2]);
176
    sb_ROLL_3->setValue(MK_Mixer.Motor[2][2]);
177
    sb_ROLL_4->setValue(MK_Mixer.Motor[3][2]);
178
    sb_ROLL_5->setValue(MK_Mixer.Motor[4][2]);
179
    sb_ROLL_6->setValue(MK_Mixer.Motor[5][2]);
180
    sb_ROLL_7->setValue(MK_Mixer.Motor[6][2]);
181
    sb_ROLL_8->setValue(MK_Mixer.Motor[7][2]);
182
    sb_ROLL_9->setValue(MK_Mixer.Motor[8][2]);
183
    sb_ROLL_10->setValue(MK_Mixer.Motor[9][2]);
184
    sb_ROLL_11->setValue(MK_Mixer.Motor[10][2]);
185
    sb_ROLL_12->setValue(MK_Mixer.Motor[11][2]);
186
 
187
    sb_GIER_1->setValue(MK_Mixer.Motor[0][3]);
188
    sb_GIER_2->setValue(MK_Mixer.Motor[1][3]);
189
    sb_GIER_3->setValue(MK_Mixer.Motor[2][3]);
190
    sb_GIER_4->setValue(MK_Mixer.Motor[3][3]);
191
    sb_GIER_5->setValue(MK_Mixer.Motor[4][3]);
192
    sb_GIER_6->setValue(MK_Mixer.Motor[5][3]);
193
    sb_GIER_7->setValue(MK_Mixer.Motor[6][3]);
194
    sb_GIER_8->setValue(MK_Mixer.Motor[7][3]);
195
    sb_GIER_9->setValue(MK_Mixer.Motor[8][3]);
196
    sb_GIER_10->setValue(MK_Mixer.Motor[9][3]);
197
    sb_GIER_11->setValue(MK_Mixer.Motor[10][3]);
198
    sb_GIER_12->setValue(MK_Mixer.Motor[11][3]);
199
}
200
 
201
// Prüfen auf vollstaändigkeit
202
void dlg_MotorMixer::slot_CheckValue(int Wert)
203
{
204
    Wert = Wert;
205
 
206
    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() +
207
               sb_NICK_7->value() + sb_NICK_8->value() + sb_NICK_9->value() + sb_NICK_10->value() + sb_NICK_11->value() + sb_NICK_12->value();
208
 
209
    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() +
210
               sb_ROLL_7->value() + sb_ROLL_8->value() + sb_ROLL_9->value() + sb_ROLL_10->value() + sb_ROLL_11->value() + sb_ROLL_12->value();
211
 
212
    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() +
213
               sb_GIER_7->value() + sb_GIER_8->value() + sb_GIER_9->value() + sb_GIER_10->value() + sb_GIER_11->value() + sb_GIER_12->value();
214
 
215
    if (NICK == 0)
216
    {
217
        lb_NICK->setEnabled(true);
218
    }
219
    else
220
    {
221
        lb_NICK->setEnabled(false);
222
    }
223
 
224
    if (ROLL == 0)
225
    {
226
        lb_ROLL->setEnabled(true);
227
    }
228
    else
229
    {
230
        lb_ROLL->setEnabled(false);
231
    }
232
 
233
    if (GIER == 0)
234
    {
235
        lb_GIER->setEnabled(true);
236
    }
237
    else
238
    {
239
        lb_GIER->setEnabled(false);
240
    }
241
}
242
 
243
// Mixer von der FC Lesen.
244
void dlg_MotorMixer::read_Mixer()
245
{
246
    c_Data[0] = 0;
247
//    o_Input->send_Data(HandlerMK::make_Frame('n', ADDRESS_FC, c_Data, 0).toLatin1().data(), DATA_READ_MIXER);
248
    emit sig_SendData(HandlerMK::make_Frame('n', ADDRESS_FC, c_Data, 0).toLatin1().data(), DATA_READ_MIXER);
249
}
250
 
251
// Button-Slots
252
void dlg_MotorMixer::slot_pb_READ()
253
{
254
    read_Mixer();
255
}
256
 
257
void dlg_MotorMixer::slot_pb_WRITE()
258
{
259
    get_MotorData();
260
 
261
    memcpy((unsigned char *)&c_Data, (unsigned char *)&MK_Mixer, sizeof(MK_Mixer));
262
 
263
//    o_Input->send_Data(HandlerMK::make_Frame('m', ADDRESS_FC, c_Data, sizeof(MK_Mixer)).toLatin1().data(), DATA_WRITE_MIXER);
264
    emit sig_SendData(HandlerMK::make_Frame('m', ADDRESS_FC, c_Data, sizeof(MK_Mixer)).toLatin1().data(), DATA_WRITE_MIXER);
265
}
266
 
267
void dlg_MotorMixer::slot_pb_LOAD()
268
{
269
    QString Dir = QDir::homePath();
270
 
271
    QString Filename = QFileDialog::getOpenFileName(this, tr("Mikrokopter MotorMixer laden"),  s_Dir.Settings + "", tr("MK MotorMixer(*.mkm);;Alle Dateien (*)"));
272
 
273
    if (!Filename.isEmpty())
274
    {
275
        QSettings Setting(Filename, QSettings::IniFormat);
276
 
277
        Setting.beginGroup("Info");
278
            memcpy(MK_Mixer.Name, Setting.value("Name", QString("--noname--")).toString().toLatin1().data(), 12);
279
            MK_Mixer.Revision = Setting.value("Version", 0).toInt();
280
        Setting.endGroup();
281
 
282
        Setting.beginGroup("Gas");
283
            for (int z = 0; z < MK_MAX_MOTOR; z++)
284
            {
285
                MK_Mixer.Motor[z][0] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt();
286
            }
287
        Setting.endGroup();
288
 
289
        Setting.beginGroup("Nick");
290
            for (int z = 0; z < MK_MAX_MOTOR; z++)
291
            {
292
                MK_Mixer.Motor[z][1] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt();
293
            }
294
        Setting.endGroup();
295
 
296
        Setting.beginGroup("Roll");
297
            for (int z = 0; z < MK_MAX_MOTOR; z++)
298
            {
299
                MK_Mixer.Motor[z][2] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt();
300
            }
301
        Setting.endGroup();
302
 
303
        Setting.beginGroup("Yaw");
304
            for (int z = 0; z < MK_MAX_MOTOR; z++)
305
            {
306
                MK_Mixer.Motor[z][3] = Setting.value(QString("Motor%1").arg(z+1), 0).toInt();
307
            }
308
        Setting.endGroup();
309
 
310
        if (MK_Mixer.Revision == MK_VERSION_MIXER)
311
        {
312
            set_MotorData();
313
        }
314
    }
315
}
316
 
317
void dlg_MotorMixer::slot_pb_SAVE()
318
{
319
    QString Dir = QDir::homePath();
320
 
321
    QString Filename = QFileDialog::getSaveFileName(this, tr("Mikrokopter MotorMixer speichern"), s_Dir.Settings + "/" + le_NAME->text(), tr("MK MotorMixer(*.mkm);;Alle Dateien (*)"));
322
 
323
    if (!Filename.isEmpty())
324
    {
325
        if (!(Filename.endsWith(".mkm", Qt::CaseInsensitive)))
326
        {
327
            Filename = Filename + QString(".mkm");
328
        }
329
 
330
        get_MotorData();
331
 
332
        QSettings Setting(Filename, QSettings::IniFormat);
333
 
334
        Setting.beginGroup("Info");
335
            Setting.setValue("Name",         QString(MK_Mixer.Name));
336
            Setting.setValue("Version",      MK_VERSION_MIXER);
337
        Setting.endGroup();
338
 
339
        Setting.beginGroup("Gas");
340
            for (int z = 0; z < MK_MAX_MOTOR; z++)
341
            {
342
                Setting.setValue(QString("Motor%1").arg(z+1), MK_Mixer.Motor[z][0]);
343
            }
344
        Setting.endGroup();
345
 
346
        Setting.beginGroup("Nick");
347
            for (int z = 0; z < MK_MAX_MOTOR; z++)
348
            {
349
                 Setting.setValue(QString("Motor%1").arg(z+1), MK_Mixer.Motor[z][1]);
350
            }
351
        Setting.endGroup();
352
 
353
        Setting.beginGroup("Roll");
354
            for (int z = 0; z < MK_MAX_MOTOR; z++)
355
            {
356
                Setting.setValue(QString("Motor%1").arg(z+1), MK_Mixer.Motor[z][2]);
357
            }
358
        Setting.endGroup();
359
 
360
        Setting.beginGroup("Yaw");
361
            for (int z = 0; z < MK_MAX_MOTOR; z++)
362
            {
363
                Setting.setValue(QString("Motor%1").arg(z+1), MK_Mixer.Motor[z][3]);
364
            }
365
        Setting.endGroup();
366
    }
367
}
368