From f71f3426e3b3eaa7a686876f63a62589f8cc771d Mon Sep 17 00:00:00 2001 From: Dan White Date: Thu, 18 Oct 2012 13:04:26 -0500 Subject: [PATCH] To a global config instance --- python-lib/calibrate.py | 5 +++++ python-lib/devboard.py | 21 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/python-lib/calibrate.py b/python-lib/calibrate.py index 8ea42f3..a6e332e 100644 --- a/python-lib/calibrate.py +++ b/python-lib/calibrate.py @@ -390,6 +390,11 @@ while True: print '-'*80 print + #back to h[0] for consistency + mux.selA = 0 + mux.selB = 0 + mux.write() + fname = '%s.npz' % (dt.datetime.now().strftime('%Y-%m-%d_%H%M%S'), ) print '*** writing to %s ***' % fname savez(fname, diff --git a/python-lib/devboard.py b/python-lib/devboard.py index 728581a..65f0e7a 100644 --- a/python-lib/devboard.py +++ b/python-lib/devboard.py @@ -37,7 +37,6 @@ RG = { 'Vdd_ns430': 10e3, 'AVdd_atoi': 10e3 } - def count2volt(c, warn=True): """Properly handle 14-b data from 12b ADC value. Average bits originate from 12b samples, so max value is 0xfff0 NOT 0xfffc. @@ -126,7 +125,7 @@ def dump_config(): """Return a hierarchical dict of settings appropriate for passing to the individual constructors. """ - s = {} + s = _config # configuration # chip SPI config s['chain'] = chain.dump_config() @@ -154,6 +153,8 @@ def save_config(name=None): """Write current config to a file. """ cfg = dump_config() + #update global run-time storage + _config.update(cfg) if name is None: name = 'config.%s.yaml' % cfg['date'] yaml.dump(cfg, open(name, 'wb')) @@ -163,6 +164,9 @@ def save_config(name=None): # # Module-level names. Define here so they are found in the module scope # +# devboard configuration +_config = {} + spi0 = None spi1 = None i2c = None @@ -177,12 +181,20 @@ arb = None amux = None def init_devboard(name='devboard-defaults.yaml'): + """Initialize devboard <-> usbio with a known configuration. `name` may be + a string filename, defaulting to 'devboard-defaults.yaml' or an integer + representing the file 'chip%02i.calibration.yaml'. + """ global spi0, spi1, i2c global ibias, vatoi, v430 global dac, adc global chain, mux global arb, amux + # try loading config for given chip ID + if isinstance(name, int): + name = 'chip%02i.calibration.yaml' % name + try: load_config(name) return @@ -268,6 +280,7 @@ def load_config(name): else: cfg = yaml.load(open(name, 'rb')) + _config.update(cfg) ########################################################################## # Setup FTDI serial ports spi0 = usbio.SPI(**cfg['spi0']) @@ -328,6 +341,10 @@ def load_config(name): #arb = usbio.Chain(spi1, 'chain1_conf', length=16) #amux = usbio.Mux(spi1, 'chain1_mux') + #send values to chip + for f in (chain, mux, arb, amux): + f.write() + # define power supply defaults -- 2.25.1