1 # Copyright (C) 2011-2012 W. Trevor King <wking@tremily.us>
3 # This file is part of pypiezo.
5 # pypiezo is free software: you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation, either version 3 of the License, or (at your option) any later
10 # pypiezo is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # pypiezo. If not, see <http://www.gnu.org/licenses/>.
17 """Construct example piezo configurations to simplify testing
19 These methods make it easier to write tests in packages that depend on
23 from .base import get_axis_name as _get_axis_name
24 from .config import AxisConfig as _AxisConfig
25 from .config import InputChannelConfig as _InputChannelConfig
26 from .config import OutputChannelConfig as _OutputChannelConfig
27 from .config import PiezoConfig as _PiezoConfig
30 def get_piezo_config(storage=None):
31 """Return a default PiezoConfig instance.
33 >>> p = get_piezo_config()
34 >>> print p.dump() # doctest: +REPORT_UDIFF
49 analog-reference: ground
50 conversion-coefficients: 0, 1
52 inverse-conversion-coefficients: 0, 1
53 inverse-conversion-origin: 0
67 analog-reference: ground
68 conversion-coefficients: 0, 1
70 inverse-conversion-coefficients: 0, 1
71 inverse-conversion-origin: 0
81 analog-reference: ground
82 conversion-coefficients: 0, 1
84 inverse-conversion-coefficients: 0, 1
85 inverse-conversion-origin: 0
93 analog-reference: ground
94 conversion-coefficients: 0, 1
96 inverse-conversion-coefficients: 0, 1
97 inverse-conversion-origin: 0
98 >>> _get_axis_name(p['axes'][0])
100 >>> d = p.select_config('inputs', 'deflection')
104 piezo_config = _PiezoConfig(storage=storage)
105 piezo_config['name'] = 'test piezo'
106 piezo_config['axes'] = []
107 for i,name in enumerate(['x', 'z']):
109 axis['channel'] = _OutputChannelConfig()
110 axis['channel']['name'] = name
111 axis['channel']['channel'] = i
112 axis['channel']['maxdata'] = 100
113 axis['channel']['conversion-coefficients'] = (0,1)
114 axis['channel']['conversion-origin'] = 0
115 axis['channel']['inverse-conversion-coefficients'] = (0,1)
116 axis['channel']['inverse-conversion-origin'] = 0
117 piezo_config['axes'].append(axis)
118 piezo_config['inputs'] = []
119 for i,name in enumerate(['deflection', 'temperature']):
120 channel = _InputChannelConfig()
121 channel = _OutputChannelConfig()
122 channel['name'] = name
123 channel['channel'] = i
124 channel['maxdata'] = 100
125 channel['conversion-coefficients'] = (0,1)
126 channel['conversion-origin'] = 0
127 channel['inverse-conversion-coefficients'] = (0,1)
128 channel['inverse-conversion-origin'] = 0
129 piezo_config['inputs'].append(channel)