Browse Source

Logging of clamps, saves and restores

Abdullah ibn Nadjo 7 years ago
parent
commit
6180bb3f5c
3 changed files with 22 additions and 1 deletions
  1. 5
    1
      include/helpers.h
  2. 12
    0
      src/helpers.c
  3. 5
    0
      src/light.c

+ 5
- 1
include/helpers.h View File

13
  *    x;
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
 #define LIGHT_LOG_FMT_BUF_SIZE 1024
18
 #define LIGHT_LOG_FMT_BUF_SIZE 1024
19
 /* Verbosity levels: 
19
 /* Verbosity levels: 
84
 /* Returns TRUE if file is readable, FALSE otherwise */
84
 /* Returns TRUE if file is readable, FALSE otherwise */
85
 LIGHT_BOOL light_isReadable(char const * filename);
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
 #endif /* LIGHT_HELPERS_H */
91
 #endif /* LIGHT_HELPERS_H */

+ 12
- 0
src/helpers.c View File

207
   fclose(fileHandle);
207
   fclose(fileHandle);
208
   return TRUE;
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 View File

678
     return FALSE;
678
     return FALSE;
679
   }
679
   }
680
 
680
 
681
+  LIGHT_NOTE_FMT("setting brightness %lu (raw) to controller", v);
681
   writeVal = light_writeULong(brightnessPath, v);
682
   writeVal = light_writeULong(brightnessPath, v);
682
 
683
 
683
   if(!writeVal)
684
   if(!writeVal)
849
     *hasMinCap = FALSE;
850
     *hasMinCap = FALSE;
850
     *minCap = 0;
851
     *minCap = 0;
851
     free(mincapPath);
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
     return TRUE;
854
     return TRUE;
853
   }
855
   }
854
 
856
 
874
     return FALSE;
876
     return FALSE;
875
   }
877
   }
876
 
878
 
879
+  LIGHT_NOTE_FMT("setting minimum cap to %lu (raw)", v);
877
   if(!light_writeULong(mincapPath, v))
880
   if(!light_writeULong(mincapPath, v))
878
   {
881
   {
879
     LIGHT_ERR("could not write to minimum cap file");
882
     LIGHT_ERR("could not write to minimum cap file");
916
     return FALSE;
919
     return FALSE;
917
   }
920
   }
918
 
921
 
922
+  LIGHT_NOTE_FMT("saving brightness %lu (raw) to save file\n", v);
919
   if(!light_writeULong(savePath, v))
923
   if(!light_writeULong(savePath, v))
920
   {
924
   {
921
     LIGHT_ERR("could not write to save/restore file");
925
     LIGHT_ERR("could not write to save/restore file");
937
     return FALSE;
941
     return FALSE;
938
   }
942
   }
939
 
943
 
944
+  LIGHT_NOTE("restoring brightness from saved file");
940
   if(!light_readULong(restorePath, &v))
945
   if(!light_readULong(restorePath, &v))
941
   {
946
   {
942
     LIGHT_ERR("could not read saved value");
947
     LIGHT_ERR("could not read saved value");