diff options
author | Anton Babushkin <anton.babushkin@me.com> | 2013-05-22 13:59:51 +0400 |
---|---|---|
committer | Anton Babushkin <anton.babushkin@me.com> | 2013-05-22 13:59:51 +0400 |
commit | 6e8621269bc032afdb77830cebac01808299263d (patch) | |
tree | d0e71fd33952ea4962c76d254bda43509d275c86 /src/modules/gpio_led/gpio_led.c | |
parent | 09ce3e2d0a531138c29e1d32f1a9a902b259683d (diff) | |
download | px4-firmware-6e8621269bc032afdb77830cebac01808299263d.tar.gz px4-firmware-6e8621269bc032afdb77830cebac01808299263d.tar.bz2 px4-firmware-6e8621269bc032afdb77830cebac01808299263d.zip |
Code style fixed
Diffstat (limited to 'src/modules/gpio_led/gpio_led.c')
-rw-r--r-- | src/modules/gpio_led/gpio_led.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/modules/gpio_led/gpio_led.c b/src/modules/gpio_led/gpio_led.c index 83b598e92..a80bf9cb8 100644 --- a/src/modules/gpio_led/gpio_led.c +++ b/src/modules/gpio_led/gpio_led.c @@ -53,8 +53,7 @@ #include <poll.h> #include <drivers/drv_gpio.h> -struct gpio_led_s -{ +struct gpio_led_s { struct work_s work; int gpio_fd; int pin; @@ -75,12 +74,15 @@ void gpio_led_cycle(FAR void *arg); int gpio_led_main(int argc, char *argv[]) { int pin = GPIO_EXT_1; + if (argc > 1) { if (!strcmp(argv[1], "-p")) { if (!strcmp(argv[2], "1")) { pin = GPIO_EXT_1; + } else if (!strcmp(argv[2], "2")) { pin = GPIO_EXT_2; + } else { printf("[gpio_led] Unsupported pin: %s\n", argv[2]); exit(1); @@ -91,10 +93,12 @@ int gpio_led_main(int argc, char *argv[]) memset(&gpio_led_data, 0, sizeof(gpio_led_data)); gpio_led_data.pin = pin; int ret = work_queue(LPWORK, &gpio_led_data.work, gpio_led_start, &gpio_led_data, 0); + if (ret != 0) { printf("[gpio_led] Failed to queue work: %d\n", ret); exit(1); } + exit(0); } @@ -104,6 +108,7 @@ void gpio_led_start(FAR void *arg) /* open GPIO device */ priv->gpio_fd = open(GPIO_DEVICE_PATH, 0); + if (priv->gpio_fd < 0) { printf("[gpio_led] GPIO: open fail\n"); return; @@ -118,6 +123,7 @@ void gpio_led_start(FAR void *arg) /* add worker to queue */ int ret = work_queue(LPWORK, &priv->work, gpio_led_cycle, priv, 0); + if (ret != 0) { printf("[gpio_led] Failed to queue work: %d\n", ret); return; @@ -133,23 +139,29 @@ void gpio_led_cycle(FAR void *arg) /* check for status updates*/ bool status_updated; orb_check(priv->vehicle_status_sub, &status_updated); + if (status_updated) orb_copy(ORB_ID(vehicle_status), priv->vehicle_status_sub, &priv->status); /* select pattern for current status */ int pattern = 0; + if (priv->status.flag_system_armed) { if (priv->status.battery_warning == VEHICLE_BATTERY_WARNING_NONE) { pattern = 0x3f; // ****** solid (armed) + } else { pattern = 0x2A; // *_*_*_ fast blink (armed, battery warning) } + } else { if (priv->status.state_machine == SYSTEM_STATE_PREFLIGHT) { pattern = 0x00; // ______ off (disarmed, preflight check) + } else if (priv->status.state_machine == SYSTEM_STATE_STANDBY && - priv->status.battery_warning == VEHICLE_BATTERY_WARNING_NONE) { + priv->status.battery_warning == VEHICLE_BATTERY_WARNING_NONE) { pattern = 0x38; // ***___ slow blink (disarmed, ready) + } else { pattern = 0x28; // *_*___ slow double blink (disarmed, not good to arm) } @@ -157,16 +169,20 @@ void gpio_led_cycle(FAR void *arg) /* blink pattern */ bool led_state_new = (pattern & (1 << priv->counter)) != 0; + if (led_state_new != priv->led_state) { priv->led_state = led_state_new; + if (led_state_new) { ioctl(priv->gpio_fd, GPIO_SET, priv->pin); + } else { ioctl(priv->gpio_fd, GPIO_CLEAR, priv->pin); } } priv->counter++; + if (priv->counter > 5) priv->counter = 0; |