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=007a0c2883ff87d494c58192048e05615846b22f;hp=eb35aca947ba3be71a0b2b53bb58d96e5e7ad7cd;hb=1e3c9f876c88582e3da20a51f43d340c40c372ab;hpb=9a376291d21ae17ba19b72be055534f425d24431 diff --git a/firmware/control.c b/firmware/control.c index eb35aca..007a0c2 100644 --- a/firmware/control.c +++ b/firmware/control.c @@ -30,15 +30,18 @@ static pattern_t panic_pattern[] = { }; pattern_t on1_pattern [] = { - { 1, PATTERN_FOREVER } + { 1, 0x10 }, + PATTERN_END }; static pattern_t on2_pattern [] = { - { 2, PATTERN_FOREVER } + { 2, 0x10 }, + PATTERN_END }; static pattern_t on3_pattern [] = { - { 3, PATTERN_FOREVER } + { 3, 0x10 }, + PATTERN_END }; static pattern_t normal2_pattern[] = { @@ -95,7 +98,7 @@ static pattern_t slow3_pattern[] = { PATTERN_END }; -static unsigned char dim_mode, towbar_mode; +static unsigned char dim_mode, towbar_mode, braking; void init_control() { @@ -103,6 +106,22 @@ void init_control() towbar_mode = 0; } +void brake_on() +{ + braking = 1; + gpio_set(0, 1); + led_set_pattern(N_PWMLEDS, status_led_pattern_select()); + // TODO brighten rear light +} + +void brake_off() +{ + braking = 0; + gpio_set(0, 0); + led_set_pattern(N_PWMLEDS, status_led_pattern_select()); + // TODO dim rear light +} + void toggle_dim_mode() { dim_mode = !dim_mode; @@ -121,19 +140,16 @@ void set_panic_mode() pattern_t *pwmled0_pattern_select() { - // TODO: battery critical - -#ifndef TESTING_FW - return normal3_pattern; -#endif + if (battery_critical) + return on1_pattern; if (towbar_mode) return NULL; switch (ambient_zone) { - case 0: return dim_mode ? NULL : on1_pattern; - case 1: return dim_mode ? NULL : slow2_pattern; - case 2: return dim_mode ? slow3_pattern : slow2_pattern; + 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 3: default: return dim_mode ? slow3_pattern : normal4_pattern; } @@ -141,11 +157,13 @@ pattern_t *pwmled0_pattern_select() pattern_t *pwmled1_pattern_select() { - // TODO: battery critical - #ifndef TESTING_FW - return off_pattern; + return NULL; +#else + if (battery_critical) + return on1_pattern; #endif + if (towbar_mode) { switch (ambient_zone) { case 0: @@ -168,11 +186,11 @@ pattern_t *pwmled1_pattern_select() pattern_t *pwmled2_pattern_select() { - // TODO: battery critical - #ifndef TESTING_FW - return on3_pattern; + if (battery_critical) + return on1_pattern; #endif + switch (ambient_zone) { case 0: return dim_mode ? on2_pattern : on3_pattern; case 1: return dim_mode ? slow1_pattern : normal2_pattern; @@ -185,16 +203,20 @@ 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(); // FIXME: do something sane - return number_pattern(1 + ambient_zone, 0); + return number_pattern(battery_gauge(), 0); } pattern_t *illumination_led_pattern_select() { - // todo: battery critical + if (battery_critical) + return NULL; switch (ambient_zone) { case 0: return dim_mode @@ -204,12 +226,19 @@ pattern_t *illumination_led_pattern_select() ? number_pattern(2, 1) : number_pattern(3, 1); case 2: return dim_mode - ? number_pattern(3, 0) - : number_pattern(4, 0); + ? number_pattern(1, 0) + : number_pattern(2, 0); case 3: default: return dim_mode - ? number_pattern(5, 0) - : number_pattern(6, 0); + ? number_pattern(3, 0) + : number_pattern(4, 0); } } +pattern_t *laser_pattern_select() +{ + if (!dim_mode && ambient_zone <= 1) + return number_pattern(2, 1); + else + return NULL; +}