~gabe/flashlight-firmware/anduril2

« back to all changes in this revision

Viewing changes to ToyKeeper/battcheck/battcheck.py

  • Committer: Selene Scriven
  • Date: 2017-09-12 23:34:36 UTC
  • mto: (188.1.3 trunk)
  • mto: This revision was merged to the branch mainline in revision 331.
  • Revision ID: bzr@toykeeper.net-20170912233436-d3w6nln0ts1subue
Added Flintrock's Bistro-HD 1.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
def main(args):
 
4
    """Very simple script to guess at driver ADC values for useful voltages,
 
5
    based on readings taken at other voltages.
 
6
    """
 
7
    measurements = {}
 
8
    readings_path = args[0]
 
9
    for line in open(readings_path):
 
10
        if line.startswith('#'):
 
11
            continue
 
12
        line = line.strip()
 
13
        print('Line: %s' % (line))
 
14
        parts = line.split()
 
15
        if line.endswith('V'):
 
16
            blinks = int(parts[0])
 
17
            volts = float(parts[2][:-1])
 
18
            measurements[volts] = blinks
 
19
 
 
20
    v_lowest = min(measurements.keys())
 
21
    v_highest = max(measurements.keys())
 
22
    b_lowest = measurements[v_lowest]
 
23
    b_highest = measurements[v_highest]
 
24
    v_range = v_highest - v_lowest
 
25
    b_range = b_highest - b_lowest
 
26
    b_per_v = b_range / v_range
 
27
    v_per_b = v_range / b_range
 
28
 
 
29
    #for target_v in [4.20, 4.00, 3.80, 3.50, 3.00, 2.80, 2.70]:
 
30
    for target_v in range(44, 19, -1):
 
31
        target_v = target_v / 10.0
 
32
        volts = target_v - v_lowest
 
33
        blinks = b_lowest + (b_per_v * volts)
 
34
        #print('%.2f - %.2fV' % (blinks, target_v))
 
35
        print('#define ADC_%i     %i' % (target_v * 10, round(blinks)))
 
36
 
 
37
if __name__ == "__main__":
 
38
    import sys
 
39
    main(sys.argv[1:])
 
40