..
 #############################################################
 # 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 - Joystick Bricklet

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

.. _joystick_bricklet_tcpip:

TCP/IP - Joystick Bricklet
==========================

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

.. _joystick_bricklet_tcpip_api:

API
---

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




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



.. tcpip:function:: BrickletJoystick.get_position

 :functionid: 1
 :emptyrequest: empty payload

 :response x: int16
 :response y: int16

 Returns the position of the Joystick. The value ranges between -100 and
 100 for both axis. The middle position of the joystick is x=0, y=0. The
 returned values are averaged and calibrated (see :tcpip:func:`calibrate <BrickletJoystick.calibrate>`).
 
 If you want to get the position periodically, it is recommended to use the
 callback :tcpip:func:`CALLBACK_POSITION <BrickletJoystick.CALLBACK_POSITION>` and set the period with 
 :tcpip:func:`set_position_callback_period <BrickletJoystick.set_position_callback_period>`.
 
.. tcpip:function:: BrickletJoystick.is_pressed

 :functionid: 2
 :emptyrequest: empty payload

 :response pressed: bool

 Returns *true* if the button is pressed and *false* otherwise.
 
 It is recommended to use the :tcpip:func:`CALLBACK_PRESSED <BrickletJoystick.CALLBACK_PRESSED>` and :tcpip:func:`CALLBACK_RELEASED <BrickletJoystick.CALLBACK_RELEASED>` callbacks
 to handle the button.
 


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

.. tcpip:function:: BrickletJoystick.get_analog_value

 :functionid: 3
 :emptyrequest: empty payload

 :response x: uint16
 :response y: uint16

 Returns the values as read by a 12-bit analog-to-digital converter.
 The values are between 0 and 4095 for both axis.
 
 .. note::
  The values returned by :tcpip:func:`get_position <BrickletJoystick.get_position>` are averaged over several samples
  to yield less noise, while :tcpip:func:`get_analog_value <BrickletJoystick.get_analog_value>` gives back raw
  unfiltered analog values. The only reason to use :tcpip:func:`get_analog_value <BrickletJoystick.get_analog_value>` is,
  if you need the full resolution of the analog-to-digital converter.
 
 If you want the analog values periodically, it is recommended to use the 
 callback :tcpip:func:`CALLBACK_ANALOG_VALUE <BrickletJoystick.CALLBACK_ANALOG_VALUE>` and set the period with 
 :tcpip:func:`set_analog_value_callback_period <BrickletJoystick.set_analog_value_callback_period>`.
 
.. tcpip:function:: BrickletJoystick.calibrate

 :functionid: 4
 :emptyrequest: empty payload

 :noresponse: no response

 Calibrates the middle position of the Joystick. If your Joystick Bricklet
 does not return x=0 and y=0 in the middle position, call this function
 while the Joystick is standing still in the middle position.
 
 The resulting calibration will be saved on the EEPROM of the Joystick
 Bricklet, thus you only have to calibrate it once.
 
.. tcpip:function:: BrickletJoystick.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:: BrickletJoystick.set_position_callback_period

 :functionid: 5
 :request period: uint32

 :noresponse: no response

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

 :functionid: 6
 :emptyrequest: empty payload

 :response period: uint32

 Returns the period as set by :tcpip:func:`set_position_callback_period <BrickletJoystick.set_position_callback_period>`.
 
.. tcpip:function:: BrickletJoystick.set_analog_value_callback_period

 :functionid: 7
 :request period: uint32

 :noresponse: no response

 Sets the period in ms with which the :tcpip:func:`CALLBACK_ANALOG_VALUE <BrickletJoystick.CALLBACK_ANALOG_VALUE>` callback is triggered
 periodically. A value of 0 turns the callback off.
 
 :tcpip:func:`CALLBACK_ANALOG_VALUE <BrickletJoystick.CALLBACK_ANALOG_VALUE>` is only triggered if the analog values have changed since the
 last triggering.
 
 The default value is 0.
 
.. tcpip:function:: BrickletJoystick.get_analog_value_callback_period

 :functionid: 8
 :emptyrequest: empty payload

 :response period: uint32

 Returns the period as set by :tcpip:func:`set_analog_value_callback_period <BrickletJoystick.set_analog_value_callback_period>`.
 
