LCOV - code coverage report
Current view: top level - AP_Notify - DroneCAN_RGB_LED.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 23 0.0 %
Date: 2026-09-09 11:02:08 Functions: 0 4 0.0 %

          Line data    Source code
       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             : 
      20             : #if HAL_ENABLE_DRONECAN_DRIVERS
      21             : #include "DroneCAN_RGB_LED.h"
      22             : 
      23             : #include <AP_DroneCAN/AP_DroneCAN.h>
      24             : 
      25             : #include <AP_CANManager/AP_CANManager.h>
      26             : 
      27             : #define LED_OFF 0
      28             : #define LED_FULL_BRIGHT 255
      29             : #define LED_MEDIUM ((LED_FULL_BRIGHT / 5) * 4)
      30             : #define LED_DIM ((LED_FULL_BRIGHT / 5) * 2)
      31             : 
      32           0 : DroneCAN_RGB_LED::DroneCAN_RGB_LED()
      33             :     : DroneCAN_RGB_LED(LED_OFF,
      34           0 :                      LED_FULL_BRIGHT, LED_MEDIUM, LED_DIM)
      35             : {
      36           0 : }
      37             : 
      38           0 : DroneCAN_RGB_LED::DroneCAN_RGB_LED(uint8_t led_off,
      39             :                                uint8_t led_full, uint8_t led_medium,
      40           0 :                                uint8_t led_dim)
      41           0 :     : RGBLed(led_off, led_full, led_medium, led_dim)
      42             : {
      43           0 : }
      44             : 
      45           0 : bool DroneCAN_RGB_LED::init()
      46             : {
      47             :     // LEDs can turn up later
      48           0 :     return true;
      49             : }
      50             : 
      51             : 
      52           0 : bool DroneCAN_RGB_LED::hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue)
      53             : {
      54           0 :     uavcan_equipment_indication_LightsCommand msg {};
      55           0 :     msg.commands.len = 1;
      56           0 :     msg.commands.data[0].light_id =0;
      57           0 :     msg.commands.data[0].color.red = red >> 3;
      58           0 :     msg.commands.data[0].color.green = green >> 2;
      59           0 :     msg.commands.data[0].color.blue = blue >> 3;
      60             : 
      61             :     // broadcast the message on all ifaces
      62           0 :     uint8_t can_num_drivers = AP::can().get_num_drivers();
      63           0 :     bool ok = false;
      64           0 :     for (uint8_t i = 0; i < can_num_drivers; i++) {
      65           0 :         auto *dronecan = AP_DroneCAN::get_dronecan(i);
      66           0 :         if (dronecan != nullptr) {
      67           0 :             ok |= dronecan->rgb_led.broadcast(msg);
      68             :         }
      69             :     }
      70           0 :     return ok;
      71             : }
      72             : 
      73             : #endif // HAL_ENABLE_DRONECAN_DRIVERS
      74             : 

Generated by: LCOV version 1.14