mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-24 19:43:35 +08:00
lib/led: move drivers/lights/rgbled LED_RGB_MAXBRT -> SYS_RGB_MAXBRT
This commit is contained in:
+27
-4
@@ -40,6 +40,31 @@
|
||||
|
||||
int LedController::update(LedControlData &control_data)
|
||||
{
|
||||
bool had_changes = false; // did one of the outputs change?
|
||||
|
||||
// check for parameter updates
|
||||
if (_parameter_update_sub.updated()) {
|
||||
// clear update
|
||||
parameter_update_s pupdate;
|
||||
_parameter_update_sub.copy(&pupdate);
|
||||
|
||||
updateParams();
|
||||
|
||||
const uint8_t max_brightness_prev = _max_brightness;
|
||||
|
||||
// set maximum brightness (0-255) from percentage
|
||||
_max_brightness = roundf(math::constrain(_param_sys_rgb_maxbrt.get(), 0.f, 1.f) * UINT8_MAX);
|
||||
|
||||
// update existing
|
||||
for (int i = 0; i < BOARD_MAX_LEDS; ++i) {
|
||||
control_data.leds[i].brightness = math::min(_max_brightness, control_data.leds[i].brightness);
|
||||
}
|
||||
|
||||
if (_max_brightness != max_brightness_prev) {
|
||||
had_changes = true;
|
||||
}
|
||||
}
|
||||
|
||||
while (_led_control_sub.updated() || _force_update) {
|
||||
const unsigned last_generation = _led_control_sub.get_last_generation();
|
||||
|
||||
@@ -78,8 +103,6 @@ int LedController::update(LedControlData &control_data)
|
||||
_force_update = false;
|
||||
}
|
||||
|
||||
bool had_changes = false; // did one of the outputs change?
|
||||
|
||||
// handle state updates
|
||||
hrt_abstime now = hrt_absolute_time();
|
||||
|
||||
@@ -207,7 +230,7 @@ void LedController::get_control_data(LedControlData &control_data)
|
||||
|
||||
for (int i = 0; i < BOARD_MAX_LEDS; ++i) {
|
||||
control_data.leds[i].color = led_control_s::COLOR_OFF; // set output to a defined state
|
||||
control_data.leds[i].brightness = 255;
|
||||
control_data.leds[i].brightness = _max_brightness;
|
||||
|
||||
for (int priority = led_control_s::MAX_PRIORITY; priority >= 0; --priority) {
|
||||
bool flash_output_active = true;
|
||||
@@ -226,7 +249,7 @@ void LedController::get_control_data(LedControlData &control_data)
|
||||
// fade on and off
|
||||
int counter = _states[i].current_blinking_time / (BREATHE_INTERVAL / 100);
|
||||
int n = counter >= (BREATHE_STEPS / 2) ? BREATHE_STEPS - counter : counter;
|
||||
control_data.leds[i].brightness = (n * n) * 255 / (BREATHE_STEPS * BREATHE_STEPS / 4); // (n/(steps/2))^2
|
||||
control_data.leds[i].brightness = (n * n) * _max_brightness / (BREATHE_STEPS * BREATHE_STEPS / 4); // (n/(steps/2))^2
|
||||
control_data.leds[i].color = cur_data.color;
|
||||
_breathe_enabled = true;
|
||||
break;
|
||||
|
||||
+23
-8
@@ -44,15 +44,23 @@
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <drivers/drv_led.h>
|
||||
|
||||
#include <px4_platform_common/module_params.h>
|
||||
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/SubscriptionInterval.hpp>
|
||||
#include <uORB/topics/led_control.h>
|
||||
#include <uORB/topics/parameter_update.h>
|
||||
|
||||
#include <lib/parameters/param.h>
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
struct LedControlDataSingle {
|
||||
uint8_t color; ///< one of led_control_s::COLOR_*
|
||||
uint8_t brightness; ///< brightness in [0, 255]
|
||||
uint8_t color{led_control_s::COLOR_OFF}; ///< one of led_control_s::COLOR_*
|
||||
uint8_t brightness{0}; ///< brightness in [0, 255]
|
||||
};
|
||||
struct LedControlData {
|
||||
LedControlDataSingle leds[BOARD_MAX_LEDS];
|
||||
LedControlDataSingle leds[BOARD_MAX_LEDS] {};
|
||||
};
|
||||
|
||||
|
||||
@@ -60,11 +68,11 @@ struct LedControlData {
|
||||
** class LedController
|
||||
* Handles the led_control topic: blinking, priorities and state updates.
|
||||
*/
|
||||
class LedController
|
||||
class LedController : public ModuleParams
|
||||
{
|
||||
public:
|
||||
LedController() = default;
|
||||
~LedController() = default;
|
||||
LedController() : ModuleParams(nullptr) {}
|
||||
~LedController() override = default;
|
||||
|
||||
/**
|
||||
* get maxium time between two consecutive calls to update() in us.
|
||||
@@ -148,8 +156,6 @@ private:
|
||||
// handle infinite case
|
||||
priority[next_priority].blink_times_left = 246;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void apply_next_state()
|
||||
@@ -175,7 +181,16 @@ private:
|
||||
PerLedData _states[BOARD_MAX_LEDS]; ///< keep current LED states
|
||||
|
||||
uORB::Subscription _led_control_sub{ORB_ID(led_control)}; ///< uorb subscription
|
||||
uORB::SubscriptionInterval _parameter_update_sub{ORB_ID(parameter_update), 1_s};
|
||||
|
||||
hrt_abstime _last_update_call{0};
|
||||
|
||||
uint8_t _max_brightness{UINT8_MAX};
|
||||
|
||||
bool _force_update{true}; ///< force an orb_copy in the beginning
|
||||
bool _breathe_enabled{false}; ///< true if at least one of the led's is currently in breathe mode
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamFloat<px4::params::SYS_RGB_MAXBRT>) _param_sys_rgb_maxbrt
|
||||
)
|
||||
};
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2015-2021 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* RGB Led brightness limit
|
||||
*
|
||||
* Set to 0 to disable, 1 for maximum brightness
|
||||
*
|
||||
* @unit %
|
||||
* @group System
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(SYS_RGB_MAXBRT, 1.f);
|
||||
Reference in New Issue
Block a user