Chromium Code Reviews| 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 | 6 |
| 7 http://msoon.com/LabEquipment/PowerMonitor/ | 7 http://msoon.com/LabEquipment/PowerMonitor/ |
| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 return status | 149 return status |
| 150 | 150 |
| 151 | 151 |
| 152 def SetVoltage(self, v): | 152 def SetVoltage(self, v): |
| 153 """Set the output voltage, 0 to disable.""" | 153 """Set the output voltage, 0 to disable.""" |
| 154 if v == 0: | 154 if v == 0: |
| 155 self._SendStruct('BBB', 0x01, 0x01, 0x00) | 155 self._SendStruct('BBB', 0x01, 0x01, 0x00) |
| 156 else: | 156 else: |
| 157 self._SendStruct('BBB', 0x01, 0x01, int((v - 2.0) * 100)) | 157 self._SendStruct('BBB', 0x01, 0x01, int((v - 2.0) * 100)) |
| 158 | 158 |
| 159 def SetStartupCurrent(self, i): | |
| 160 """Set the max startup output current.""" | |
|
tonyg
2015/03/17 13:58:28
It'd be nice if this explain the units of |i| -- m
JungJik
2015/03/18 10:21:28
Done.
| |
| 161 assert i >= 0 and i <= 8 | |
| 162 | |
| 163 val = 1023 - int((i/8)*1023) | |
|
tonyg
2015/03/17 13:58:28
I don't think this does what you want.
JungJik
2015/03/18 10:21:28
PTAL again.
it looks like confusing |i| as integer
| |
| 164 self._SendStruct('BBB', 0x01, 0x08, val & 0xff) | |
| 165 self._SendStruct('BBB', 0x01, 0x09, val >> 8) | |
| 159 | 166 |
| 160 def SetMaxCurrent(self, i): | 167 def SetMaxCurrent(self, i): |
| 161 """Set the max output current.""" | 168 """Set the max output current.""" |
| 162 assert i >= 0 and i <= 8 | 169 assert i >= 0 and i <= 8 |
| 163 | 170 |
| 164 val = 1023 - int((i/8)*1023) | 171 val = 1023 - int((i/8)*1023) |
| 165 self._SendStruct('BBB', 0x01, 0x0a, val & 0xff) | 172 self._SendStruct('BBB', 0x01, 0x0a, val & 0xff) |
| 166 self._SendStruct('BBB', 0x01, 0x0b, val >> 8) | 173 self._SendStruct('BBB', 0x01, 0x0b, val >> 8) |
| 167 | 174 |
| 168 def SetUsbPassthrough(self, val): | 175 def SetUsbPassthrough(self, val): |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 logging.error('exception from serial port') | 286 logging.error('exception from serial port') |
| 280 return None | 287 return None |
| 281 elif len(ready_r) > 0: | 288 elif len(ready_r) > 0: |
| 282 flushed += 1 | 289 flushed += 1 |
| 283 self.ser.read(1) # This may cause underlying buffering. | 290 self.ser.read(1) # This may cause underlying buffering. |
| 284 self.ser.flush() # Flush the underlying buffer too. | 291 self.ser.flush() # Flush the underlying buffer too. |
| 285 else: | 292 else: |
| 286 break | 293 break |
| 287 if flushed > 0: | 294 if flushed > 0: |
| 288 logging.debug('dropped >%d bytes', flushed) | 295 logging.debug('dropped >%d bytes', flushed) |
| OLD | NEW |