Browse Source

Cache max brightness data from automatic controller detection

Abdullah ibn Nadjo 7 years ago
parent
commit
6860e111a5
2 changed files with 14 additions and 1 deletions
  1. 5
    0
      include/light.h
  2. 9
    1
      src/light.c

+ 5
- 0
include/light.h View File

89
   double          specifiedValuePercent; /* The specified value in percent */
89
   double          specifiedValuePercent; /* The specified value in percent */
90
 
90
 
91
   LIGHT_TARGET    target;
91
   LIGHT_TARGET    target;
92
+
93
+  /* Cache data */
94
+  LIGHT_BOOL      hasCachedMaxBrightness;
95
+  unsigned long   cachedMaxBrightness;
96
+
92
 } light_runtimeArguments, *light_runtimeArguments_p;
97
 } light_runtimeArguments, *light_runtimeArguments_p;
93
 
98
 
94
 /* -- Global variables that handles iterating controllers -- */
99
 /* -- Global variables that handles iterating controllers -- */

+ 9
- 1
src/light.c View File

17
   light_Configuration.specifiedValueRaw      = 0;
17
   light_Configuration.specifiedValueRaw      = 0;
18
   light_Configuration.specifiedValuePercent  = 0.0;
18
   light_Configuration.specifiedValuePercent  = 0.0;
19
   light_Configuration.target                 = LIGHT_BRIGHTNESS;
19
   light_Configuration.target                 = LIGHT_BRIGHTNESS;
20
+  light_Configuration.hasCachedMaxBrightness = FALSE;
21
+  light_Configuration.cachedMaxBrightness    = 0;
20
   light_verbosity                            = 0;
22
   light_verbosity                            = 0;
21
 }
23
 }
22
 
24
 
339
     return FALSE;
341
     return FALSE;
340
   }
342
   }
341
 
343
 
342
-  if(!light_getMaxBrightness(light_Configuration.specifiedController, &rawMax))
344
+  if(light_Configuration.hasCachedMaxBrightness)
345
+  {
346
+    rawMax = light_Configuration.cachedMaxBrightness;
347
+  }
348
+  else if(!light_getMaxBrightness(light_Configuration.specifiedController, &rawMax))
343
   {
349
   {
344
     LIGHT_ERR("could not get max brightness");
350
     LIGHT_ERR("could not get max brightness");
345
     return FALSE;
351
     return FALSE;
795
         bestValYet = currVal;
801
         bestValYet = currVal;
796
         memset(bestYet, '\0', 256);
802
         memset(bestYet, '\0', 256);
797
         strcpy(bestYet, light_currentController);
803
         strcpy(bestYet, light_currentController);
804
+        light_Configuration.hasCachedMaxBrightness = TRUE;
805
+        light_Configuration.cachedMaxBrightness = currVal;
798
         }else{
806
         }else{
799
           LIGHT_NOTE("ignoring controller as better one already found");
807
           LIGHT_NOTE("ignoring controller as better one already found");
800
         }
808
         }