[tuxdroid-svn] r981 - software_suite_v2/middleware/tuxdriver/trunk/src
Status: Beta
Brought to you by:
ks156
From: eFfeM <c2m...@c2...> - 2008-04-20 11:41:42
|
Author: eFfeM Date: 2008-04-20 13:41:47 +0200 (Sun, 20 Apr 2008) New Revision: 981 Modified: software_suite_v2/middleware/tuxdriver/trunk/src/tux_leds.c Log: cleanup, includes, split one function in two Modified: software_suite_v2/middleware/tuxdriver/trunk/src/tux_leds.c =================================================================== --- software_suite_v2/middleware/tuxdriver/trunk/src/tux_leds.c 2008-04-20 11:22:44 UTC (rev 980) +++ software_suite_v2/middleware/tuxdriver/trunk/src/tux_leds.c 2008-04-20 11:41:47 UTC (rev 981) @@ -23,13 +23,11 @@ #include <stdlib.h> #include <string.h> +#include "tux_hw_cmd.h" #include "tux_hw_status.h" +#include "tux_leds.h" #include "tux_sw_status.h" #include "tux_usb.h" -#include "tux_hw_cmd.h" -#include "tux_leds.h" -#include "tux_cmd_parser.h" -#include "tux_usb.h" typedef enum { @@ -58,9 +56,13 @@ /* Get on / off state */ if (hw_status_table.led.left_led_intensity < 50) + { left_led_state = OFF; + } else + { left_led_state = ON; + } /* Get changing state */ if (hw_status_table.led.effect_status.bits.left_led_fading || @@ -87,7 +89,9 @@ /* Check if the state have changed */ if (strcmp(new_left_state, old_left_state)) + { tux_sw_status_set_value(SW_ID_LEFT_LED_STATE, (void *)new_left_state, true); + } } /** @@ -101,9 +105,13 @@ /* Get on / off state */ if (hw_status_table.led.right_led_intensity < 50) + { right_led_state = OFF; + } else + { right_led_state = ON; + } /* Get changing state */ if (hw_status_table.led.effect_status.bits.right_led_fading || @@ -130,8 +138,10 @@ /* Check if the state have changed */ if (strcmp(new_right_state, old_right_state)) + { tux_sw_status_set_value(SW_ID_RIGHT_LED_STATE, (void *)new_right_state, true); + } } /** Default settings for the fading effect. */ @@ -213,19 +223,28 @@ /* Preconditions. */ if (delta <= 0) + { delta = 1; + } if (delta > 255) + { delta = 255; + } delay = (unsigned char)roundf(gradient_delay / FW_MAIN_LOOP_DELAY); /* Can't go infinitely fast. */ if (delay == 0) + { delay = 1; + } + /* Hardware doesn't support longer delays, we should do them with multiple * commands if necessary. XXX Not supported for now. */ if (delay > 255) + { delay = 255; + } frame[0] = LED_FADE_SPEED_CMD; frame[1] = leds; @@ -323,8 +342,10 @@ right_intensity_delta); } if (skip) + { /* Nothing to do then. */ return ret; + } } break; case FADE_RATE: @@ -349,13 +370,19 @@ /* Preconditions */ if (effect->step <= 0) + { effect->step = 1; + } if (effect->step > 255) + { effect->step = 255; + } /* We should use effect NONE if we don't want gradient. */ if (effect->speed <= 0) + { effect->speed = 0.1; + } /* Don't divide by zero if there's nothing to do ;-). */ if (leds & LED_LEFT && left_intensity_delta) @@ -364,7 +391,9 @@ delta = (int)roundf(left_intensity_delta / effect->step); /* If we can't have as many steps as required. */ if (delta == 0) + { delta = 1; + } ret = config_gradient(LED_LEFT, delta, effect->speed/effect->step); } @@ -374,13 +403,17 @@ delta = (int)roundf(right_intensity_delta / effect->step); /* If we can't have as many steps as required. */ if (delta == 0) + { delta = 1; + } ret = config_gradient(LED_RIGHT, delta, effect->speed/effect->step); } if (skip) + { /* Nothing to do then. */ return ret; + } } break; case GRADIENT_DELTA: @@ -391,32 +424,40 @@ /* Preconditions */ if (effect->step <= 0) + { effect->step = 1; + } if (effect->step > 255) + { effect->step = 255; + } /* We should use effect NONE if we don't want gradient. */ if (effect->speed <= 0) + { effect->speed = 0.1; + } /* Don't divide by zero if there's nothing to do ;-). */ if (leds & LED_LEFT && left_intensity_delta) { skip = false; - gradient_delay = effect->speed * effect->step / \ + gradient_delay = effect->speed * effect->step / left_intensity_delta; ret = config_gradient(LED_LEFT, effect->step, gradient_delay); } if (leds & LED_RIGHT && right_intensity_delta) { skip = false; - gradient_delay = effect->speed * effect->step / \ + gradient_delay = effect->speed * effect->step / right_intensity_delta; ret = config_gradient(LED_RIGHT, effect->step, gradient_delay); } if (skip) + { /* Nothing to do then. */ return ret; + } } break; default: @@ -444,14 +485,28 @@ /* Preconditions */ if (leds < LED_NONE) + { leds = LED_NONE; - else if (leds > LED_BOTH) - leds = LED_BOTH; + } + else + { + if (leds > LED_BOTH) + { + leds = LED_BOTH; + } + } if (intensity < 0) + { intensity = 0; - else if (intensity > 255) - intensity = 255; + } + else + { + if (intensity > 255) + { + intensity = 255; + } + } left_intensity_delta = abs(intensity - hw_status_table.led.left_led_intensity); right_intensity_delta = abs(intensity - hw_status_table.led.right_led_intensity); @@ -494,37 +549,71 @@ /* Preconditions */ if (leds < LED_NONE) + { leds = LED_NONE; - else if (leds > LED_BOTH) - leds = LED_BOTH; + } + else + { + if (leds > LED_BOTH) + { + leds = LED_BOTH; + } + } if (min_intensity < 0) + { min_intensity = 0; - else if (min_intensity > 255) - min_intensity = 255; + } + else + { + if (min_intensity > 255) + { + min_intensity = 255; + } + } if (max_intensity < 0) + { max_intensity = 0; - else if (max_intensity > 255) - max_intensity = 255; + } + else + { + if (max_intensity > 255) + { + max_intensity = 255; + } + } if (min_intensity > max_intensity) + { min_intensity = max_intensity; + } if (pulse_period <= 0) + { pulse_period = 1; + } if (toggle_count <= 0) + { toggle_count = 1; + } delta = max_intensity - min_intensity; ret = led_configure_effects(leds, delta, delta, effect); pulse_width = (int)roundf(pulse_period/FW_MAIN_LOOP_DELAY/2); if (pulse_width < 1) + { pulse_width = 1; - if (pulse_width > 255) - pulse_width = 255; + } + else + { + if (pulse_width > 255) + { + pulse_width = 255; + } + } frame[0] = LED_PULSE_RANGE_CMD; frame[1] = leds; @@ -545,33 +634,66 @@ /** * */ -LIBLOCAL unsigned char -conststr_to_val(char *conststr) +static unsigned char +conststr_to_ledval(char *conststr) { if (!strcmp(conststr, "LED_NONE")) - return 0; + { + return 0; + } if (!strcmp(conststr, "LED_LEFT")) + { return 1; + } if (!strcmp(conststr, "LED_RIGHT")) + { return 2; + } if (!strcmp(conststr, "LED_BOTH")) + { return 3; + } + return 0; +} + +/** + * + */ +static unsigned char +conststr_to_effectval(char *conststr) +{ if (!strcmp(conststr, "UNAFFECTED")) + { return 0; + } if (!strcmp(conststr, "LAST")) + { return 1; + } if (!strcmp(conststr, "NONE")) + { return 2; + } if (!strcmp(conststr, "DEFAULT")) + { return 3; + } if (!strcmp(conststr, "FADE_DURATION")) + { return 4; + } if (!strcmp(conststr, "FADE_RATE")) + { return 5; + } if (!strcmp(conststr, "GRADIENT_NBR")) + { return 6; + } if (!strcmp(conststr, "GRADIENT_DELTA")) + { return 7; + } return 0; } @@ -592,25 +714,36 @@ unsigned char e_st = 2; bool ret = true; - lds = conststr_to_val(leds); + lds = conststr_to_ledval(leds); ret = str_to_float(intensity, &intsty); - e_t = conststr_to_val(effect_type); + e_t = conststr_to_effectval(effect_type); ret &= str_to_float(effect_speed, &e_sp); ret &= str_to_uint8(effect_step, &e_st); if (!ret) + { return false; + } effect.type = e_t; effect.speed = e_sp; effect.step = e_st; if (intsty < 0) + { intsty2 = 0; - else if (intsty > 1.0) - intsty2 = 255; + } else - intsty2 = (int)(255 * intsty); + { + if (intsty > 1.0) + { + intsty2 = 255; + } + else + { + intsty2 = (int)(255 * intsty); + } + } return led_set(lds, intsty2, &effect); } @@ -637,8 +770,8 @@ float p_period = 0.3; bool ret = true; - lds = conststr_to_val(leds); - e_t = conststr_to_val(effect_type); + lds = conststr_to_ledval(leds); + e_t = conststr_to_effectval(effect_type); ret = str_to_float(min_intensity, &min_intsty); ret &= str_to_float(max_intensity, &max_intsty); ret &= str_to_float(effect_speed, &e_sp); @@ -647,25 +780,45 @@ ret &= str_to_float(pulse_period, &p_period); if (!ret) + { return false; + } effect.type = e_t; effect.speed = e_sp; effect.step = e_st; if (min_intsty < 0) + { min_intsty2 = 0; - else if (min_intsty > 1.0) - min_intsty2 = 255; + } else - min_intsty2 = (int)(255 * min_intsty); + { + if (min_intsty > 1.0) + { + min_intsty2 = 255; + } + else + { + min_intsty2 = (int)(255 * min_intsty); + } + } if (max_intsty < 0) + { max_intsty2 = 0; - else if (max_intsty > 1.0) - max_intsty2 = 255; + } else - max_intsty2 = (int)(255 * max_intsty); + { + if (max_intsty > 1.0) + { + max_intsty2 = 255; + } + else + { + max_intsty2 = (int)(255 * max_intsty); + } + } return led_pulse(lds, min_intsty2, max_intsty2, p_count, p_period, &effect); |