X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=firmware%2Fcontrol.c;h=c5ba92fe2c2e79b42fe150df6a08769cce305f02;hb=b34429defa04d493a49e24ad8840e42600bd0f28;hp=9b356993d359f575bdc76b865fd7e6fddbe91fff;hpb=dce798d0d68b014d538406085a6fb761f9393559;p=bike-lights.git diff --git a/firmware/control.c b/firmware/control.c index 9b35699..c5ba92f 100644 --- a/firmware/control.c +++ b/firmware/control.c @@ -50,12 +50,12 @@ static pattern_t fast_pattern[] = { }; static pattern_t night_pattern[] = { - { PWM_PAT(2, 0, 2), D_3 }, - { PWM_PAT(3, 0, 0), D_8 }, - { PWM_PAT(2, 0, 2), D_1 }, - { PWM_PAT(3, 0, 0), D_2 }, - { PWM_PAT(2, 0, 2), D_1 }, - { PWM_PAT(3, 0, 0), D_8 }, + { PWM_PAT(3, 0, 1), D_3 }, + { PWM_PAT(2, 0, 0), D_8 }, + { PWM_PAT(3, 0, 1), D_1 }, + { PWM_PAT(2, 0, 0), D_2 }, + { PWM_PAT(3, 0, 1), D_1 }, + { PWM_PAT(2, 0, 0), D_8 }, PATTERN_END }; @@ -83,6 +83,8 @@ void init_control() dim_mode = 0; towbar_mode = 0; braking = 0; + + pwmled_select_brightness(); } void brake_on() @@ -104,6 +106,7 @@ void brake_off() void toggle_dim_mode() { dim_mode = !dim_mode; + pwmled_select_brightness(); pattern_reload(); } @@ -172,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); +}