.. tcpip:function:: BrickletJoystick.set_position_callback_threshold

 :functionid: 9
 :request option: char
 :request min_x: int16
 :request max_x: int16
 :request min_y: int16
 :request max_y: int16

 :noresponse: no response

 Sets the thresholds for the :tcpip:func:`CALLBACK_POSITION_REACHED <BrickletJoystick.CALLBACK_POSITION_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 position is *outside* the min and max values"
  "'i'",    "Callback is triggered when the position is *inside* the min and max values"
  "'<'",    "Callback is triggered when the position is smaller than the min values (max is ignored)"
  "'>'",    "Callback is triggered when the position is greater than the min values (max is ignored)"
 
 The default value is ('x', 0, 0, 0, 0).
 
.. tcpip:function:: BrickletJoystick.get_position_callback_threshold

 :functionid: 10
 :emptyrequest: empty payload

 :response option: char
 :response min_x: int16
 :response max_x: int16
 :response min_y: int16
 :response max_y: int16

 Returns the threshold as set by :tcpip:func:`set_position_callback_threshold <BrickletJoystick.set_position_callback_threshold>`.
 
.. tcpip:function:: BrickletJoystick.set_analog_value_callback_threshold

 :functionid: 11
 :request option: char
 :request min_x: uint16
 :request max_x: uint16
 :request min_y: uint16
 :request max_y: uint16

 :noresponse: no response

 Sets the thresholds for the :tcpip:func:`CALLBACK_ANALOG_VALUE_REACHED <BrickletJoystick.CALLBACK_ANALOG_VALUE_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 analog values are *outside* the min and max values"
  "'i'",    "Callback is triggered when the analog values are *inside* the min and max values"
  "'<'",    "Callback is triggered when the analog values are smaller than the min values (max is ignored)"
  "'>'",    "Callback is triggered when the analog values are greater than the min values (max is ignored)"
 
 The default value is ('x', 0, 0, 0, 0).
 
.. tcpip:function:: BrickletJoystick.get_analog_value_callback_threshold

 :functionid: 12
 :emptyrequest: empty payload

 :response option: char
 :response min_x: uint16
 :response max_x: uint16
 :response min_y: uint16
 :response max_y: uint16

 Returns the threshold as set by :tcpip:func:`set_analog_value_callback_threshold <BrickletJoystick.set_analog_value_callback_threshold>`.
 
.. tcpip:function:: BrickletJoystick.set_debounce_period

 :functionid: 13
 :request debounce: uint32

 :noresponse: no response

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

 :functionid: 14
 :emptyrequest: empty payload

 :response debounce: uint32

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


.. _joystick_bricklet_tcpip_callbacks:

Callbacks
^^^^^^^^^

.. tcpip:function:: BrickletJoystick.CALLBACK_POSITION

 :functionid: 15

 :response x: int16
 :response y: int16


 This callback is triggered periodically with the period that is set by
 :tcpip:func:`set_position_callback_period <BrickletJoystick.set_position_callback_period>`. The response value is the position of the
 Joystick.
 
 :tcpip:func:`CALLBACK_POSITION <BrickletJoystick.CALLBACK_POSITION>` is only triggered if the position has changed since the
 last triggering.
 
.. tcpip:function:: BrickletJoystick.CALLBACK_ANALOG_VALUE

 :functionid: 16

 :response x: uint16
 :response y: uint16


 This callback is triggered periodically with the period that is set by
 :tcpip:func:`set_analog_value_callback_period <BrickletJoystick.set_analog_value_callback_period>`. The response values are the analog values
 of the Joystick.
 
 :tcpip:func:`CALLBACK_ANALOG_VALUE <BrickletJoystick.CALLBACK_ANALOG_VALUE>` is only triggered if the values have changed since the
 last triggering.
 
.. tcpip:function:: BrickletJoystick.CALLBACK_POSITION_REACHED

 :functionid: 17

 :response x: int16
 :response y: int16


 This callback is triggered when the threshold as set by
 :tcpip:func:`set_position_callback_threshold <BrickletJoystick.set_position_callback_threshold>` is reached.
 The response values are the position of the Joystick.
 
 If the threshold keeps being reached, the callback is triggered periodically
 with the period as set by :tcpip:func:`set_debounce_period <BrickletJoystick.set_debounce_period>`.
 
.. tcpip:function:: BrickletJoystick.CALLBACK_ANALOG_VALUE_REACHED

 :functionid: 18

 :response x: uint16
 :response y: uint16


 This callback is triggered when the threshold as set by
 :tcpip:func:`set_analog_value_callback_threshold <BrickletJoystick.set_analog_value_callback_threshold>` is reached.
 The response values are the analog values of the Joystick.
 
 If the threshold keeps being reached, the callback is triggered periodically
 with the period as set by :tcpip:func:`set_debounce_period <BrickletJoystick.set_debounce_period>`.
 
.. tcpip:function:: BrickletJoystick.CALLBACK_PRESSED

 :functionid: 19

 :emptyresponse: empty payload


 This callback is triggered when the button is pressed.
 
.. tcpip:function:: BrickletJoystick.CALLBACK_RELEASED

 :functionid: 20

 :emptyresponse: empty payload


 This callback is triggered when the button is released.
 


