Просмотр исходного кода

Cache max brightness data from automatic controller detection

Abdullah ibn Nadjo 6 лет назад
Родитель
Сommit
6860e111a5
2 измененных файлов: 14 добавлений и 1 удалений
  1. 5
    0
      include/light.h
  2. 9
    1
      src/light.c

+ 5
- 0
include/light.h Просмотреть файл

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

+ 9
- 1
src/light.c Просмотреть файл

@@ -17,6 +17,8 @@ void light_defaultConfig()
17 17
   light_Configuration.specifiedValueRaw      = 0;
18 18
   light_Configuration.specifiedValuePercent  = 0.0;
19 19
   light_Configuration.target                 = LIGHT_BRIGHTNESS;
20
+  light_Configuration.hasCachedMaxBrightness = FALSE;
21
+  light_Configuration.cachedMaxBrightness    = 0;
20 22
   light_verbosity                            = 0;
21 23
 }
22 24
 
@@ -339,7 +341,11 @@ LIGHT_BOOL light_execute()
339 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 350
     LIGHT_ERR("could not get max brightness");
345 351
     return FALSE;
@@ -795,6 +801,8 @@ LIGHT_BOOL light_getBestController(char *controller)
795 801
         bestValYet = currVal;
796 802
         memset(bestYet, '\0', 256);
797 803
         strcpy(bestYet, light_currentController);
804
+        light_Configuration.hasCachedMaxBrightness = TRUE;
805
+        light_Configuration.cachedMaxBrightness = currVal;
798 806
         }else{
799 807
           LIGHT_NOTE("ignoring controller as better one already found");
800 808
         }