mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-21 01:12:11 +00:00
rgbled_ncp5623c:Add comand line mapping of PWM to color
This commit is contained in:
committed by
Daniel Agar
parent
b961f6a1e1
commit
8e57a62c9d
@@ -68,7 +68,7 @@ using namespace time_literals;
|
||||
class RGBLED_NCP5623C : public device::I2C, public I2CSPIDriver<RGBLED_NCP5623C>
|
||||
{
|
||||
public:
|
||||
RGBLED_NCP5623C(I2CSPIBusOption bus_option, const int bus, int bus_frequency, const int address);
|
||||
RGBLED_NCP5623C(I2CSPIBusOption bus_option, const int bus, int bus_frequency, const int address, const int order);
|
||||
virtual ~RGBLED_NCP5623C() = default;
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
@@ -106,10 +106,35 @@ private:
|
||||
uint8_t _blue{NCP5623_LED_PWM2};
|
||||
};
|
||||
|
||||
RGBLED_NCP5623C::RGBLED_NCP5623C(I2CSPIBusOption bus_option, const int bus, int bus_frequency, const int address) :
|
||||
RGBLED_NCP5623C::RGBLED_NCP5623C(I2CSPIBusOption bus_option, const int bus, int bus_frequency, const int address,
|
||||
const int order) :
|
||||
I2C(DRV_LED_DEVTYPE_RGBLED_NCP5623C, MODULE_NAME, bus, address, bus_frequency),
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus, address)
|
||||
{
|
||||
int ordering = order;
|
||||
// ordering is RGB: Hundreds is Red, Tens is green and ones is Blue
|
||||
// 123 would drive the
|
||||
// R LED from = NCP5623_LED_PWM0
|
||||
// G LED from = NCP5623_LED_PWM1
|
||||
// B LED from = NCP5623_LED_PWM2
|
||||
// 321 would drive the
|
||||
// R LED from = NCP5623_LED_PWM2
|
||||
// G LED from = NCP5623_LED_PWM1
|
||||
// B LED from = NCP5623_LED_PWM0
|
||||
const uint8_t sig[] = {NCP5623_LED_PWM0, NCP5623_LED_PWM1, NCP5623_LED_PWM2};
|
||||
// Process ordering in lsd to msd order.(BGR)
|
||||
uint8_t *color[] = {&_blue, &_green, &_red };
|
||||
unsigned int s = 0;
|
||||
|
||||
for (unsigned int i = 0; i < arraySize(color); i++) {
|
||||
s = (ordering % 10) - 1;
|
||||
|
||||
if (s < arraySize(sig)) {
|
||||
*color[i] = sig[s];
|
||||
}
|
||||
|
||||
ordering /= 10;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
@@ -150,11 +175,6 @@ RGBLED_NCP5623C::probe()
|
||||
if (status == PX4_ERROR) {
|
||||
set_device_address(NCP5623B_ADDR);
|
||||
status = write(NCP5623_LED_CURRENT, NCP5623_LED_OFF);
|
||||
|
||||
if (status == PX4_OK) {
|
||||
_red = NCP5623_LED_PWM2;
|
||||
_blue = NCP5623_LED_PWM0;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -262,6 +282,7 @@ RGBLED_NCP5623C::print_usage()
|
||||
PRINT_MODULE_USAGE_COMMAND("start");
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x39);
|
||||
PRINT_MODULE_USAGE_PARAM_INT('o', 123, 123, 321, "RGB PWM Assignment", true);
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
@@ -269,7 +290,7 @@ I2CSPIDriverBase *RGBLED_NCP5623C::instantiate(const BusCLIArguments &cli, const
|
||||
int runtime_instance)
|
||||
{
|
||||
RGBLED_NCP5623C *instance = new RGBLED_NCP5623C(iterator.configuredBusOption(), iterator.bus(), cli.bus_frequency,
|
||||
cli.i2c_address);
|
||||
cli.i2c_address, cli.custom1);
|
||||
|
||||
if (instance == nullptr) {
|
||||
PX4_ERR("alloc failed");
|
||||
@@ -290,8 +311,18 @@ extern "C" __EXPORT int rgbled_ncp5623c_main(int argc, char *argv[])
|
||||
BusCLIArguments cli{true, false};
|
||||
cli.default_i2c_frequency = 100000;
|
||||
cli.i2c_address = NCP5623C_ADDR;
|
||||
cli.custom1 = 123;
|
||||
int ch;
|
||||
|
||||
const char *verb = cli.parseDefaultArguments(argc, argv);
|
||||
while ((ch = cli.getOpt(argc, argv, "o:")) != EOF) {
|
||||
switch (ch) {
|
||||
case 'o':
|
||||
cli.custom1 = atoi(cli.optArg());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const char *verb = cli.optArg();
|
||||
|
||||
if (!verb) {
|
||||
ThisDriver::print_usage();
|
||||
|
||||
Reference in New Issue
Block a user