• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python
2
3# Copyright (C) 2014 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18from abc import abstractmethod
19
20class Abstract_Power_Monitor(object):
21  """
22  Provides a simple interface to use the power meter.
23  The implementer should establish communications with the power monitor
24  on __init__:
25
26  monitor = <<Implementing Class>>(...)
27
28  Afterward, data can be collected multiple times via the
29  series of calls, for example:
30
31      montior.StartDataCollection()
32      data = True
33      while data is not None:
34          data = monitor.CollectData()
35          <<do-something-with-data>>
36      monitor.StopDataCollection()
37
38  On exit, Close should be called:
39
40      monitor.Close()
41
42  The method GetStatus() can be used to check voltage setting as well as
43  ensure status of the USB passthrough connection.
44  """
45
46
47
48  def __init__(self ):
49      pass
50
51  @abstractmethod
52  def Close(self):
53      """Close the connection to the device, preventing
54      further interactions.  This should be called only
55      when the power monitor is no longer needed
56      (e.g. on exit)
57      """
58      pass
59
60  @abstractmethod
61  def GetStatus(self):
62    """ Requests and waits for status.  Returns status dictionary.
63    This should at a minimum contain entries for "usbPassthroughMode"
64    and "outputVoltageSetting" """
65    pass
66
67  @abstractmethod
68  def SetVoltage(self, v):
69    """ Set the output voltage, 0 to disable. """
70    pass
71
72  @abstractmethod
73  def SetMaxCurrent(self, i):
74    """Set the max output current."""
75    pass
76
77  @abstractmethod
78  def SetUsbPassthrough(self, val):
79    """ Set the USB passthrough mode: 0 = off, 1 = on,  2 = auto. """
80    pass
81
82  @abstractmethod
83  def StartDataCollection(self):
84    """ Tell the device to start collecting and sending measurement data. """
85    pass
86
87  @abstractmethod
88  def StopDataCollection(self):
89    """ Tell the device to stop collecting measurement data. """
90    pass
91
92  @abstractmethod
93  def CollectData(self, verbose = True):
94    """ Return some current samples.  Call StartDataCollection() first.
95    Returns None if no data available"""
96    pass
97