X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=firmware%2Fcontrol.c;h=a90bb713dfa846f9df2775b347180f8a6290d7f4;hb=4728997cb5f6eff94c8a9d9e253d1675b7516987;hp=7a8d4473c9cf52da0640e3e3870f88cd2de69711;hpb=df47dcc3b0407d6a91fa0ed8acf7a40875d855e6;p=bike-lights.git diff --git a/firmware/control.c b/firmware/control.c index 7a8d447..a90bb71 100644 --- a/firmware/control.c +++ b/firmware/control.c @@ -30,17 +30,23 @@ static pattern_t panic_pattern[] = { }; pattern_t on1_pattern [] = { - { 1, 0x10 }, + { 1, 0x7 }, PATTERN_END }; static pattern_t on2_pattern [] = { - { 2, 0x10 }, + { 2, 0x7 }, PATTERN_END }; static pattern_t on3_pattern [] = { - { 3, 0x10 }, + { 3, 0x7 }, + PATTERN_END +}; + +static pattern_t brake_pattern [] = { + { 4, 0x2 }, + { 3, 0x7 }, PATTERN_END }; @@ -48,11 +54,11 @@ static pattern_t normal2_pattern[] = { { 2, 0x1 }, { 0, 0x1 }, { 2, 0x1 }, - { 0, 0x8 }, + { 0, 0x7 }, { 1, 0x1 }, { 0, 0x1 }, { 1, 0x1 }, - { 0, 0x8 }, + { 0, 0x7 }, PATTERN_END }; @@ -60,11 +66,11 @@ static pattern_t normal3_pattern[] = { { 3, 0x1 }, { 0, 0x1 }, { 3, 0x1 }, - { 0, 0x8 }, + { 0, 0x7 }, { 1, 0x1 }, { 0, 0x1 }, { 1, 0x1 }, - { 0, 0x8 }, + { 0, 0x7 }, PATTERN_END }; @@ -72,38 +78,58 @@ static pattern_t normal4_pattern[] = { { 4, 0x1 }, { 0, 0x1 }, { 4, 0x1 }, - { 0, 0x8 }, + { 0, 0x7 }, { 1, 0x1 }, { 0, 0x1 }, { 1, 0x1 }, - { 0, 0x8 }, + { 0, 0x7 }, PATTERN_END }; static pattern_t slow1_pattern[] = { { 1, 0x01 }, - { 0, 0x10 }, + { 0, 0x7 }, + { 0, 0x7 }, PATTERN_END }; static pattern_t slow2_pattern[] = { { 2, 0x01 }, - { 0, 0x10 }, + { 0, 0x7 }, + { 0, 0x7 }, PATTERN_END }; static pattern_t slow3_pattern[] = { { 3, 0x01 }, - { 0, 0x10 }, + { 0, 0x7 }, + { 0, 0x7 }, PATTERN_END }; -static unsigned char dim_mode, towbar_mode; +static unsigned char dim_mode, towbar_mode, braking; void init_control() { dim_mode = 0; towbar_mode = 0; + braking = 0; +} + +void brake_on() +{ + braking = 1; + gpio_set(0, 1); + led_set_pattern(N_PWMLEDS, status_led_pattern_select()); + led_set_pattern(0, pwmled0_pattern_select()); +} + +void brake_off() +{ + braking = 0; + gpio_set(0, 0); + led_set_pattern(N_PWMLEDS, status_led_pattern_select()); + led_set_pattern(0, pwmled0_pattern_select()); } void toggle_dim_mode() @@ -130,10 +156,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; } @@ -187,6 +216,9 @@ pattern_t *pwmled2_pattern_select() pattern_t *status_led_pattern_select() { + if (braking) + return on1_pattern; + if (buttons_setup_in_progress()) return buttons_setup_status0_pattern_select();