dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
brain.cpp
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #include "brain.h"
29 
33 #include "board_usb_ids.h"
34 
35 #include "brainconfiguration.h"
36 #include "hwbrain.h"
37 
43 {
44  // Common USB IDs
46  USBInfo(DRONIN_VID_DRONIN_BOOTLOADER, DRONIN_PID_DRONIN_BOOTLOADER, BCD_DEVICE_BOOTLOADER));
48  USBInfo(DRONIN_VID_DRONIN_FIRMWARE, DRONIN_PID_DRONIN_FIRMWARE, BCD_DEVICE_FIRMWARE));
49  // Legacy USB IDs
51  USBInfo(DRONIN_VID_BRAINFPV_BRAIN, DRONIN_PID_BRAINFPV_BRAIN, BCD_DEVICE_BOOTLOADER));
53  USBInfo(DRONIN_VID_BRAINFPV_BRAIN, DRONIN_PID_BRAINFPV_BRAIN, BCD_DEVICE_FIRMWARE));
54 
55  boardType = 0x8A;
56 
57  // Define the bank of channels that are connected to a given timer
58  channelBanks.resize(3);
59  channelBanks[0] = QVector<int>() << 1 << 2 << 3 << 4; // TIM5 main outputs
60  channelBanks[1] = QVector<int>() << 5 << 6 << 7 << 8; // TIM8 on receiverport
61  channelBanks[2] = QVector<int>() << 9 << 10; // TIM12 on receiverport
62 }
63 
65 {
66 }
67 
69 {
70  return 0x82;
71 }
72 
74 {
75  return QString("Brain");
76 }
77 
79 {
80  return QString("Brain - FPV Flight Controller");
81 }
82 
85 {
86  switch (capability) {
93  return true;
94  default:
95  break;
96  }
97 
98  return false;
99 }
100 
102 {
103  return QPixmap(":/brainfpv/images/brain.png");
104 }
105 
107 {
108  return "HwBrain";
109 }
110 
113 {
114  switch (type) {
115  case INPUT_TYPE_UNKNOWN:
116  return false;
117  default:
118  break;
119  }
120 
121  return true;
122 }
123 
130 {
131  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
132  UAVObjectManager *uavoManager = pm->getObject<UAVObjectManager>();
133  HwBrain *hwBrain = HwBrain::GetInstance(uavoManager);
134  Q_ASSERT(hwBrain);
135  if (!hwBrain)
136  return false;
137 
138  HwBrain::DataFields settings = hwBrain->getData();
139 
140  switch (type) {
141  case INPUT_TYPE_PPM:
142  settings.RxPort = HwBrain::RXPORT_PPM;
143  break;
144  case INPUT_TYPE_PWM:
145  settings.RxPort = HwBrain::RXPORT_PWM;
146  break;
147  case INPUT_TYPE_SBUS:
148  settings.MainPort = HwBrain::MAINPORT_SBUS;
149  break;
151  settings.MainPort = HwBrain::MAINPORT_SBUSNONINVERTED;
152  break;
153  case INPUT_TYPE_DSM:
154  settings.MainPort = HwBrain::MAINPORT_DSM;
155  break;
156  case INPUT_TYPE_HOTTSUMD:
157  settings.MainPort = HwBrain::MAINPORT_HOTTSUMD;
158  break;
159  case INPUT_TYPE_HOTTSUMH:
160  settings.MainPort = HwBrain::MAINPORT_HOTTSUMH;
161  break;
162  case INPUT_TYPE_IBUS:
163  settings.MainPort = HwBrain::MAINPORT_IBUS;
164  break;
165  case INPUT_TYPE_SRXL:
166  settings.MainPort = HwBrain::MAINPORT_SRXL;
167  break;
169  settings.MainPort = HwBrain::MAINPORT_TBSCROSSFIRE;
170  break;
171  default:
172  return false;
173  }
174 
175  // Apply these changes
176  hwBrain->setData(settings);
177 
178  return true;
179 }
180 
186 {
187  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
188  UAVObjectManager *uavoManager = pm->getObject<UAVObjectManager>();
189  HwBrain *hwBrain = HwBrain::GetInstance(uavoManager);
190  Q_ASSERT(hwBrain);
191  if (!hwBrain)
192  return INPUT_TYPE_UNKNOWN;
193 
194  HwBrain::DataFields settings = hwBrain->getData();
195 
196  switch (settings.MainPort) {
197  case HwBrain::MAINPORT_SBUS:
198  return INPUT_TYPE_SBUS;
199  case HwBrain::MAINPORT_SBUSNONINVERTED:
201  case HwBrain::MAINPORT_DSM:
202  return INPUT_TYPE_DSM;
203  case HwBrain::MAINPORT_HOTTSUMD:
204  return INPUT_TYPE_HOTTSUMD;
205  case HwBrain::MAINPORT_HOTTSUMH:
206  return INPUT_TYPE_HOTTSUMH;
207  case HwBrain::MAINPORT_IBUS:
208  return INPUT_TYPE_IBUS;
209  case HwBrain::MAINPORT_SRXL:
210  return INPUT_TYPE_SRXL;
211  case HwBrain::MAINPORT_TBSCROSSFIRE:
213  default:
214  break;
215  }
216 
217  switch (settings.FlxPort) {
218  case HwBrain::FLXPORT_DSM:
219  return INPUT_TYPE_DSM;
220  case HwBrain::FLXPORT_HOTTSUMD:
221  return INPUT_TYPE_HOTTSUMD;
222  case HwBrain::FLXPORT_HOTTSUMH:
223  return INPUT_TYPE_HOTTSUMH;
224  case HwBrain::FLXPORT_IBUS:
225  return INPUT_TYPE_IBUS;
226  case HwBrain::FLXPORT_SRXL:
227  return INPUT_TYPE_SRXL;
228  case HwBrain::FLXPORT_TBSCROSSFIRE:
230  default:
231  break;
232  }
233 
234  switch (settings.RxPort) {
235  case HwBrain::RXPORT_PPM:
236  case HwBrain::RXPORT_PPMPWM:
237  case HwBrain::RXPORT_PPMOUTPUTS:
238  case HwBrain::RXPORT_PPMUART:
239  case HwBrain::RXPORT_PPMUARTOUTPUTS:
240  return INPUT_TYPE_PPM;
241  case HwBrain::RXPORT_PWM:
242  return INPUT_TYPE_PWM;
243  case HwBrain::RXPORT_UART:
244  case HwBrain::RXPORT_UARTOUTPUTS:
245  switch (settings.RxPortUsart) {
246  case HwBrain::RXPORTUSART_DSM:
247  return INPUT_TYPE_DSM;
248  case HwBrain::RXPORTUSART_HOTTSUMD:
249  return INPUT_TYPE_HOTTSUMD;
250  case HwBrain::RXPORTUSART_HOTTSUMH:
251  return INPUT_TYPE_HOTTSUMH;
252  case HwBrain::RXPORTUSART_SBUSNONINVERTED:
254  case HwBrain::RXPORTUSART_IBUS:
255  return INPUT_TYPE_IBUS;
256  case HwBrain::RXPORTUSART_SRXL:
257  return INPUT_TYPE_SRXL;
258  case HwBrain::RXPORTUSART_TBSCROSSFIRE:
260  default:
261  break;
262  }
263  break;
264  default:
265  break;
266  }
267 
268  return INPUT_TYPE_UNKNOWN;
269 }
270 
272 {
273  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
274  UAVObjectManager *uavoManager = pm->getObject<UAVObjectManager>();
275  HwBrain *hwBrain = HwBrain::GetInstance(uavoManager);
276  Q_ASSERT(hwBrain);
277  if (!hwBrain)
278  return 0;
279 
280  HwBrain::DataFields settings = hwBrain->getData();
281 
282  switch (settings.GyroFullScale) {
283  case HwBrain::GYROFULLSCALE_250:
284  return 250;
285  case HwBrain::GYROFULLSCALE_500:
286  return 500;
287  case HwBrain::GYROFULLSCALE_1000:
288  return 1000;
289  case HwBrain::GYROFULLSCALE_2000:
290  return 2000;
291  default:
292  break;
293  }
294 
295  return 2000;
296 }
297 
298 QWidget *Brain::getBoardConfiguration(QWidget *parent, bool connected)
299 {
300  Q_UNUSED(connected);
301  return new BrainConfiguration(parent);
302 }
303 
304 QStringList Brain::getAdcNames()
305 {
306  return QStringList() << "Sen ADC0"
307  << "Sen ADC1"
308  << "Sen ADC2";
309 }
310 
312 {
313  switch (annunc) {
315  case ANNUNCIATOR_ALARM:
316  case ANNUNCIATOR_DAC:
317  return true;
318  case ANNUNCIATOR_BUZZER:
319  case ANNUNCIATOR_RGB:
320  break;
321  }
322  return false;
323 }
qint32 boardType
The numerical board type ID.
Definition: iboardtype.h:284
virtual QPixmap getBoardPicture()
getBoardPicture
Definition: brain.cpp:101
virtual QString shortName()
Definition: brain.cpp:73
InputType
Types of input to configure for the default port.
Definition: iboardtype.h:158
QVector< QVector< qint32 > > channelBanks
The channel groups that are driven by timers.
Definition: iboardtype.h:287
virtual QString boardDescription()
Definition: brain.cpp:78
Core plugin system that manages the plugins, their life cycle and their registered objects...
Definition: pluginmanager.h:53
BoardCapabilities
Types of capabilities boards can support.
Definition: iboardtype.h:92
virtual bool isInputConfigurationSupported(Core::IBoardType::InputType type)
Determine if this board supports configuring the receiver.
Definition: brain.cpp:112
virtual bool setInputType(Core::IBoardType::InputType type)
Definition: brain.cpp:129
The USBInfo struct.
Definition: iboardtype.h:62
void addFirmwareUSBInfo(USBInfo info)
Definition: iboardtype.h:277
void addBootloaderUSBInfo(USBInfo info)
Definition: iboardtype.h:278
virtual int queryMaxGyroRate()
Query the board for the currently set max rate of the gyro.
Definition: brain.cpp:271
virtual bool queryCapabilities(BoardCapabilities capability)
Return which capabilities this board has.
Definition: brain.cpp:84
Brain()
Brain::Brain This is the Brain board definition.
Definition: brain.cpp:42
virtual ~Brain()
Definition: brain.cpp:64
virtual QStringList getAdcNames()
Definition: brain.cpp:304
virtual QString getHwUAVO()
Definition: brain.cpp:106
virtual int minBootLoaderVersion()
Returns the minimum bootloader version required.
Definition: brain.cpp:68
virtual Core::IBoardType::InputType getInputType()
getInputType get the current input type
Definition: brain.cpp:185
virtual QWidget * getBoardConfiguration(QWidget *parent, bool connected)
Return a custom configuration widget, if one is provided.
Definition: brain.cpp:298
virtual bool hasAnnunciator(AnnunciatorType annunc)
Check if the board has the given type of annunciator.
Definition: brain.cpp:311