]> www.fi.muni.cz Git - bike-lights.git/commitdiff
logic for setting brightness
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Wed, 26 Jun 2013 21:55:59 +0000 (23:55 +0200)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Wed, 26 Jun 2013 21:55:59 +0000 (23:55 +0200)
We set the brightness in an universal function pwmled_select_brightness(),
and this function is called on various events, such as
- ambient light zone change
- dim mode toggle

For now, dim mode means different brightness only for night-ish modes,
because for day modes, slow_pattern uses level 1 as main brightness.

firmware/ambient.c
firmware/control.c
firmware/lights.h

index 4818ab4a8e7a63f596103dc92afca45386c664f0..48a752d4b35bf744fcf11992684a2b1fef521e44 100644 (file)
@@ -72,18 +72,10 @@ void ambient_log_min_max()
        ambient_16drop = 0;
 }
 
-void ambient_zone_changed()
+static inline void ambient_zone_changed()
 {
-#if 1
-       log_byte(0xab);
-       log_byte(ambient_zone);
-       log_word(ambient_val);
-       log_flush();
-#endif
-
-       // led_set_pattern(N_PWMLEDS, status_led_pattern_select());
-       // led_set_pattern(N_PWMLEDS+1, illumination_led_pattern_select());
-       // pattern_reload();
+       pwmled_select_brightness();
+       pattern_reload();
 }
 
 void ambient_adc(uint16_t adcval)
@@ -116,14 +108,14 @@ void ambient_adc(uint16_t adcval)
 
        if (ambient_max < byte_val)
                ambient_max = byte_val;
-#if 0
        if (old_zone != ambient_zone) {
+#if 0
                log_byte(0xab);
                log_byte(ambient_zone);
                log_word(adcval);
                log_flush();
-       }
-               // ambient_zone_changed();
 #endif
+               ambient_zone_changed();
+       }
 }
 
index 9b356993d359f575bdc76b865fd7e6fddbe91fff..3012ba65856aaa02d9e2939ace37ed2463863da0 100644 (file)
@@ -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);
+}
index 2c06b57e910b2288d296893457f6a1ceda71e538..9d0386878bf9b79ff774a1e6de929ee74f6cb2f2 100644 (file)
@@ -141,6 +141,7 @@ pattern_t *pwmled_pattern_select();
 pattern_t *status_led_pattern_select();
 pattern_t *illumination_led_pattern_select();
 pattern_t *laser_pattern_select();
+void pwmled_select_brightness();
 
 /* main.c */
 void power_down(unsigned char err);