]> oss.titaniummirror.com Git - rgblamp.git/blobdiff - rgb.h
Perceived intensities via the CIE Lighting formula
[rgblamp.git] / rgb.h
diff --git a/rgb.h b/rgb.h
index 4456c8075bd500d6a855c42be3cddf033165a363..b2149edfaffd1786bf89066bfeb0bce5084495e3 100644 (file)
--- a/rgb.h
+++ b/rgb.h
 
 #include "isr.h"
 
+/* Optional brightness compensation.  Pick zero or one */
+#define CEIL256
+#undef CEIL32
+
 /* Initialize the RGB LED assembly.  Outputs are zero, PWM is off. */
 void rgb_init();
 
@@ -20,6 +24,28 @@ void rgb_init();
 void rgb_off();
 
 /* Set a PWM value for each color LED.  0=off, 255=full on. */
+#ifdef CEIL256
+extern const unsigned char pwm_table[];
+#define rgb_set(red, grn, blu, wht) do { \
+    ndi(); /* FIXME: doesn't seem to fix flicker */ \
+    CCPR3L = pwm_table[(red)]; \
+    CCPR2L = pwm_table[(grn)]; \
+    CCPR4L = pwm_table[(blu)]; \
+    CCPR1L = pwm_table[(wht)]; \
+    nei(); \
+} while (0)
+#else
+#ifdef CEIL32
+extern const unsigned char pwm_table[];
+#define rgb_set(red, grn, blu, wht) do { \
+    ndi(); /* FIXME: doesn't seem to fix flicker */ \
+    CCPR3L = pwm_table[(red) >> 3]; \
+    CCPR2L = pwm_table[(grn) >> 3]; \
+    CCPR4L = pwm_table[(blu) >> 3]; \
+    CCPR1L = pwm_table[(wht) >> 3]; \
+    nei(); \
+} while (0)
+#else
 #define rgb_set(red, grn, blu, wht) do { \
     ndi(); /* FIXME: doesn't seem to fix flicker */ \
     CCPR3L = (red); \
@@ -28,5 +54,7 @@ void rgb_off();
     CCPR1L = (wht); \
     nei(); \
 } while (0)
+#endif
+#endif
 
 #endif