OLD | NEW |
---|---|
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Interface for a USB-connected Monsoon power meter | 5 """Interface for a USB-connected Monsoon power meter |
6 (http://msoon.com/LabEquipment/PowerMonitor/). | 6 (http://msoon.com/LabEquipment/PowerMonitor/). |
7 | 7 |
8 Currently Unix-only. Relies on fcntl, /dev, and /tmp. | 8 Currently Unix-only. Relies on fcntl, /dev, and /tmp. |
9 """ | 9 """ |
10 | 10 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 if self._last_seq and seq & 0xF != (self._last_seq + 1) & 0xF: | 192 if self._last_seq and seq & 0xF != (self._last_seq + 1) & 0xF: |
193 logging.info('data sequence skipped, lost packet?') | 193 logging.info('data sequence skipped, lost packet?') |
194 self._last_seq = seq | 194 self._last_seq = seq |
195 | 195 |
196 if packet_type == 0: | 196 if packet_type == 0: |
197 if not self._coarse_scale or not self._fine_scale: | 197 if not self._coarse_scale or not self._fine_scale: |
198 logging.info('waiting for calibration, dropped data packet') | 198 logging.info('waiting for calibration, dropped data packet') |
199 continue | 199 continue |
200 | 200 |
201 out = [] | 201 out = [] |
202 for main, usb, _, voltage in data: | 202 for main, usb, _, _ in data: |
203 main_voltage_v = self._voltage_multiplier * (voltage & ~3) | |
204 sample = 0.0 | 203 sample = 0.0 |
205 if main & 1: | 204 if main & 1: |
206 sample += ((main & ~1) - self._coarse_zero) * self._coarse_scale | 205 sample += ((main & ~1) - self._coarse_zero) * self._coarse_scale |
207 else: | 206 else: |
208 sample += (main - self._fine_zero) * self._fine_scale | 207 sample += (main - self._fine_zero) * self._fine_scale |
209 if usb & 1: | 208 if usb & 1: |
210 sample += ((usb & ~1) - self._coarse_zero) * self._coarse_scale | 209 sample += ((usb & ~1) - self._coarse_zero) * self._coarse_scale |
211 else: | 210 else: |
212 sample += (usb - self._fine_zero) * self._fine_scale | 211 sample += (usb - self._fine_zero) * self._fine_scale |
213 out.append((sample, main_voltage_v)) | 212 out.append(sample) |
dtu
2014/03/03 23:24:48
I've got another patch for this: https://coderevie
tonyg
2014/03/08 17:30:03
If you rebase, the changes in this file should no
| |
214 return out | 213 return out |
215 | 214 |
216 elif packet_type == 1: | 215 elif packet_type == 1: |
217 self._fine_zero = data[0][0] | 216 self._fine_zero = data[0][0] |
218 self._coarse_zero = data[1][0] | 217 self._coarse_zero = data[1][0] |
219 | 218 |
220 elif packet_type == 2: | 219 elif packet_type == 2: |
221 self._fine_ref = data[0][0] | 220 self._fine_ref = data[0][0] |
222 self._coarse_ref = data[1][0] | 221 self._coarse_ref = data[1][0] |
223 | 222 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 logging.error('exception from serial port') | 271 logging.error('exception from serial port') |
273 return None | 272 return None |
274 elif len(ready_r) > 0: | 273 elif len(ready_r) > 0: |
275 flushed += 1 | 274 flushed += 1 |
276 self.ser.read(1) # This may cause underlying buffering. | 275 self.ser.read(1) # This may cause underlying buffering. |
277 self.ser.flush() # Flush the underlying buffer too. | 276 self.ser.flush() # Flush the underlying buffer too. |
278 else: | 277 else: |
279 break | 278 break |
280 if flushed > 0: | 279 if flushed > 0: |
281 logging.debug('dropped >%d bytes', flushed) | 280 logging.debug('dropped >%d bytes', flushed) |
OLD | NEW |