..
 #############################################################
 # This file was automatically generated on 2015-05-08.      #
 #                                                           #
 # If you have a bugfix for this file and want to commit it, #
 # please fix the bug in the generator. You can find a link  #
 # to the generators git repository on tinkerforge.com       #
 #############################################################


:breadcrumbs: <a href="../../index.html">Home</a> / <a href="../../index.html#software-tcpip">Software</a> / TCP/IP - Distance US Bricklet

.. |device_identifier_constant| unicode:: 0xA0
   :trim:

.. _distance_us_bricklet_tcpip:

TCP/IP - Distance US Bricklet
=============================

This is the description of the :ref:`TCP/IP protocol <llproto_tcpip>` for the :ref:`Distance US Bricklet <distance_us_bricklet>`. General information and technical
specifications for the Distance US Bricklet are summarized in its :ref:`hardware description
<distance_us_bricklet_description>`.

.. _distance_us_bricklet_tcpip_api:

API
---

A general description of the TCP/IP protocol structure can be found
:ref:`here <llproto_tcpip>`.




Basic Functions
^^^^^^^^^^^^^^^



.. tcpip:function:: BrickletDistanceUS.get_distance_value

 :functionid: 1
 :emptyrequest: empty payload

 :response distance: uint16

 Returns the current distance value measured by the sensor. The value has a
 range of 0 to 4095. A small value corresponds to a small distance, a big
 value corresponds to a big distance. The relation between the measured distance
 value and the actual distance is affected by the 5V supply voltage (deviations
 in the supply voltage result in deviations in the distance values) and is
 non-linear (resolution is bigger at close range).
 
 If you want to get the distance value periodically, it is recommended to
 use the callback :tcpip:func:`CALLBACK_DISTANCE <BrickletDistanceUS.CALLBACK_DISTANCE>` and set the period with 
 :tcpip:func:`set_distance_callback_period <BrickletDistanceUS.set_distance_callback_period>`.
 


Advanced Functions
^^^^^^^^^^^^^^^^^^

.. tcpip:function:: BrickletDistanceUS.set_moving_average

 :functionid: 10
 :request average: uint8

 :noresponse: no response

 Sets the length of a `moving averaging <http://en.wikipedia.org/wiki/Moving_average>`__ 
 for the distance value.
 
 Setting the length to 0 will turn the averaging completely off. With less
 averaging, there is more noise on the data.
 
 The range for the averaging is 0-100.
 
 The default value is 20.
 
.. tcpip:function:: BrickletDistanceUS.get_moving_average

 :functionid: 11
 :emptyrequest: empty payload

 :response average: uint8

 Returns the length moving average as set by :tcpip:func:`set_moving_average <BrickletDistanceUS.set_moving_average>`.
 
.. tcpip:function:: BrickletDistanceUS.get_identity

 :functionid: 255
 :emptyrequest: empty payload

 :response uid: char[8]
 :response connected_uid: char[8]
 :response position: char
 :response hardware_version: uint8[3]
 :response firmware_version: uint8[3]
 :response device_identifier: uint16

 Returns the UID, the UID where the Bricklet is connected to, 
 the position, the hardware and firmware version as well as the
 device identifier.
 
 The position can be 'a', 'b', 'c' or 'd'.
 
 The device identifier numbers can be found :ref:`here <device_identifier>`.
 |device_identifier_constant|
 


Callback Configuration Functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



.. tcpip:function:: BrickletDistanceUS.set_distance_callback_period

 :functionid: 2
 :request period: uint32

 :noresponse: no response

 Sets the period in ms with which the :tcpip:func:`CALLBACK_DISTANCE <BrickletDistanceUS.CALLBACK_DISTANCE>` callback is triggered
 periodically. A value of 0 turns the callback off.
 
 :tcpip:func:`CALLBACK_DISTANCE <BrickletDistanceUS.CALLBACK_DISTANCE>` is only triggered if the distance value has changed since the
 last triggering.
 
 The default value is 0.
 
.. tcpip:function:: BrickletDistanceUS.get_distance_callback_period

 :functionid: 3
 :emptyrequest: empty payload

 :response period: uint32

 Returns the period as set by :tcpip:func:`set_distance_callback_period <BrickletDistanceUS.set_distance_callback_period>`.
 
.. tcpip:function:: BrickletDistanceUS.set_distance_callback_threshold

 :functionid: 4
 :request option: char
 :request min: int16
 :request max: int16

 :noresponse: no response

 Sets the thresholds for the :tcpip:func:`CALLBACK_DISTANCE_REACHED <BrickletDistanceUS.CALLBACK_DISTANCE_REACHED>` callback. 
 
 The following options are possible:
 
 .. csv-table::
  :header: "Option", "Description"
  :widths: 10, 100
 
  "'x'",    "Callback is turned off"
  "'o'",    "Callback is triggered when the distance value is *outside* the min and max values"
  "'i'",    "Callback is triggered when the distance value is *inside* the min and max values"
  "'<'",    "Callback is triggered when the distance value is smaller than the min value (max is ignored)"
  "'>'",    "Callback is triggered when the distance value is greater than the min value (max is ignored)"
 
 The default value is ('x', 0, 0).
 
.. tcpip:function:: BrickletDistanceUS.get_distance_callback_threshold

 :functionid: 5
 :emptyrequest: empty payload

 :response option: char
 :response min: int16
 :response max: int16

 Returns the threshold as set by :tcpip:func:`set_distance_callback_threshold <BrickletDistanceUS.set_distance_callback_threshold>`.
 
.. tcpip:function:: BrickletDistanceUS.set_debounce_period

 :functionid: 6
 :request debounce: uint32

 :noresponse: no response

 Sets the period in ms with which the threshold callbacks
 
 * :tcpip:func:`CALLBACK_DISTANCE_REACHED <BrickletDistanceUS.CALLBACK_DISTANCE_REACHED>`,
 
 are triggered, if the thresholds
 
 * :tcpip:func:`set_distance_callback_threshold <BrickletDistanceUS.set_distance_callback_threshold>`,
 
 keep being reached.
 
 The default value is 100.
 
.. tcpip:function:: BrickletDistanceUS.get_debounce_period

 :functionid: 7
 :emptyrequest: empty payload

 :response debounce: uint32

 Returns the debounce period as set by :tcpip:func:`set_debounce_period <BrickletDistanceUS.set_debounce_period>`.
 


.. _distance_us_bricklet_tcpip_callbacks:

Callbacks
^^^^^^^^^

.. tcpip:function:: BrickletDistanceUS.CALLBACK_DISTANCE

 :functionid: 8

 :response distance: uint16


 This callback is triggered periodically with the period that is set by
 :tcpip:func:`set_distance_callback_period <BrickletDistanceUS.set_distance_callback_period>`. The response value is the distance value
 of the sensor.
 
 :tcpip:func:`CALLBACK_DISTANCE <BrickletDistanceUS.CALLBACK_DISTANCE>` is only triggered if the distance value has changed since the
 last triggering.
 
.. tcpip:function:: BrickletDistanceUS.CALLBACK_DISTANCE_REACHED

 :functionid: 9

 :response distance: uint16


 This callback is triggered when the threshold as set by
 :tcpip:func:`set_distance_callback_threshold <BrickletDistanceUS.set_distance_callback_threshold>` is reached.
 The response value is the distance value of the sensor.
 
 If the threshold keeps being reached, the callback is triggered periodically
 with the period as set by :tcpip:func:`set_debounce_period <BrickletDistanceUS.set_debounce_period>`.
 


