#!/usr/bin/env python from sys import stdout # Table of ADC-value : Voltage tab = { # 360 : 4.2, # 352 : 4.15, # 334 : 4.1, # 322 : 4.05, # 320 : 4, # 319 : 3.95, # 318 : 3.9, 316 : 3.85, 313 : 3.8, 309 : 3.75, 300 : 3.7, 291 : 3.65, 287 : 3.6, 286 : 3.55, 282 : 3.5, 274 : 3.45, # 259 : 3.4, # 257 : 3.35, # 256 : 3.3, # 255 : 3.25, # 254 : 3.2, # 253 : 3.15, # 252 : 3.1, # 250 : 3.05, # 247 : 3, } print "/**************************" print " * THIS FILE IS GENERATED *" print " * DO NOT EDIT! *" print " **************************/" print "" print "#include " print "" print "" print "/* Analog-digital-converter-7 value to voltage table. */" col = 0 stdout.write("static const prog_uint8_t battery_adc7_tab[] = {") for i in range(min(tab), max(tab) + 1): try: volt = tab[i] except KeyError: pass value = (volt * 100) - 300 if col % 7 == 0: stdout.write("\n\t%3d," % value) else: stdout.write(" %3d," % value) col += 1 stdout.write("\n};\n\n") print "/* The ADC value that matches table index 0. */" print "#define ADC7_MIN %d" % min(tab) print "/* The ADC value that matches table index sizeof(table)-1. */" print "#define ADC7_MAX %d" % max(tab) print "/* Macro to convert a table value to millivolts. */" print "#define batt_adc7_millivolts(v) (((v) + 300) * 10)"