Parcourir la source

Logging of clamps, saves and restores

Abdullah ibn Nadjo il y a 6 ans
Parent
révision
6180bb3f5c
3 fichiers modifiés avec 22 ajouts et 1 suppressions
  1. 5
    1
      include/helpers.h
  2. 12
    0
      src/helpers.c
  3. 5
    0
      src/light.c

+ 5
- 1
include/helpers.h Voir le fichier

@@ -13,7 +13,7 @@
13 13
  *    x;
14 14
  *  }
15 15
  * }*/
16
-#define LIGHT_CLAMP(x, y, z) ((x<y) ? y : ((x>z) ? z : x ));
16
+#define LIGHT_CLAMP(x, y, z) ((x<y) ? (light_logInfClamp(y)) : ((x>z) ? (light_logSupClamp(z)) : x ))
17 17
 
18 18
 #define LIGHT_LOG_FMT_BUF_SIZE 1024
19 19
 /* Verbosity levels: 
@@ -84,4 +84,8 @@ LIGHT_BOOL light_isWritable(char const * filename);
84 84
 /* Returns TRUE if file is readable, FALSE otherwise */
85 85
 LIGHT_BOOL light_isReadable(char const * filename);
86 86
 
87
+double light_logInfClamp(double x);
88
+
89
+double light_logSupClamp(double x);
90
+
87 91
 #endif /* LIGHT_HELPERS_H */

+ 12
- 0
src/helpers.c Voir le fichier

@@ -207,3 +207,15 @@ LIGHT_BOOL light_isReadable(char const * filename)
207 207
   fclose(fileHandle);
208 208
   return TRUE;
209 209
 }
210
+
211
+double light_logInfClamp(double x)
212
+{
213
+  LIGHT_NOTE_FMT("specified value is inferior to %g, so adjusting it to this mininum value", x);
214
+  return x;
215
+}
216
+
217
+double light_logSupClamp(double x)
218
+{
219
+  LIGHT_NOTE_FMT("specified value is superior to %g, so adjusting it to this maximum value", x);
220
+  return x;
221
+}

+ 5
- 0
src/light.c Voir le fichier

@@ -678,6 +678,7 @@ LIGHT_BOOL light_setBrightness(char const *controller, unsigned long v)
678 678
     return FALSE;
679 679
   }
680 680
 
681
+  LIGHT_NOTE_FMT("setting brightness %lu (raw) to controller", v);
681 682
   writeVal = light_writeULong(brightnessPath, v);
682 683
 
683 684
   if(!writeVal)
@@ -849,6 +850,7 @@ LIGHT_BOOL light_getMinCap(char const * controller, LIGHT_BOOL * hasMinCap, unsi
849 850
     *hasMinCap = FALSE;
850 851
     *minCap = 0;
851 852
     free(mincapPath);
853
+    LIGHT_NOTE("cap file doesn't exist or can't read from it, so assuming a minimum brightness of 0");
852 854
     return TRUE;
853 855
   }
854 856
 
@@ -874,6 +876,7 @@ LIGHT_BOOL light_setMinCap(char const * controller, unsigned long v)
874 876
     return FALSE;
875 877
   }
876 878
 
879
+  LIGHT_NOTE_FMT("setting minimum cap to %lu (raw)", v);
877 880
   if(!light_writeULong(mincapPath, v))
878 881
   {
879 882
     LIGHT_ERR("could not write to minimum cap file");
@@ -916,6 +919,7 @@ LIGHT_BOOL light_saveBrightness(char const *controller, unsigned long v){
916 919
     return FALSE;
917 920
   }
918 921
 
922
+  LIGHT_NOTE_FMT("saving brightness %lu (raw) to save file\n", v);
919 923
   if(!light_writeULong(savePath, v))
920 924
   {
921 925
     LIGHT_ERR("could not write to save/restore file");
@@ -937,6 +941,7 @@ LIGHT_BOOL light_restoreBrightness(char const *controller){
937 941
     return FALSE;
938 942
   }
939 943
 
944
+  LIGHT_NOTE("restoring brightness from saved file");
940 945
   if(!light_readULong(restorePath, &v))
941 946
   {
942 947
     LIGHT_ERR("could not read saved value");