Browse Source

Unconfigurable smooth brightness changes

Forces brightness to always change gradually in 20 steps, with a delay of 10 milliseconds between each step. This is a preliminary proof-of-concept until both values are made configurable.
Nicola Sorace 4 years ago
parent
commit
34b158166a
1 changed files with 28 additions and 1 deletions
  1. 28
    1
      src/light.c

+ 28
- 1
src/light.c View File

17
 
17
 
18
 /* Static helper functions for this file only, prefix with _ */
18
 /* Static helper functions for this file only, prefix with _ */
19
 
19
 
20
+// Changes brightness smoothly from start value to end value
21
+static void _fade_value(light_device_target_t *target, uint64_t start_value, uint64_t end_value)
22
+{
23
+    int steps = 20;
24
+    uint64_t step_size = (uint64_t) ( ((float)end_value - (float)start_value) / (float)steps );
25
+
26
+    for(int i=1; i<steps-1; i++)
27
+    {
28
+      target->set_value(target, start_value + i * step_size);
29
+      usleep(10000);
30
+    }
31
+}
20
 
32
 
21
 static void _light_add_enumerator_device(light_device_enumerator_t *enumerator, light_device_t *new_device)
33
 static void _light_add_enumerator_device(light_device_enumerator_t *enumerator, light_device_t *new_device)
22
 {
34
 {
721
         return false;
733
         return false;
722
     }
734
     }
723
     
735
     
724
-    
725
     uint64_t mincap = _light_get_min_cap(ctx);
736
     uint64_t mincap = _light_get_min_cap(ctx);
726
     uint64_t value = ctx->run_params.value;
737
     uint64_t value = ctx->run_params.value;
727
     if(mincap > value)
738
     if(mincap > value)
728
     {
739
     {
729
         value = mincap;
740
         value = mincap;
730
     }
741
     }
742
+
743
+    uint64_t start_value;
744
+    target->get_value(target, &start_value);
745
+    _fade_value(target, start_value, value);
731
     
746
     
732
     if(!target->set_value(target, value))
747
     if(!target->set_value(target, value))
733
     {
748
     {
899
         value = max_value;
914
         value = max_value;
900
     }
915
     }
901
     
916
     
917
+    uint64_t start_value;
918
+    target->get_value(target, &start_value);
919
+    _fade_value(target, start_value, value);
920
+
902
     if(!target->set_value(target, value))
921
     if(!target->set_value(target, value))
903
     {
922
     {
904
         LIGHT_ERR("failed to write to target");
923
         LIGHT_ERR("failed to write to target");
939
         value = mincap;
958
         value = mincap;
940
     }
959
     }
941
 
960
 
961
+    uint64_t start_value;
962
+    target->get_value(target, &start_value);
963
+    _fade_value(target, start_value, value);
964
+
942
     if(!target->set_value(target, value))
965
     if(!target->set_value(target, value))
943
     {
966
     {
944
         LIGHT_ERR("failed to write to target");
967
         LIGHT_ERR("failed to write to target");
994
         value = max_value;
1017
         value = max_value;
995
     }
1018
     }
996
 
1019
 
1020
+    uint64_t start_value;
1021
+    target->get_value(target, &start_value);
1022
+    _fade_value(target, start_value, value);
1023
+
997
     if(!target->set_value(target, value))
1024
     if(!target->set_value(target, value))
998
     {
1025
     {
999
         LIGHT_ERR("failed to write to target");
1026
         LIGHT_ERR("failed to write to target");