APM:Libraries
UAVCAN_RGB_LED.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Emlid Ltd. All rights reserved.
3  *
4  * This file is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This file is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  * See the GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #include <AP_HAL/AP_HAL.h>
18 #include <AP_HAL/system.h>
19 
21 
22 #if HAL_WITH_UAVCAN
23 #include "UAVCAN_RGB_LED.h"
24 
25 #include <AP_UAVCAN/AP_UAVCAN.h>
26 
28 
29 static const AP_HAL::HAL& hal = AP_HAL::get_HAL();
30 
31 #define LED_OFF 0
32 #define LED_FULL_BRIGHT 255
33 #define LED_MEDIUM ((LED_FULL_BRIGHT / 5) * 4)
34 #define LED_DIM ((LED_FULL_BRIGHT / 5) * 2)
35 
36 UAVCAN_RGB_LED::UAVCAN_RGB_LED(uint8_t led_index)
37  : UAVCAN_RGB_LED(led_index, LED_OFF,
39 {
40 }
41 
42 UAVCAN_RGB_LED::UAVCAN_RGB_LED(uint8_t led_index, uint8_t led_off,
43  uint8_t led_full, uint8_t led_medium,
44  uint8_t led_dim)
45  : RGBLed(led_off, led_full, led_medium, led_dim)
46  , _led_index(led_index)
47 {
48 }
49 
51 {
52  return true;
53 }
54 
55 
56 bool UAVCAN_RGB_LED::hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue)
57 {
58  bool success = false;
59  if (AP_BoardConfig_CAN::get_can_num_ifaces() != 0) {
60  for (uint8_t i = 0; i < MAX_NUMBER_OF_CAN_DRIVERS; i++) {
61  if (hal.can_mgr[i] != nullptr) {
62  AP_UAVCAN *uavcan = hal.can_mgr[i]->get_UAVCAN();
63  if (uavcan != nullptr) {
64  success |= uavcan->led_write(_led_index, red, green, blue);
65  }
66  }
67  }
68  }
69  return success;
70 }
71 #endif
Definition: RGBLed.h:25
#define LED_OFF
Definition: Config.h:44
#define LED_FULL_BRIGHT
bool hw_init() override
const AP_HAL::HAL & hal
Definition: UARTDriver.cpp:37
#define LED_DIM
AP_HAL::CANManager ** can_mgr
Definition: HAL.h:120
#define LED_MEDIUM
bool led_write(uint8_t led_index, uint8_t red, uint8_t green, uint8_t blue)
const HAL & get_HAL()
virtual bool hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) override
UAVCAN_RGB_LED(uint8_t led_index, uint8_t led_off, uint8_t led_full, uint8_t led_medium, uint8_t led_dim)