From 57a44265b81a17cae11384d983ec35fb6cffdaee Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Wed, 12 Feb 2020 12:49:40 +0100 Subject: [PATCH] api/nxtdevices: add VernierAdapter --- doc/api/nxtdevices.rst | 11 +++++++++ pybricks-projects | 2 +- pybricks/nxtdevices.py | 52 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/doc/api/nxtdevices.rst b/doc/api/nxtdevices.rst index 7ac81de..1eecbfc 100644 --- a/doc/api/nxtdevices.rst +++ b/doc/api/nxtdevices.rst @@ -54,3 +54,14 @@ NXT Temperature Sensor NXT Energy Meter ^^^^^^^^^^^^^^^^^ .. autoclass:: pybricks.nxtdevices.EnergyMeter + +Vernier Adapter +^^^^^^^^^^^^^^^^^ +.. autoclass:: pybricks.nxtdevices.VernierAdapter + +.. toggle-header:: + :header: **Show/hide example** + + **Example: Using the Surface Temperature Sensor.** + + .. literalinclude:: ../../pybricks-projects/snippets/ev3/vernier_surface_temperature/main.py diff --git a/pybricks-projects b/pybricks-projects index 5ffedc9..a18ba64 160000 --- a/pybricks-projects +++ b/pybricks-projects @@ -1 +1 @@ -Subproject commit 5ffedc9d51504041a932bcba8587b2fa2d3ee2ca +Subproject commit a18ba6499c47d2f1153fe17d2e839456e5c2075b diff --git a/pybricks/nxtdevices.py b/pybricks/nxtdevices.py index 12b8d4e..43554ea 100644 --- a/pybricks/nxtdevices.py +++ b/pybricks/nxtdevices.py @@ -1,6 +1,9 @@ """Use LEGO® MINDSTORMS® NXT motors and sensors with the EV3 brick.""" +from pybricks.iodevices import AnalogSensor + + class TouchSensor(): """LEGO® MINDSTORMS® NXT Touch Sensor.""" @@ -221,3 +224,52 @@ class EnergyMeter(): """ pass + + +class VernierAdapter(AnalogSensor): + """LEGO® MINDSTORMS® Education NXT/EV3 Adapter for Vernier Sensors.""" + + def __init__(self, port, conversion=None): + """ + + Arguments: + port (Port): Port to which the sensor is connected. + conversion (callable): Function of the format :meth:`.conversion`. + This function is used to convert the raw analog voltage to the + sensor-specific output value. Each Vernier Sensor has its + own conversion function. The example given below demonstrates + the conversion for the Surface Temperature Sensor. + """ + pass + + def voltage(self): + """Measure the raw analog sensor voltage. + + Returns: + :ref:`voltage`: Analog voltage. + """ + pass + + def conversion(self, voltage): + """User-supplied function that converts the raw voltage (mV) to a + sensor value. + + If you did not provide a ``conversion`` function earlier, no conversion + will be applied. + + Arguments: + voltage (:ref:`voltage`): Analog sensor voltage + + :returns: Converted sensor value. + :rtype: float + """ + pass + + def value(self): + """This method measures the sensor :meth:`.voltage` and then + applies your :meth:`.conversion` to give you the sensor value. + + :returns: Converted sensor value. + :rtype: float + """ + pass