forked from ArduPilot/ardupilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAP_Notify.cpp
568 lines (500 loc) · 18.8 KB
/
AP_Notify.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "AP_Notify.h"
#include "AP_BoardLED.h"
#include "PixRacerLED.h"
#include "Buzzer.h"
#include "Display.h"
#include "ExternalLED.h"
#include "GPIO_LED_1.h"
#include "IS31FL3195.h"
#include "PCA9685LED_I2C.h"
#include "NavigatorLED.h"
#include "NeoPixel.h"
#include "NCP5623.h"
#include "OreoLED_I2C.h"
#include "RCOutputRGBLed.h"
#include "ToneAlarm.h"
#include "ToshibaLED_I2C.h"
#include "LP5562.h"
#include "VRBoard_LED.h"
#include "DiscreteRGBLed.h"
#include "DiscoLED.h"
#include "Led_Sysfs.h"
#include "DroneCAN_RGB_LED.h"
#include "SITL_SFML_LED.h"
#include <stdio.h>
#include "AP_BoardLED2.h"
#include "ProfiLED.h"
#include "ScriptingLED.h"
#include "DShotLED.h"
extern const AP_HAL::HAL& hal;
AP_Notify *AP_Notify::_singleton;
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
#define CONFIG_NOTIFY_DEVICES_MAX 12
#else
#define CONFIG_NOTIFY_DEVICES_MAX 6
#endif
#if AP_NOTIFY_TOSHIBALED_ENABLED
#define TOSHIBA_LED_I2C_BUS_INTERNAL 0
#define TOSHIBA_LED_I2C_BUS_EXTERNAL 1
#define ALL_TOSHIBALED_I2C (Notify_LED_ToshibaLED_I2C_Internal | Notify_LED_ToshibaLED_I2C_External)
#else
#define ALL_TOSHIBALED_I2C 0
#endif
#if AP_NOTIFY_NCP5623_ENABLED
#define ALL_NCP5623_I2C (Notify_LED_NCP5623_I2C_Internal | Notify_LED_NCP5623_I2C_External)
#else
#define ALL_NCP5623_I2C 0
#endif
#if AP_NOTIFY_LP5562_ENABLED
#define ALL_LP5562_I2C (Notify_LED_LP5562_I2C_Internal | Notify_LED_LP5562_I2C_External)
#else
#define ALL_LP5562_I2C 0
#endif
#if AP_NOTIFY_IS31FL3195_ENABLED
#define ALL_IS31FL3195_I2C (Notify_LED_IS31FL3195_I2C_Internal | Notify_LED_IS31FL3195_I2C_External)
#else
#define ALL_IS31FL3195_I2C 0
#endif
// all I2C_LEDS
#define I2C_LEDS (ALL_TOSHIBALED_I2C | ALL_NCP5623_I2C | ALL_LP5562_I2C | ALL_IS31FL3195_I2C)
#if AP_NOTIFY_DRONECAN_LED_ENABLED
#define DRONECAN_LEDS Notify_LED_DroneCAN
#else
#define DRONECAN_LEDS 0
#endif
#ifndef DEFAULT_NTF_LED_TYPES
#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO
#define DEFAULT_NTF_LED_TYPES (Notify_LED_Board | I2C_LEDS |\
Notify_LED_PCA9685LED_I2C_External)
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE
#define DEFAULT_NTF_LED_TYPES (Notify_LED_Board | I2C_LEDS |\
DRONECAN_LEDS)
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BLUE || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_POCKET || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2 || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXFMINI || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BH || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DISCO || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_OBAL_V1 || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_CANZERO
#define DEFAULT_NTF_LED_TYPES (Notify_LED_Board)
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_RST_ZYNQ
#define DEFAULT_NTF_LED_TYPES (Notify_LED_ToshibaLED_I2C_External)
#endif // board subtype
#endif // CONFIG_HAL_BOARD == HAL_BOARD_LINUX
#endif // defined (DEFAULT_NTF_LED_TYPES)
#ifndef DEFAULT_NTF_LED_TYPES
#define DEFAULT_NTF_LED_TYPES (Notify_LED_Board | I2C_LEDS)
#endif // DEFAULT_NTF_LED_TYPES
#ifndef BUZZER_ENABLE_DEFAULT
#if HAL_CANMANAGER_ENABLED
// Enable Buzzer messages over UAVCAN
#define BUZZER_ENABLE_DEFAULT (uint8_t(BuzzerType::BUILTIN) | uint8_t(BuzzerType::UAVCAN))
#else
#define BUZZER_ENABLE_DEFAULT uint8_t(BuzzerType::BUILTIN)
#endif
#endif
#ifndef BUILD_DEFAULT_BUZZER_TYPE
#define BUILD_DEFAULT_BUZZER_TYPE BUZZER_ENABLE_DEFAULT
#endif
#ifndef NOTIFY_LED_BRIGHT_DEFAULT
#define NOTIFY_LED_BRIGHT_DEFAULT RGB_LED_HIGH
#endif
#ifndef NOTIFY_LED_OVERRIDE_DEFAULT
#define NOTIFY_LED_OVERRIDE_DEFAULT 0 // rgb_source_t::standard
#endif
#ifndef NOTIFY_LED_LEN_DEFAULT
#define NOTIFY_LED_LEN_DEFAULT 1
#endif
#ifndef HAL_BUZZER_PIN
#define HAL_BUZZER_PIN -1
#endif
#ifndef DEFAULT_BUZZ_ON_LVL
#define DEFAULT_BUZZ_ON_LVL 1
#endif
// table of user settable parameters
const AP_Param::GroupInfo AP_Notify::var_info[] = {
// @Param: LED_BRIGHT
// @DisplayName: LED Brightness
// @Description: Select the RGB LED brightness level. When USB is connected brightness will never be higher than low regardless of the setting.
// @Values: 0:Off,1:Low,2:Medium,3:High
// @User: Advanced
AP_GROUPINFO("LED_BRIGHT", 0, AP_Notify, _rgb_led_brightness, NOTIFY_LED_BRIGHT_DEFAULT),
// @Param: BUZZ_TYPES
// @DisplayName: Buzzer Driver Types
// @Description: Controls what types of Buzzer will be enabled
// @Bitmask: 0:Built-in buzzer, 1:DShot, 2:DroneCAN
// @User: Advanced
AP_GROUPINFO("BUZZ_TYPES", 1, AP_Notify, _buzzer_type, BUILD_DEFAULT_BUZZER_TYPE),
// @Param: LED_OVERRIDE
// @DisplayName: Specifies colour source for the RGBLed
// @Description: Specifies the source for the colours and brightness for the LED. OutbackChallenge conforms to the MedicalExpress (https://uavchallenge.org/medical-express/) rules, essentially "Green" is disarmed (safe-to-approach), "Red" is armed (not safe-to-approach). Traffic light is a simplified color set, red when armed, yellow when the safety switch is not surpressing outputs (but disarmed), and green when outputs are surpressed and disarmed, the LED will blink faster if disarmed and failing arming checks.
// @Values: 0:Standard,1:MAVLink/Scripting/AP_Periph,2:OutbackChallenge,3:TrafficLight
// @User: Advanced
AP_GROUPINFO("LED_OVERRIDE", 2, AP_Notify, _rgb_led_override, NOTIFY_LED_OVERRIDE_DEFAULT),
#if HAL_DISPLAY_ENABLED
// @Param: DISPLAY_TYPE
// @DisplayName: Type of on-board I2C display
// @Description: This sets up the type of on-board I2C display. Disabled by default.
// @Values: 0:Disable,1:ssd1306,2:sh1106,10:SITL
// @User: Advanced
AP_GROUPINFO("DISPLAY_TYPE", 3, AP_Notify, _display_type, 0),
#endif
#if AP_NOTIFY_OREOLED_ENABLED
// @Param: OREO_THEME
// @DisplayName: OreoLED Theme
// @Description: Enable/Disable Solo Oreo LED driver, 0 to disable, 1 for Aircraft theme, 2 for Rover theme
// @Values: 0:Disabled,1:Aircraft,2:Rover
// @User: Advanced
AP_GROUPINFO("OREO_THEME", 4, AP_Notify, _oreo_theme, 0),
#endif
// @Param: BUZZ_PIN
// @DisplayName: Buzzer pin
// @Description: Enables to connect active buzzer to arbitrary pin. Requires 3-pin buzzer or additional MOSFET! Some the Wiki's "GPIOs" page for how to determine the pin number for a given autopilot.
// @Values: -1:Disabled
// @User: Advanced
AP_GROUPINFO("BUZZ_PIN", 5, AP_Notify, _buzzer_pin, HAL_BUZZER_PIN),
// @Param: LED_TYPES
// @DisplayName: LED Driver Types
// @Description: Controls what types of LEDs will be enabled
// @Bitmask: 0:Built-in LED, 1:Internal ToshibaLED, 2:External ToshibaLED, 3:External PCA9685, 4:Oreo LED, 5:DroneCAN, 6:NCP5623 External, 7:NCP5623 Internal, 8:NeoPixel, 9:ProfiLED, 10:Scripting, 11:DShot, 12:ProfiLED_SPI, 13:LP5562 External, 14: LP5562 Internal, 15:IS31FL3195 External, 16: IS31FL3195 Internal, 17: DiscreteRGB, 18: NeoPixelRGB
// @User: Advanced
AP_GROUPINFO("LED_TYPES", 6, AP_Notify, _led_type, DEFAULT_NTF_LED_TYPES),
// @Param: BUZZ_ON_LVL
// @DisplayName: Buzzer-on pin logic level
// @Description: Specifies pin level that indicates buzzer should play
// @Values: 0:LowIsOn,1:HighIsOn
// @User: Advanced
AP_GROUPINFO("BUZZ_ON_LVL", 7, AP_Notify, _buzzer_level, DEFAULT_BUZZ_ON_LVL),
// @Param: BUZZ_VOLUME
// @DisplayName: Buzzer volume
// @Description: Control the volume of the buzzer
// @Range: 0 100
// @Units: %
AP_GROUPINFO("BUZZ_VOLUME", 8, AP_Notify, _buzzer_volume, 100),
// @Param: LED_LEN
// @DisplayName: Serial LED String Length
// @Description: The number of Serial LED's to use for notifications (NeoPixel's and ProfiLED)
// @Range: 1 32
// @User: Advanced
// @RebootRequired: True
AP_GROUPINFO("LED_LEN", 9, AP_Notify, _led_len, NOTIFY_LED_LEN_DEFAULT),
AP_GROUPEND
};
// Default constructor
AP_Notify::AP_Notify()
{
AP_Param::setup_object_defaults(this, var_info);
if (_singleton != nullptr) {
AP_HAL::panic("AP_Notify must be singleton");
}
_singleton = this;
}
// static flags, to allow for direct class update from device drivers
struct AP_Notify::notify_flags_and_values_type AP_Notify::flags;
struct AP_Notify::notify_events_type AP_Notify::events;
NotifyDevice *AP_Notify::_devices[CONFIG_NOTIFY_DEVICES_MAX];
uint8_t AP_Notify::_num_devices;
void AP_Notify::add_backend_helper(NotifyDevice *backend)
{
_devices[_num_devices] = backend;
_devices[_num_devices]->pNotify = this;
if(!_devices[_num_devices]->init()) {
delete _devices[_num_devices];
_devices[_num_devices] = nullptr;
} else {
_num_devices++;
}
}
#define ADD_BACKEND(backend) do { add_backend_helper(backend); if (_num_devices >= CONFIG_NOTIFY_DEVICES_MAX) return;} while(0)
// add notify backends to _devices array
void AP_Notify::add_backends(void)
{
if (_num_devices != 0) {
return;
}
for (uint32_t i = 1; i < Notify_LED_MAX; i = i << 1) {
switch(_led_type & i) {
case Notify_LED_None:
break;
case Notify_LED_Board:
// select the most appropriate built in LED driver type
#if AP_NOTIFY_SYSFS_LED_ENABLED
ADD_BACKEND(NEW_NOTHROW Led_Sysfs("rgb_led0", "rgb_led2", "rgb_led1"));
#elif AP_NOTIFY_RCOUTPUTRGBLEDINVERTED_LED_ENABLED
ADD_BACKEND(NEW_NOTHROW RCOutputRGBLedInverted(12, 13, 14));
#elif AP_NOTIFY_RCOUTPUTRGBLED_LED_ENABLED
ADD_BACKEND(NEW_NOTHROW RCOutputRGBLed(HAL_RCOUT_RGBLED_RED, HAL_RCOUT_RGBLED_GREEN, HAL_RCOUT_RGBLED_BLUE));
#elif AP_NOTIFY_DISCO_LED_ENABLED
ADD_BACKEND(NEW_NOTHROW DiscoLED());
#elif AP_NOTIFY_NAVIGATOR_LED_ENABLED
ADD_BACKEND(NEW_NOTHROW NavigatorLED());
#endif
#if AP_NOTIFY_EXTERNALLED_ENABLED
ADD_BACKEND(NEW_NOTHROW ExternalLED()); // despite the name this is a built in set of onboard LED's
#endif
#if AP_NOTIFY_GPIO_LED_RGB_ENABLED
ADD_BACKEND(NEW_NOTHROW PixRacerLED());
#elif AP_NOTIFY_VRBOARD_LED_ENABLED
ADD_BACKEND(NEW_NOTHROW VRBoard_LED());
#elif AP_NOTIFY_GPIO_LED_3_ENABLED
ADD_BACKEND(NEW_NOTHROW AP_BoardLED());
#elif AP_NOTIFY_GPIO_LED_2_ENABLED
ADD_BACKEND(NEW_NOTHROW AP_BoardLED2());
#endif
#if AP_NOTIFY_GPIO_LED_1_ENABLED
ADD_BACKEND(NEW_NOTHROW GPIO_LED_1());
#endif
break;
#if AP_NOTIFY_TOSHIBALED_ENABLED
case Notify_LED_ToshibaLED_I2C_Internal:
ADD_BACKEND(NEW_NOTHROW ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_INTERNAL));
break;
case Notify_LED_ToshibaLED_I2C_External:
ADD_BACKEND(NEW_NOTHROW ToshibaLED_I2C(TOSHIBA_LED_I2C_BUS_EXTERNAL));
break;
#endif
#if AP_NOTIFY_NCP5623_ENABLED
case Notify_LED_NCP5623_I2C_External:
FOREACH_I2C_EXTERNAL(b) {
ADD_BACKEND(NEW_NOTHROW NCP5623(b));
}
break;
case Notify_LED_NCP5623_I2C_Internal:
FOREACH_I2C_INTERNAL(b) {
ADD_BACKEND(NEW_NOTHROW NCP5623(b));
}
break;
#endif
#if AP_NOTIFY_PCA9685_ENABLED
case Notify_LED_PCA9685LED_I2C_External:
ADD_BACKEND(NEW_NOTHROW PCA9685LED_I2C());
break;
#endif
#if AP_NOTIFY_NEOPIXEL_ENABLED
case Notify_LED_NeoPixel:
case Notify_LED_NeoPixelRGB:
ADD_BACKEND(NEW_NOTHROW NeoPixel());
break;
#endif
#if AP_NOTIFY_PROFILED_ENABLED
case Notify_LED_ProfiLED:
ADD_BACKEND(NEW_NOTHROW ProfiLED());
break;
#endif
#if AP_NOTIFY_PROFILED_SPI_ENABLED
case Notify_LED_ProfiLED_SPI:
ADD_BACKEND(NEW_NOTHROW ProfiLED_SPI());
break;
#endif
#if AP_NOTIFY_OREOLED_ENABLED
case Notify_LED_OreoLED:
if (_oreo_theme) {
ADD_BACKEND(NEW_NOTHROW OreoLED_I2C(0, _oreo_theme));
}
break;
#endif
#if AP_NOTIFY_DRONECAN_LED_ENABLED
case Notify_LED_DroneCAN:
ADD_BACKEND(NEW_NOTHROW DroneCAN_RGB_LED());
break;
#endif // AP_NOTIFY_DRONECAN_LED_ENABLED
#if AP_NOTIFY_SCRIPTING_LED_ENABLED
case Notify_LED_Scripting:
ADD_BACKEND(NEW_NOTHROW ScriptingLED());
break;
#endif
#if AP_NOTIFY_DSHOT_LED_ENABLED
case Notify_LED_DShot:
ADD_BACKEND(NEW_NOTHROW DShotLED());
break;
#endif
#if AP_NOTIFY_LP5562_ENABLED
case Notify_LED_LP5562_I2C_External:
FOREACH_I2C_EXTERNAL(b) {
ADD_BACKEND(NEW_NOTHROW LP5562(b, 0x30));
}
break;
case Notify_LED_LP5562_I2C_Internal:
FOREACH_I2C_INTERNAL(b) {
ADD_BACKEND(NEW_NOTHROW LP5562(b, 0x30));
}
break;
#endif
#if AP_NOTIFY_IS31FL3195_ENABLED
case Notify_LED_IS31FL3195_I2C_External:
FOREACH_I2C_EXTERNAL(b) {
ADD_BACKEND(NEW_NOTHROW IS31FL3195(b, 0x54));
}
break;
case Notify_LED_IS31FL3195_I2C_Internal:
FOREACH_I2C_INTERNAL(b) {
ADD_BACKEND(NEW_NOTHROW IS31FL3195(b, 0x54));
}
break;
#endif
#if AP_NOTIFY_DISCRETE_RGB_ENABLED
case Notify_LED_DiscreteRGB:
ADD_BACKEND(NEW_NOTHROW DiscreteRGBLed(DISCRETE_RGB_RED_PIN,
DISCRETE_RGB_GREEN_PIN,
DISCRETE_RGB_BLUE_PIN,
DISCRETE_RGB_POLARITY));
break;
#endif
}
}
#if HAL_DISPLAY_ENABLED
// Always try and add a display backend
ADD_BACKEND(NEW_NOTHROW Display());
#endif
// ChibiOS noise makers
#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
ADD_BACKEND(NEW_NOTHROW Buzzer());
#if AP_NOTIFY_TONEALARM_ENABLED
ADD_BACKEND(NEW_NOTHROW AP_ToneAlarm());
#endif
// Linux noise makers
#elif CONFIG_HAL_BOARD == HAL_BOARD_LINUX
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2 || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2 || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXFMINI || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_RST_ZYNQ || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BLUE || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_CANZERO
// No noise makers, keep this though to ensure that the final else is safe
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BBBMINI || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_POCKET || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_OBAL_V1
ADD_BACKEND(NEW_NOTHROW Buzzer());
#else // other linux
ADD_BACKEND(NEW_NOTHROW AP_ToneAlarm());
#endif
#elif CONFIG_HAL_BOARD == HAL_BOARD_SITL
ADD_BACKEND(NEW_NOTHROW AP_ToneAlarm());
ADD_BACKEND(NEW_NOTHROW Buzzer());
#ifdef WITH_SITL_RGBLED
ADD_BACKEND(NEW_NOTHROW SITL_SFML_LED());
#endif
#endif // Noise makers
}
// initialisation
void AP_Notify::init(void)
{
// add all the backends
add_backends();
}
// main update function, called at 50Hz
void AP_Notify::update(void)
{
for (uint8_t i = 0; i < _num_devices; i++) {
if (_devices[i] != nullptr) {
_devices[i]->update();
}
}
//reset the events
memset(&AP_Notify::events, 0, sizeof(AP_Notify::events));
}
#if AP_NOTIFY_MAVLINK_LED_CONTROL_SUPPORT_ENABLED
// handle a LED_CONTROL message
void AP_Notify::handle_led_control(const mavlink_message_t &msg)
{
for (uint8_t i = 0; i < _num_devices; i++) {
if (_devices[i] != nullptr) {
_devices[i]->handle_led_control(msg);
}
}
}
#endif
// handle RGB from Scripting or AP_Periph
void AP_Notify::handle_rgb(uint8_t r, uint8_t g, uint8_t b, uint8_t rate_hz)
{
for (uint8_t i = 0; i < _num_devices; i++) {
if (_devices[i] != nullptr) {
_devices[i]->rgb_control(r, g, b, rate_hz);
}
}
}
// handle RGB Per led from Scripting
void AP_Notify::handle_rgb_id(uint8_t r, uint8_t g, uint8_t b, uint8_t id)
{
for (uint8_t i = 0; i < _num_devices; i++) {
if (_devices[i] != nullptr) {
_devices[i]->rgb_set_id(r, g, b, id);
}
}
}
void AP_Notify::play_tune(const char *tune)
{
for (uint8_t i = 0; i < _num_devices; i++) {
if (_devices[i] != nullptr) {
_devices[i]->play_tune(tune);
}
}
}
// set flight mode string
void AP_Notify::set_flight_mode_str(const char *str)
{
strncpy(_flight_mode_str, str, sizeof(_flight_mode_str));
_flight_mode_str[sizeof(_flight_mode_str)-1] = 0;
}
void AP_Notify::send_text(const char *str)
{
strncpy(_send_text, str, sizeof(_send_text));
_send_text[sizeof(_send_text)-1] = 0;
_send_text_updated_millis = AP_HAL::millis();
}
#if AP_SCRIPTING_ENABLED
void AP_Notify::send_text_scripting(const char *str, uint8_t r)
{
for (uint8_t i = 0; i < _num_devices; i++) {
if (_devices[i] != nullptr) {
_devices[i]->send_text_blocking(str, r);
}
}
}
void AP_Notify::release_text_scripting(uint8_t r)
{
for (uint8_t i = 0; i < _num_devices; i++) {
if (_devices[i] != nullptr) {
_devices[i]->release_text(r);
}
}
}
#endif
// convert 0-3 to 0-100
int8_t AP_Notify::get_rgb_led_brightness_percent() const
{
switch (_rgb_led_brightness) {
default:
case RGB_LED_OFF:
return 0;
case RGB_LED_LOW:
return 33;
case RGB_LED_MEDIUM:
return 66;
case RGB_LED_HIGH:
return 100;
}
}
namespace AP {
AP_Notify ¬ify()
{
return *AP_Notify::get_singleton();
}
};