~gabe/flashlight-firmware/anduril2

« back to all changes in this revision

Viewing changes to bin/level_calc.py

  • Committer: Selene Scriven
  • Date: 2015-10-08 03:36:32 UTC
  • mfrom: (150.1.12 sandbox)
  • Revision ID: ubuntu@toykeeper.net-20151008033632-qzq66vm22gcj94vg
merged TK refactoring effort and bistro project from sandbox:
  - reworking how common code is shared (in headers)
  - made battcheck output more values (and has more reference measurements too)
  - added new 'bistro' project
  - reworked blf-a6 to use new refactored base code
  - reworked s7 to use new refactored base code, including volts+tenths battcheck
  - made level_calc.py able to use several different curve shapes

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
 
44
44
def single_pwm(v):
45
45
    """Estimate the PWM levels for a one-channel driver."""
46
 
    visual_min = math.pow(v['lm_min'], 1.0/3)
47
 
    visual_max = math.pow(v['lm_max'], 1.0/3)
 
46
    visual_min = invpower(v['lm_min'])
 
47
    visual_max = invpower(v['lm_max'])
48
48
    step_size = (visual_max - visual_min) / (v['num_levels']-1)
49
49
    modes = []
50
50
    goal = visual_min
51
51
    for i in range(v['num_levels']):
52
 
        goal_lm = goal**3
 
52
        goal_lm = power(goal)
53
53
        #pwm_float = ((goal_lm / v['lm_max']) * (256-v['pwm_min'])) + v['pwm_min'] - 1
54
54
        pwm_float = (((goal_lm-v['lm_min']) / (v['lm_max']-v['lm_min'])) \
55
55
                        * (255-v['pwm_min'])) \
66
66
    """Estimate the PWM levels for a two-channel driver.
67
67
    Assume the first channel is the brighter one, and second will be used for moon/low modes.
68
68
    """
69
 
    visual_min = math.pow(v['lm2_min'], 1.0/3)
70
 
    visual_max = math.pow(v['lm_max'], 1.0/3)
 
69
    #visual_min = math.pow(v['lm2_min'], 1.0/power)
 
70
    #visual_max = math.pow(v['lm_max'], 1.0/power)
 
71
    visual_min = invpower(v['lm2_min'])
 
72
    visual_max = invpower(v['lm_max'])
71
73
    step_size = (visual_max - visual_min) / (v['num_levels']-1)
72
74
    modes = []
73
75
    goal = visual_min
74
76
    for i in range(v['num_levels']):
75
 
        goal_lm = goal**3
 
77
        goal_lm = power(goal)
76
78
        # Up to the second channel's limit, calculate things just like a 
77
79
        # single-channel driver (first channel will be zero)
78
80
        if goal_lm <= v['lm2_max']:
125
127
    result = result.strip()
126
128
    return result
127
129
 
 
130
def power(x):
 
131
    #return x**5
 
132
    return x**3
 
133
    #return x**2
 
134
    #return math.e**x
 
135
    #return 2.0**x
 
136
 
 
137
def invpower(x):
 
138
    #return math.pow(x, 1/5.0)
 
139
    return math.pow(x, 1/3.0)
 
140
    #return math.pow(x, 1/2.0)
 
141
    #return math.log(x, math.e)
 
142
    #return math.log(x, 2.0)
 
143
 
128
144
if __name__ == "__main__":
129
145
    import sys
130
146
    main(sys.argv[1:])