]>
Commit | Line | Data |
---|---|---|
1 | ## | |
2 | ## This file is part of the sigrok-meter project. | |
3 | ## | |
4 | ## Copyright (C) 2015 Jens Steinhauser <jens.steinhauser@gmail.com> | |
5 | ## | |
6 | ## This program is free software; you can redistribute it and/or modify | |
7 | ## it under the terms of the GNU General Public License as published by | |
8 | ## the Free Software Foundation; either version 2 of the License, or | |
9 | ## (at your option) any later version. | |
10 | ## | |
11 | ## This program is distributed in the hope that it will be useful, | |
12 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | ## GNU General Public License for more details. | |
15 | ## | |
16 | ## You should have received a copy of the GNU General Public License | |
17 | ## along with this program; if not, write to the Free Software | |
18 | ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | ## | |
20 | ||
21 | import sigrok.core as sr | |
22 | ||
23 | def format_unit(u): | |
24 | units = { | |
25 | sr.Unit.VOLT: 'V', | |
26 | sr.Unit.AMPERE: 'A', | |
27 | sr.Unit.OHM: u'\u03A9', | |
28 | sr.Unit.FARAD: 'F', | |
29 | sr.Unit.KELVIN: 'K', | |
30 | sr.Unit.CELSIUS: u'\u00B0C', | |
31 | sr.Unit.FAHRENHEIT: u'\u00B0F', | |
32 | sr.Unit.HERTZ: 'Hz', | |
33 | sr.Unit.PERCENTAGE: '%', | |
34 | # sr.Unit.BOOLEAN | |
35 | sr.Unit.SECOND: 's', | |
36 | sr.Unit.SIEMENS: 'S', | |
37 | sr.Unit.DECIBEL_MW: 'dBm', | |
38 | sr.Unit.DECIBEL_VOLT: 'dBV', | |
39 | # sr.Unit.UNITLESS | |
40 | sr.Unit.DECIBEL_SPL: 'dB', | |
41 | # sr.Unit.CONCENTRATION | |
42 | sr.Unit.REVOLUTIONS_PER_MINUTE: 'rpm', | |
43 | sr.Unit.VOLT_AMPERE: 'VA', | |
44 | sr.Unit.WATT: 'W', | |
45 | sr.Unit.WATT_HOUR: 'Wh', | |
46 | sr.Unit.METER_SECOND: 'm/s', | |
47 | sr.Unit.HECTOPASCAL: 'hPa', | |
48 | sr.Unit.HUMIDITY_293K: '%rF', | |
49 | sr.Unit.DEGREE: u'\u00B0', | |
50 | sr.Unit.HENRY: 'H' | |
51 | } | |
52 | ||
53 | return units.get(u, '') | |
54 | ||
55 | def quantity_from_unit(u): | |
56 | quantities = { | |
57 | sr.Unit.VOLT: 'Voltage', | |
58 | sr.Unit.AMPERE: 'Current', | |
59 | sr.Unit.OHM: 'Resistance', | |
60 | sr.Unit.FARAD: 'Capacity', | |
61 | sr.Unit.KELVIN: 'Temperature', | |
62 | sr.Unit.CELSIUS: 'Temperature', | |
63 | sr.Unit.FAHRENHEIT: 'Temperature', | |
64 | sr.Unit.HERTZ: 'Frequency', | |
65 | sr.Unit.PERCENTAGE: 'Duty Cycle', | |
66 | sr.Unit.BOOLEAN: 'Continuity', | |
67 | sr.Unit.SECOND: 'Time', | |
68 | sr.Unit.SIEMENS: 'Conductance', | |
69 | sr.Unit.DECIBEL_MW: 'Power Ratio', | |
70 | sr.Unit.DECIBEL_VOLT: 'Voltage Ratio', | |
71 | sr.Unit.UNITLESS: 'Unitless Quantity', | |
72 | sr.Unit.DECIBEL_SPL: 'Sound Pressure', | |
73 | sr.Unit.CONCENTRATION: 'Concentration', | |
74 | sr.Unit.REVOLUTIONS_PER_MINUTE: 'Revolutions', | |
75 | sr.Unit.VOLT_AMPERE: 'Apparent Power', | |
76 | sr.Unit.WATT: 'Power', | |
77 | sr.Unit.WATT_HOUR: 'Energy', | |
78 | sr.Unit.METER_SECOND: 'Velocity', | |
79 | sr.Unit.HECTOPASCAL: 'Pressure', | |
80 | sr.Unit.HUMIDITY_293K: 'Humidity', | |
81 | sr.Unit.DEGREE: 'Angle', | |
82 | sr.Unit.HENRY: 'Inductance' | |
83 | } | |
84 | ||
85 | return quantities.get(u, '') |