38 #include <px4_platform_common/getopt.h> 39 #include <px4_platform_common/module.h> 40 #include <px4_platform_common/log.h> 67 PX4_INFO(
"generating LED pattern...");
71 led_control.
mode = led_control_s::MODE_OFF;
72 led_control.
priority = led_control_s::MAX_PRIORITY;
75 px4_usleep(200 * 1000);
78 for (
int round = led_control_s::COLOR_RED; round <= led_control_s::COLOR_WHITE; ++round) {
81 led_control.
mode = led_control_s::MODE_ON;
82 led_control.
color = round;
84 px4_usleep(80 * 1000);
87 px4_usleep(100 * 1000);
90 for (
int i = 0; i < 3; ++i) {
91 led_control.
mode = led_control_s::MODE_ON;
93 px4_usleep(100 * 1000);
94 led_control.
mode = led_control_s::MODE_OFF;
96 px4_usleep(100 * 1000);
99 px4_usleep(200 * 1000);
102 px4_usleep(500 * 1000);
106 led_control.
mode = led_control_s::MODE_DISABLED;
117 const char *myoptarg =
nullptr;
118 uint8_t blink_speed = led_control_s::MODE_BLINK_NORMAL;
121 led_control.
priority = led_control_s::MAX_PRIORITY;
122 led_control.
mode = 0xff;
124 led_control.
color = led_control_s::COLOR_WHITE;
126 while ((ch = px4_getopt(argc, argv,
"c:l:n:s:p:", &myoptind, &myoptarg)) != EOF) {
129 if (!strcmp(myoptarg,
"red")) {
130 led_control.
color = led_control_s::COLOR_RED;
132 }
else if (!strcmp(myoptarg,
"blue")) {
133 led_control.
color = led_control_s::COLOR_BLUE;
135 }
else if (!strcmp(myoptarg,
"green")) {
136 led_control.
color = led_control_s::COLOR_GREEN;
138 }
else if (!strcmp(myoptarg,
"yellow")) {
139 led_control.
color = led_control_s::COLOR_YELLOW;
141 }
else if (!strcmp(myoptarg,
"purple")) {
142 led_control.
color = led_control_s::COLOR_PURPLE;
144 }
else if (!strcmp(myoptarg,
"amber")) {
145 led_control.
color = led_control_s::COLOR_AMBER;
147 }
else if (!strcmp(myoptarg,
"cyan")) {
148 led_control.
color = led_control_s::COLOR_CYAN;
150 }
else if (!strcmp(myoptarg,
"white")) {
151 led_control.
color = led_control_s::COLOR_WHITE;
161 led_control.
led_mask = 1 << strtol(myoptarg,
nullptr, 0);
165 led_control.
num_blinks = strtol(myoptarg,
nullptr, 0);
169 if (!strcmp(myoptarg,
"fast")) {
170 blink_speed = led_control_s::MODE_BLINK_FAST;
172 }
else if (!strcmp(myoptarg,
"normal")) {
173 blink_speed = led_control_s::MODE_BLINK_NORMAL;
175 }
else if (!strcmp(myoptarg,
"slow")) {
176 blink_speed = led_control_s::MODE_BLINK_SLOW;
186 led_control.
priority = strtol(myoptarg,
nullptr, 0);
196 if (led_control.
priority > led_control_s::MAX_PRIORITY) {
197 led_control.
priority = led_control_s::MAX_PRIORITY;
200 if (myoptind >= argc) {
205 if (!strcmp(argv[myoptind],
"test")) {
208 }
else if (!strcmp(argv[myoptind],
"on")) {
209 led_control.
mode = led_control_s::MODE_ON;
211 }
else if (!strcmp(argv[myoptind],
"off")) {
212 led_control.
mode = led_control_s::MODE_OFF;
214 }
else if (!strcmp(argv[myoptind],
"reset")) {
215 led_control.
mode = led_control_s::MODE_DISABLED;
217 }
else if (!strcmp(argv[myoptind],
"blink")) {
218 led_control.
mode = blink_speed;
220 }
else if (!strcmp(argv[myoptind],
"breathe")) {
221 led_control.
mode = led_control_s::MODE_BREATHE;
223 }
else if (!strcmp(argv[myoptind],
"flash")) {
224 led_control.
mode = led_control_s::MODE_FLASH;
231 if (led_control.
mode != 0xff) {
241 PRINT_MODULE_DESCRIPTION(
244 Command-line tool to control & test the (external) LED's. 246 To use it make sure there's a driver running, which handles the led_control uorb topic. 248 There are different priorities, such that for example one module can set a color with low priority, and another 249 module can blink N times with high priority, and the LED's automatically return to the lower priority state 250 after the blinking. The `reset` command can also be used to return to a lower priority. 253 Blink the first LED 5 times in blue: 254 $ led_control blink -c blue -l 0 -n 5 258 PRINT_MODULE_USAGE_NAME("led_control",
"command");
260 PRINT_MODULE_USAGE_COMMAND_DESCR(
"test",
"Run a test pattern");
261 PRINT_MODULE_USAGE_COMMAND_DESCR(
"on",
"Turn LED on");
262 PRINT_MODULE_USAGE_COMMAND_DESCR(
"off",
"Turn LED off");
263 PRINT_MODULE_USAGE_COMMAND_DESCR(
"reset",
"Reset LED priority");
264 PRINT_MODULE_USAGE_COMMAND_DESCR(
"blink",
"Blink LED N times");
265 PRINT_MODULE_USAGE_PARAM_INT(
'n', 3, 1, 20,
"Number of blinks",
true);
266 PRINT_MODULE_USAGE_PARAM_STRING(
's',
"normal",
"fast|normal|slow",
"Set blinking speed",
true);
267 PRINT_MODULE_USAGE_COMMAND_DESCR(
"breathe",
"Continuously fade LED in & out");
268 PRINT_MODULE_USAGE_COMMAND_DESCR(
"flash",
"Two fast blinks and then off with frequency of 1Hz");
270 PRINT_MODULE_USAGE_PARAM_COMMENT(
"The following arguments apply to all of the above commands except for 'test':");
271 PRINT_MODULE_USAGE_PARAM_STRING(
'c',
"white",
"red|blue|green|yellow|purple|amber|cyan|white",
"color",
true);
272 PRINT_MODULE_USAGE_PARAM_INT(
'l', -1, 0, 100,
"Which LED to control: 0, 1, 2, ... (default=all)",
true);
273 PRINT_MODULE_USAGE_PARAM_INT(
'p', 2, 0, 2,
"Priority",
true);
__EXPORT int led_control_main(int argc, char *argv[])
static led_control_s led_control
static orb_advert_t led_control_pub
static void publish_led_control(led_control_s &led_control)
High-resolution timer with callouts and timekeeping.
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
Led device API to control the external LED(s) via uORB interface.
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
static void run_led_test1()