forked from OpenPanzerProject/OP-Config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcombo_drivetype.cpp
123 lines (102 loc) · 3.91 KB
/
combo_drivetype.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
#include "combo_drivetype.h"
DriveTypeComboBox::DriveTypeComboBox(QWidget *parent) : QComboBox(parent), m_nextDriveTypeCode(-1){}
void DriveTypeComboBox::setCategory(MotorCategory mc)
{
/* generate the default options with associated values */
// We'll give the servo option slightly different labels depending on category.
// They will all accept standard servo signals and be plugged into a servo channel on the board,
// but for drive motors you would probably be using an RC ESC, for turret elevation it will be a literal servo
// Of course you can use a literal servo for drive motors and an RC ESC for elevation if you want.
switch (mc)
{
case mcDrive:
insertItem(count(), "RC Output", SERVO_ESC);
insertItem(count(), "Built-in Driver", ONBOARD);
break;
case mcTurretRotation:
insertItem(count(), "RC Output", SERVO_ESC);
insertItem(count(), "Servo - Pan Effect", SERVO_PAN);
insertItem(count(), "Built-in Driver (Motor A)", ONBOARD);
break;
case mcTurretElevation:
insertItem(count(), "RC Output", SERVO_ESC);
insertItem(count(), "Servo - Pan Effect", SERVO_PAN);
insertItem(count(), "Built-in Driver (Motor B)", ONBOARD);
break;
}
insertItem(count(), "OP Scout Serial ESC", OP_SCOUT);
insertItem(count(), "Sabertooth Serial ESC", SABERTOOTH);
insertItem(count(), "Pololu Serial ESC", POLOLU);
// So that it shows up last -
if (mc == mcTurretRotation || mc == mcTurretElevation)
{
insertItem(count(), "Detached", DRIVE_DETACHED);
}
// Create our own custom signal
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(emitCurrentDriveTypeChanged()));
}
void DriveTypeComboBox::emitCurrentDriveTypeChanged()
{ // Whenever index changes, we emit the current drive type in both QByteArray and QString format.
emit currentDriveTypeChanged(this->currentData().toByteArray());
emit currentDriveTypeChanged(this->currentText());
emit currentDriveTypeChanged(static_cast<Drive_t>(this->currentData().toUInt()));
}
// We can programmatically set the combo box to a value by passing it directly the enum code
void DriveTypeComboBox::setCurrentDriveType(int driveTypeCode)
{
this->setCurrentIndex(this->findData(driveTypeCode));
}
// We can programmatically set the combo box to a value by passing it a Drive_t enum member name
void DriveTypeComboBox::setCurrentDriveType(const Drive_t& driveType)
{
this->setCurrentIndex(this->findData(driveType));
}
// Returns the current index by string name
int DriveTypeComboBox::getCode(QString label)
{
return this->findText(label);
}
// Returns the current index by enum code
QString DriveTypeComboBox::getLabel(int code)
{
return this->itemText(this->findData(code));
}
// This returns the current actual Drive_t
Drive_t DriveTypeComboBox::getCurrentDriveType(void)
{
return Drive_t(this->currentData().toInt());
}
boolean DriveTypeComboBox::isSerial()
{
switch(this->getCurrentDriveType())
{
case POLOLU:
case SABERTOOTH:
case OP_SCOUT:
return true;
break;
default:
return false;
}
}
boolean DriveTypeComboBox::isOnboard()
{
if (this->getCurrentDriveType() == ONBOARD) return true;
else return false;
}
boolean DriveTypeComboBox::isRCOutput()
{
if (this->getCurrentDriveType() == SERVO_ESC || this->getCurrentDriveType() == SERVO_PAN) return true;
else return false;
}
boolean DriveTypeComboBox::isESC()
{ // Same as above, but this doesn't include the pan servo option (which in fact shouldn't ever be an ESC)
if (this->getCurrentDriveType() == SERVO_ESC) return true;
else return false;
}
/* For user-entered items, we won't need this
void DriveTypeComboBox::insertDriveType(const QString& newlabel)
{
insertItem(0, newlabel, m_nextDriveTypeCode--);
}
*/