mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-09 05:30:35 +08:00
RGB led: Fixed code style
This commit is contained in:
@@ -135,9 +135,9 @@ extern "C" __EXPORT int rgbled_main(int argc, char *argv[]);
|
||||
RGBLED::RGBLED(int bus, int rgbled) :
|
||||
I2C("rgbled", RGBLED0_DEVICE_PATH, bus, rgbled
|
||||
#ifdef __PX4_NUTTX
|
||||
,100000 /* maximum speed supported */
|
||||
, 100000 /* maximum speed supported */
|
||||
#endif
|
||||
),
|
||||
),
|
||||
_mode(RGBLED_MODE_OFF),
|
||||
_r(0),
|
||||
_g(0),
|
||||
@@ -195,9 +195,9 @@ RGBLED::probe()
|
||||
unsigned prevretries = _retries;
|
||||
_retries = 4;
|
||||
|
||||
if ((ret=get(on, powersave, r, g, b)) != OK ||
|
||||
(ret=send_led_enable(false) != OK) ||
|
||||
(ret=send_led_enable(false) != OK)) {
|
||||
if ((ret = get(on, powersave, r, g, b)) != OK ||
|
||||
(ret = send_led_enable(false) != OK) ||
|
||||
(ret = send_led_enable(false) != OK)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -297,6 +297,7 @@ RGBLED::led()
|
||||
if (_param_sub >= 0) {
|
||||
bool updated = false;
|
||||
orb_check(_param_sub, &updated);
|
||||
|
||||
if (updated) {
|
||||
parameter_update_s pupdate;
|
||||
orb_copy(ORB_ID(parameter_update), _param_sub, &pupdate);
|
||||
@@ -310,8 +311,9 @@ RGBLED::led()
|
||||
case RGBLED_MODE_BLINK_SLOW:
|
||||
case RGBLED_MODE_BLINK_NORMAL:
|
||||
case RGBLED_MODE_BLINK_FAST:
|
||||
if (_counter >= 2)
|
||||
if (_counter >= 2) {
|
||||
_counter = 0;
|
||||
}
|
||||
|
||||
send_led_enable(_counter == 0);
|
||||
|
||||
@@ -319,8 +321,9 @@ RGBLED::led()
|
||||
|
||||
case RGBLED_MODE_BREATHE:
|
||||
|
||||
if (_counter >= 62)
|
||||
if (_counter >= 62) {
|
||||
_counter = 0;
|
||||
}
|
||||
|
||||
int n;
|
||||
|
||||
@@ -338,8 +341,9 @@ RGBLED::led()
|
||||
case RGBLED_MODE_PATTERN:
|
||||
|
||||
/* don't run out of the pattern array and stop if the next frame is 0 */
|
||||
if (_counter >= RGBLED_PATTERN_LENGTH || _pattern.duration[_counter] <= 0)
|
||||
if (_counter >= RGBLED_PATTERN_LENGTH || _pattern.duration[_counter] <= 0) {
|
||||
_counter = 0;
|
||||
}
|
||||
|
||||
set_color(_pattern.color[_counter]);
|
||||
send_led_rgb();
|
||||
@@ -549,8 +553,9 @@ RGBLED::send_led_enable(bool enable)
|
||||
{
|
||||
uint8_t settings_byte = 0;
|
||||
|
||||
if (enable)
|
||||
if (enable) {
|
||||
settings_byte |= SETTING_ENABLE;
|
||||
}
|
||||
|
||||
settings_byte |= SETTING_NOT_POWERSAVE;
|
||||
|
||||
@@ -606,6 +611,7 @@ RGBLED::update_params()
|
||||
if (maxbrt == 1) {
|
||||
maxbrt = 2;
|
||||
}
|
||||
|
||||
_max_brightness = maxbrt / 15.0f;
|
||||
}
|
||||
|
||||
@@ -629,6 +635,7 @@ rgbled_main(int argc, char *argv[])
|
||||
/* jump over start/off/etc and look at options first */
|
||||
int myoptind = 1;
|
||||
const char *myoptarg = NULL;
|
||||
|
||||
while ((ch = px4_getopt(argc, argv, "a:b:", &myoptind, &myoptarg)) != EOF) {
|
||||
switch (ch) {
|
||||
case 'a':
|
||||
@@ -645,10 +652,10 @@ rgbled_main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (myoptind >= argc) {
|
||||
rgbled_usage();
|
||||
return 1;
|
||||
}
|
||||
if (myoptind >= argc) {
|
||||
rgbled_usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *verb = argv[myoptind];
|
||||
|
||||
@@ -677,6 +684,7 @@ rgbled_main(int argc, char *argv[])
|
||||
warnx("no RGB led on bus #%d", i2cdevice);
|
||||
return 1;
|
||||
}
|
||||
|
||||
i2cdevice = PX4_I2C_BUS_LED;
|
||||
}
|
||||
}
|
||||
@@ -741,12 +749,14 @@ rgbled_main(int argc, char *argv[])
|
||||
|
||||
ret = px4_ioctl(fd, RGBLED_SET_MODE, (unsigned long)RGBLED_MODE_OFF);
|
||||
px4_close(fd);
|
||||
|
||||
/* delete the rgbled object if stop was requested, in addition to turning off the LED. */
|
||||
if (!strcmp(verb, "stop")) {
|
||||
delete g_rgbled;
|
||||
g_rgbled = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user