Browse Source

Exponential bright regulation

Vladimir N. Shilov 5 years ago
parent
commit
93be637462
3 changed files with 43 additions and 0 deletions
  1. BIN
      linear_led/Brightness.7z
  2. 16 0
      linear_led/cie1931.h
  3. 27 0
      linear_led/cie1931.py

BIN
linear_led/Brightness.7z


+ 16 - 0
linear_led/cie1931.h

@@ -0,0 +1,16 @@
+// CIE1931 correction table
+// Automatically generated
+
+const unsigned char cie[100] = {
+	0, 0, 1, 1, 1, 2, 2, 2, 3, 3,
+	3, 4, 4, 4, 5, 5, 6, 6, 7, 8,
+	8, 9, 10, 10, 11, 12, 13, 14, 15, 16,
+	17, 18, 19, 20, 22, 23, 24, 26, 27, 29,
+	30, 32, 34, 35, 37, 39, 41, 43, 45, 47,
+	49, 51, 54, 56, 58, 61, 64, 66, 69, 72,
+	75, 78, 81, 84, 87, 90, 93, 97, 100, 104,
+	108, 111, 115, 119, 123, 127, 131, 136, 140, 145,
+	149, 154, 159, 163, 168, 173, 179, 184, 189, 195,
+	200, 206, 212, 217, 223, 230, 236, 242, 248, 255
+};
+

+ 27 - 0
linear_led/cie1931.py

@@ -0,0 +1,27 @@
+# http://jared.geek.nz/2013/feb/linear-led-pwm
+INPUT_SIZE = 255       # Input integer size
+OUTPUT_SIZE = 255      # Output integer size
+INT_TYPE = 'const unsigned char'
+TABLE_NAME = 'cie';
+
+def cie1931(L):
+    L = L*100.0
+    if L <= 8:
+        return (L/902.3)
+    else:
+        return ((L+16.0)/116.0)**3
+
+x = range(0,int(INPUT_SIZE+1))
+y = [round(cie1931(float(L)/INPUT_SIZE)*OUTPUT_SIZE) for L in x]
+
+f = open('cie1931.h', 'w')
+f.write('// CIE1931 correction table\n')
+f.write('// Automatically generated\n\n')
+
+f.write('%s %s[%d] = {\n' % (INT_TYPE, TABLE_NAME, INPUT_SIZE+1))
+f.write('\t')
+for i,L in enumerate(y):
+    f.write('%d, ' % int(L))
+    if i % 10 == 9:
+        f.write('\n\t')
+f.write('\n};\n\n')