aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorSelene ToyKeeper2015-04-06 15:29:04 -0600
committerSelene ToyKeeper2015-04-06 15:29:04 -0600
commitf850c38952a7b1004c09ae6843cf805df3276a84 (patch)
tree6e669903ac8660306c0f606b990ba9d64fae183b /bin
parentImproved info for Windows users in the README. (diff)
downloadanduril-f850c38952a7b1004c09ae6843cf805df3276a84.tar.gz
anduril-f850c38952a7b1004c09ae6843cf805df3276a84.tar.bz2
anduril-f850c38952a7b1004c09ae6843cf805df3276a84.zip
Moved level_calc.py to bin/ since it's useful for general purposes.
Made level_calc.py prompt the user for input interactively, or get values from the command line if possible.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/level_calc.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/bin/level_calc.py b/bin/level_calc.py
new file mode 100755
index 0000000..c792bba
--- /dev/null
+++ b/bin/level_calc.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+
+import math
+
+def main(args):
+ """Calculates PWM levels for visually-linear steps.
+ """
+ # Get parameters from the user
+ v = dict()
+ questions = [
+ (int, 'pwm_min', 6, 'Lowest visible PWM level, for moon mode:'),
+ (float, 'lm_min', 0.25, 'How bright is moon mode, in lumens?'),
+ (int, 'pwm_max', 255, 'Highest PWM level:'),
+ (float, 'lm_max', 1000, 'How bright is the highest level, in lumens?'),
+ (int, 'num_levels', 4, 'How many total levels do you want?'),
+ ]
+ for typ, name, default, text in questions:
+ value = get_value(text, default, args)
+ if not value:
+ value = default
+ else:
+ value = typ(value)
+ v[name] = value
+
+ # change these values for each device:
+ #pwm_min = 0 # lowest visible PWM level, for moon mode
+ #lm_min = 10.0 # how bright is moon mode, in lumens?
+ #pwm_max = 255 # highest PWM level
+ #lm_max = 1300 # how bright is the highest level, in lumens?
+ #num_levels = 4 # how many total levels do you want?
+
+ # The rest should work fine without changes
+ visual_min = math.pow(v['lm_min'], 1.0/3)
+ visual_max = math.pow(v['lm_max'], 1.0/3)
+ step_size = (visual_max - visual_min) / (v['num_levels']-1)
+ modes = []
+ goal = visual_min
+ for i in range(v['num_levels']):
+ pwm_float = (((goal**3) / v['lm_max']) * (256-v['pwm_min'])) + v['pwm_min'] - 1
+ pwm = int(round(pwm_float))
+ pwm = max(min(pwm,v['pwm_max']),v['pwm_min'])
+ modes.append(pwm)
+ print '%i: visually %.2f (%.2f lm): %.2f/255' % (i+1, goal, goal ** 3, pwm_float)
+ goal += step_size
+
+ print 'PWM values:', ','.join([str(i) for i in modes])
+
+def get_value(text, default, args):
+ if args:
+ result = args[0]
+ del args[0]
+ else:
+ print text, '(%s)' % (default),
+ result = raw_input()
+ result = result.strip()
+ return result
+
+if __name__ == "__main__":
+ import sys
+ main(sys.argv[1:])
+
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.