X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=bike-lights.git;a=blobdiff_plain;f=firmware%2Fcontrol.c;h=3012ba65856aaa02d9e2939ace37ed2463863da0;hp=8477722f86bd8095d461af75735c90e991b6c4c1;hb=94524330d5709845fe0bbe8562fd68deedcb818c;hpb=15758319e9901ada7e67a7c0c3288e53d803f059 diff --git a/firmware/control.c b/firmware/control.c index 8477722..3012ba6 100644 --- a/firmware/control.c +++ b/firmware/control.c @@ -64,6 +64,17 @@ pattern_t on_pattern[] = { PATTERN_END }; +// #define TEST_PATTERN 1 +#ifdef TEST_PATTERN +pattern_t test_pattern[] = { + { PWM_PAT(1, 0, 0), D_13 }, + { PWM_PAT(2, 0, 0), D_13 }, + { PWM_PAT(0, 0, 1), D_13 }, + { PWM_PAT(0, 0, 2), D_13 }, + PATTERN_END +}; +#endif + volatile unsigned char braking; static unsigned char dim_mode, towbar_mode; @@ -72,6 +83,8 @@ void init_control() dim_mode = 0; towbar_mode = 0; braking = 0; + + pwmled_select_brightness(); } void brake_on() @@ -93,6 +106,7 @@ void brake_off() void toggle_dim_mode() { dim_mode = !dim_mode; + pwmled_select_brightness(); pattern_reload(); } @@ -104,6 +118,9 @@ void set_panic_mode() pattern_t *pwmled_pattern_select() { +#ifdef TEST_PATTERN + return tmp_pattern; +#endif if (battery_critical) return slow_pattern; @@ -158,3 +175,23 @@ pattern_t *laser_pattern_select() else return NULL; } + +void pwmled_select_brightness() +{ + uint16_t brightness = PWMLED_BRIGHTNESS(0, 2, 1, 0, 2); // default + + if (battery_critical) { + brightness = PWMLED_BRIGHTNESS(0, 0, 0, 0, 0); + } else if (ambient_zone < 2) { + if (dim_mode) + brightness = PWMLED_BRIGHTNESS(0, 1, 0, 0, 1); + else + brightness = PWMLED_BRIGHTNESS(0, 2, 1, 0, 2); + } else if (ambient_zone == 2) { + brightness = PWMLED_BRIGHTNESS(1, 3, 2, 1, 3); + } else if (ambient_zone == 3) { + brightness = PWMLED_BRIGHTNESS(2, 4, 2, 2, 4); + } + + pwmled_set_brightness(brightness); +}