mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-18 00:13:34 +08:00
lib/led: move drivers/lights/rgbled LED_RGB_MAXBRT -> SYS_RGB_MAXBRT
This commit is contained in:
@@ -48,9 +48,6 @@
|
||||
#include <px4_platform_common/getopt.h>
|
||||
#include <px4_platform_common/i2c_spi_buses.h>
|
||||
#include <px4_platform_common/module.h>
|
||||
#include <uORB/Subscription.hpp>
|
||||
#include <uORB/SubscriptionInterval.hpp>
|
||||
#include <uORB/topics/parameter_update.h>
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
@@ -78,26 +75,20 @@ public:
|
||||
|
||||
void RunImpl();
|
||||
|
||||
protected:
|
||||
void print_status() override;
|
||||
private:
|
||||
void print_status() override;
|
||||
int send_led_enable(bool enable);
|
||||
int send_led_rgb();
|
||||
int get(bool &on, bool &powersave, uint8_t &r, uint8_t &g, uint8_t &b);
|
||||
|
||||
float _brightness{1.0f};
|
||||
float _max_brightness{1.0f};
|
||||
|
||||
uint8_t _r{0};
|
||||
uint8_t _g{0};
|
||||
uint8_t _b{0};
|
||||
bool _leds_enabled{true};
|
||||
|
||||
uORB::SubscriptionInterval _parameter_update_sub{ORB_ID(parameter_update), 1_s};
|
||||
|
||||
LedController _led_controller;
|
||||
|
||||
int send_led_enable(bool enable);
|
||||
int send_led_rgb();
|
||||
int get(bool &on, bool &powersave, uint8_t &r, uint8_t &g, uint8_t &b);
|
||||
void update_params();
|
||||
};
|
||||
|
||||
RGBLED::RGBLED(const I2CSPIDriverConfig &config) :
|
||||
@@ -119,8 +110,6 @@ RGBLED::init()
|
||||
send_led_enable(false);
|
||||
send_led_rgb();
|
||||
|
||||
update_params();
|
||||
|
||||
// kick off work queue
|
||||
ScheduleNow();
|
||||
|
||||
@@ -166,19 +155,6 @@ RGBLED::print_status()
|
||||
void
|
||||
RGBLED::RunImpl()
|
||||
{
|
||||
// check for parameter updates
|
||||
if (_parameter_update_sub.updated()) {
|
||||
// clear update
|
||||
parameter_update_s pupdate;
|
||||
_parameter_update_sub.copy(&pupdate);
|
||||
|
||||
// update parameters from storage
|
||||
update_params();
|
||||
|
||||
// Immediately update to change brightness
|
||||
send_led_rgb();
|
||||
}
|
||||
|
||||
LedControlData led_control_data;
|
||||
|
||||
if (_led_controller.update(led_control_data) == 1) {
|
||||
@@ -267,9 +243,9 @@ RGBLED::send_led_rgb()
|
||||
{
|
||||
/* To scale from 0..255 -> 0..15 shift right by 4 bits */
|
||||
const uint8_t msg[6] = {
|
||||
SUB_ADDR_PWM0, static_cast<uint8_t>((_b >> 4) * _brightness * _max_brightness + 0.5f),
|
||||
SUB_ADDR_PWM1, static_cast<uint8_t>((_g >> 4) * _brightness * _max_brightness + 0.5f),
|
||||
SUB_ADDR_PWM2, static_cast<uint8_t>((_r >> 4) * _brightness * _max_brightness + 0.5f)
|
||||
SUB_ADDR_PWM0, static_cast<uint8_t>((_b >> 4) * _brightness + 0.5f),
|
||||
SUB_ADDR_PWM1, static_cast<uint8_t>((_g >> 4) * _brightness + 0.5f),
|
||||
SUB_ADDR_PWM2, static_cast<uint8_t>((_r >> 4) * _brightness + 0.5f)
|
||||
};
|
||||
return transfer(msg, sizeof(msg), nullptr, 0);
|
||||
}
|
||||
@@ -294,22 +270,6 @@ RGBLED::get(bool &on, bool &powersave, uint8_t &r, uint8_t &g, uint8_t &b)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
RGBLED::update_params()
|
||||
{
|
||||
int32_t maxbrt = 15;
|
||||
param_get(param_find("LED_RGB_MAXBRT"), &maxbrt);
|
||||
maxbrt = maxbrt > 15 ? 15 : maxbrt;
|
||||
maxbrt = maxbrt < 0 ? 0 : maxbrt;
|
||||
|
||||
// A minimum of 2 "on" steps is required for breathe effect
|
||||
if (maxbrt == 1) {
|
||||
maxbrt = 2;
|
||||
}
|
||||
|
||||
_max_brightness = maxbrt / 15.0f;
|
||||
}
|
||||
|
||||
void
|
||||
RGBLED::print_usage()
|
||||
{
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2015 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* @file rgbled_params.c
|
||||
*
|
||||
* Parameters defined by the RBG led driver
|
||||
*
|
||||
* @author Nate Weibley <nate.weibley@prioria.com>
|
||||
*/
|
||||
|
||||
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <parameters/param.h>
|
||||
|
||||
/**
|
||||
* RGB Led brightness limit
|
||||
*
|
||||
* Set to 0 to disable, 1 for minimum brightness up to 15 (max)
|
||||
*
|
||||
* @min 0
|
||||
* @max 15
|
||||
* @group System
|
||||
*/
|
||||
PARAM_DEFINE_INT32(LED_RGB_MAXBRT, 15);
|
||||
@@ -44,12 +44,9 @@
|
||||
|
||||
#include <drivers/device/i2c.h>
|
||||
#include <lib/led/led.h>
|
||||
#include <lib/parameters/param.h>
|
||||
#include <px4_platform_common/getopt.h>
|
||||
#include <px4_platform_common/i2c_spi_buses.h>
|
||||
#include <px4_platform_common/module.h>
|
||||
#include <uORB/SubscriptionInterval.hpp>
|
||||
#include <uORB/topics/parameter_update.h>
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
@@ -81,12 +78,10 @@ public:
|
||||
|
||||
private:
|
||||
int send_led_rgb();
|
||||
void update_params();
|
||||
|
||||
int write(uint8_t reg, uint8_t data);
|
||||
|
||||
float _brightness{1.0f};
|
||||
float _max_brightness{1.0f};
|
||||
|
||||
uint8_t _r{0};
|
||||
uint8_t _g{0};
|
||||
@@ -95,8 +90,6 @@ private:
|
||||
volatile bool _should_run{true};
|
||||
bool _leds_enabled{true};
|
||||
|
||||
uORB::SubscriptionInterval _parameter_update_sub{ORB_ID(parameter_update), 1_s};
|
||||
|
||||
LedController _led_controller;
|
||||
|
||||
uint8_t _red{NCP5623_LED_PWM0};
|
||||
@@ -154,8 +147,6 @@ RGBLED_NCP5623C::init()
|
||||
return ret;
|
||||
}
|
||||
|
||||
update_params();
|
||||
|
||||
_running = true;
|
||||
|
||||
ScheduleNow();
|
||||
@@ -180,19 +171,6 @@ RGBLED_NCP5623C::probe()
|
||||
void
|
||||
RGBLED_NCP5623C::RunImpl()
|
||||
{
|
||||
// check for parameter updates
|
||||
if (_parameter_update_sub.updated()) {
|
||||
// clear update
|
||||
parameter_update_s pupdate;
|
||||
_parameter_update_sub.copy(&pupdate);
|
||||
|
||||
// update parameters from storage
|
||||
update_params();
|
||||
|
||||
// Immediately update to change brightness
|
||||
send_led_rgb();
|
||||
}
|
||||
|
||||
LedControlData led_control_data;
|
||||
|
||||
if (_led_controller.update(led_control_data) == 1) {
|
||||
@@ -247,7 +225,7 @@ int
|
||||
RGBLED_NCP5623C::send_led_rgb()
|
||||
{
|
||||
uint8_t msg[7] = {0x20, 0x70, 0x40, 0x70, 0x60, 0x70, 0x80};
|
||||
uint8_t brightness = 0x1f * _max_brightness;
|
||||
uint8_t brightness = UINT8_MAX;
|
||||
|
||||
msg[0] = NCP5623_LED_CURRENT | (brightness & 0x1f);
|
||||
msg[2] = _red | (uint8_t(_r * _brightness) & 0x1f);
|
||||
@@ -257,21 +235,6 @@ RGBLED_NCP5623C::send_led_rgb()
|
||||
return transfer(&msg[0], 7, nullptr, 0);
|
||||
}
|
||||
|
||||
void
|
||||
RGBLED_NCP5623C::update_params()
|
||||
{
|
||||
int32_t maxbrt = 31;
|
||||
param_get(param_find("LED_RGB1_MAXBRT"), &maxbrt);
|
||||
maxbrt = maxbrt > 31 ? 31 : maxbrt;
|
||||
maxbrt = maxbrt < 0 ? 0 : maxbrt;
|
||||
|
||||
if (maxbrt == 0) {
|
||||
maxbrt = 1;
|
||||
}
|
||||
|
||||
_max_brightness = maxbrt / 31.0f;
|
||||
}
|
||||
|
||||
void
|
||||
RGBLED_NCP5623C::print_usage()
|
||||
{
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 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. Redistribution of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistribution 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* @file rgbled_ncp5623c_params.c
|
||||
*
|
||||
* Parameters defined by the RBG led driver
|
||||
*
|
||||
* @author CUAVcaijie <caijie@cuav.net>
|
||||
*/
|
||||
|
||||
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <parameters/param.h>
|
||||
|
||||
/**
|
||||
* RGB Led brightness limit
|
||||
*
|
||||
* Set to 0 to disable, 1 for minimum brightness up to 31 (max)
|
||||
*
|
||||
* @min 0
|
||||
* @max 31
|
||||
* @group System
|
||||
*/
|
||||
PARAM_DEFINE_INT32(LED_RGB1_MAXBRT, 31);
|
||||
Reference in New Issue
Block a user