X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=firmware%2Fcontrol.c;h=a219f19205947b8a11a6b3d3ee9efb1ccad37b94;hb=8865db8363413d05d188b50b0a10928cf119f68d;hp=007a0c2883ff87d494c58192048e05615846b22f;hpb=1e3c9f876c88582e3da20a51f43d340c40c372ab;p=bike-lights.git diff --git a/firmware/control.c b/firmware/control.c index 007a0c2..a219f19 100644 --- a/firmware/control.c +++ b/firmware/control.c @@ -4,97 +4,103 @@ #include "lights.h" static pattern_t panic_pattern[] = { - { 3, 1 }, // FIXME: will be 4, but let's be safe while testing - { 0, 1 }, - { 3, 1 }, - { 0, 1 }, - { 3, 1 }, - { 0, 1 }, - { 3, 1 }, - { 0, 1 }, - { 3, 1 }, - { 0, 1 }, - { 3, 1 }, - { 0, 1 }, - { 3, 1 }, - { 0, 1 }, - { 3, 1 }, - { 0, 1 }, - { 3, 1 }, - { 0, 1 }, - { 3, 1 }, - { 0, 1 }, - { 3, 1 }, - { 0, 1 }, + { 3, D_1 }, // FIXME: will be 4, but let's be safe while testing + { 0, D_1 }, + { 3, D_1 }, + { 0, D_1 }, + { 3, D_1 }, + { 0, D_1 }, + { 3, D_1 }, + { 0, D_1 }, + { 3, D_1 }, + { 0, D_1 }, + { 3, D_1 }, + { 0, D_1 }, + { 3, D_1 }, + { 0, D_1 }, + { 3, D_1 }, + { 0, D_1 }, + { 3, D_1 }, + { 0, D_1 }, + { 3, D_1 }, + { 0, D_1 }, + { 3, D_1 }, + { 0, D_1 }, PATTERN_END }; pattern_t on1_pattern [] = { - { 1, 0x10 }, + { 1, D_8 }, PATTERN_END }; static pattern_t on2_pattern [] = { - { 2, 0x10 }, + { 2, D_8 }, PATTERN_END }; static pattern_t on3_pattern [] = { - { 3, 0x10 }, + { 3, D_8 }, + PATTERN_END +}; + +static pattern_t brake_pattern [] = { + { 4, D_2 }, + { 3, D_8 }, PATTERN_END }; static pattern_t normal2_pattern[] = { - { 2, 0x1 }, - { 0, 0x1 }, - { 2, 0x1 }, - { 0, 0x8 }, - { 1, 0x1 }, - { 0, 0x1 }, - { 1, 0x1 }, - { 0, 0x8 }, + { 2, D_1 }, + { 0, D_1 }, + { 2, D_1 }, + { 0, D_8 }, + { 1, D_1 }, + { 0, D_1 }, + { 1, D_1 }, + { 0, D_8 }, PATTERN_END }; static pattern_t normal3_pattern[] = { - { 3, 0x1 }, - { 0, 0x1 }, - { 3, 0x1 }, - { 0, 0x8 }, - { 1, 0x1 }, - { 0, 0x1 }, - { 1, 0x1 }, - { 0, 0x8 }, + { 3, D_1 }, + { 0, D_1 }, + { 3, D_1 }, + { 0, D_8 }, + { 1, D_1 }, + { 0, D_1 }, + { 1, D_1 }, + { 0, D_8 }, PATTERN_END }; static pattern_t normal4_pattern[] = { - { 4, 0x1 }, - { 0, 0x1 }, - { 4, 0x1 }, - { 0, 0x8 }, - { 1, 0x1 }, - { 0, 0x1 }, - { 1, 0x1 }, - { 0, 0x8 }, + { 4, D_1 }, + { 0, D_1 }, + { 4, D_1 }, + { 0, D_8 }, + { 1, D_1 }, + { 0, D_1 }, + { 1, D_1 }, + { 0, D_8 }, PATTERN_END }; static pattern_t slow1_pattern[] = { - { 1, 0x01 }, - { 0, 0x10 }, + { 1, D_1 }, + { 0, D_13 }, PATTERN_END }; static pattern_t slow2_pattern[] = { - { 2, 0x01 }, - { 0, 0x10 }, + { 2, D_1 }, + { 0, D_13 }, PATTERN_END }; static pattern_t slow3_pattern[] = { - { 3, 0x01 }, - { 0, 0x10 }, + { 3, D_1 }, + { 0, D_13 }, PATTERN_END }; @@ -104,6 +110,7 @@ void init_control() { dim_mode = 0; towbar_mode = 0; + braking = 0; } void brake_on() @@ -111,7 +118,7 @@ void brake_on() braking = 1; gpio_set(0, 1); led_set_pattern(N_PWMLEDS, status_led_pattern_select()); - // TODO brighten rear light + led_set_pattern(0, pwmled0_pattern_select()); } void brake_off() @@ -119,7 +126,7 @@ void brake_off() braking = 0; gpio_set(0, 0); led_set_pattern(N_PWMLEDS, status_led_pattern_select()); - // TODO dim rear light + led_set_pattern(0, pwmled0_pattern_select()); } void toggle_dim_mode() @@ -146,10 +153,13 @@ pattern_t *pwmled0_pattern_select() if (towbar_mode) return NULL; + if (braking) + return brake_pattern; + switch (ambient_zone) { - case 0: return dim_mode ? NULL : on3_pattern; - case 1: return dim_mode ? NULL : normal3_pattern; - case 2: return dim_mode ? slow3_pattern : normal3_pattern; + case 0: return dim_mode ? NULL : number_pattern(2, 1); + case 1: return dim_mode ? slow1_pattern : normal2_pattern; + case 2: return dim_mode ? slow2_pattern : normal3_pattern; case 3: default: return dim_mode ? slow3_pattern : normal4_pattern; }