Commit ede5afa9 authored by James Pallister's avatar James Pallister

Multiple points working, apart from triggers. Added some tests

parent a85cf4ad
This diff is collapsed.
......@@ -116,7 +116,7 @@ class EnergyMonitor(object):
if adc is None:
# If we want mpoint 1 or 2 and ADC3 is free, prioritise it
# becuase ADC3 doesnt work with mpoint 3 or self
if m_point in [1, 2] and self.adcMpoint[2] is not None:
if m_point in [1, 2] and self.adcMpoint[2] is None:
adc = 2
else:
adc = self.adcMpoint.index(None)
......@@ -130,6 +130,7 @@ class EnergyMonitor(object):
def disableMeasurementPoint(self, m_point):
if m_point not in self.adcMpoint:
warning("Tried to disable already disabled measurement point "+str(m_point))
return
adc = self.adcMpoint.index(m_point)
self.adcMpoint[adc] = None
# TODO: perhaps a control transfer to actually disable the mpoint
......@@ -173,9 +174,21 @@ if __name__ == "__main__":
em.toggleLEDs()
# em.enableMeasurementPoint(1)
em.enableMeasurementPoint(1)
em.enableMeasurementPoint(2)
em.setTrigger("PA0")
# em.start(1)
em.start(2)
em.start(1)
sleep(1)
em.stop(1)
em.stop(2)
# em.stop(1)
em.getMeasurement(1)
em.getMeasurement(2)
quit()
print "*** Press the blue button to make a measurement"
while True:
......
from pyenergy import EnergyMonitor
from time import sleep
resistors = [330, 330, 330]
# Check values are as expected
def checkOutput(em, m_point, time, bounds=0.05):
vals = em.getMeasurement(m_point)
# TODO check
class withMeasurementPoints(object):
def __init__(self, *args):
self.pnts = args
def __call__(self, f):
def wrap(em, *args):
for p in self.pnts:
em.enableMeasurementPoint(p)
ret = f(em, *args)
for p in self.pnts:
em.disableMeasurementPoint(p)
return ret
return wrap
@withMeasurementPoints(1, 2)
def test_1(em):
em.start(2)
em.start(1)
sleep(1)
em.stop(1)
em.stop(2)
@withMeasurementPoints(1, 2)
def test_2(em):
em.start(2)
em.start(1)
sleep(1)
em.stop(2)
em.stop(1)
@withMeasurementPoints(1, 2)
def test_3(em):
em.start(1)
sleep(0.5)
em.start(2)
sleep(0.5)
em.stop(1)
sleep(0.5)
em.stop(2)
@withMeasurementPoints(1, 2, 3)
def test_4(em):
em.start(1)
em.start(2)
em.start(3)
sleep(1)
em.stop(1)
em.stop(2)
em.stop(3)
if __name__ == "__main__":
em = EnergyMonitor("EE00")
em.connect()
em.toggleLEDs()
test_1(em)
em.getMeasurement(1)
em.getMeasurement(2)
test_2(em)
em.getMeasurement(1)
em.getMeasurement(2)
test_3(em)
em.getMeasurement(1)
em.getMeasurement(2)
test_4(em)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment