..
 #############################################################
 # 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-shell">Software</a> / Shell - LCD 16x2 Bricklet

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

.. _lcd_16x2_bricklet_shell:

Shell - LCD 16x2 Bricklet
=========================

This is the description of the :ref:`Shell API bindings <api_bindings_shell>` for the :ref:`LCD 16x2 Bricklet <lcd_16x2_bricklet>`. General information and technical
specifications for the LCD 16x2 Bricklet are summarized in its :ref:`hardware description
<lcd_16x2_bricklet_description>`.

An :ref:`installation guide <api_bindings_shell_install>` for the Shell API
bindings is part of their general description.

.. _lcd_16x2_bricklet_shell_examples:


Examples
--------

The example code below is `Public Domain (CC0 1.0)
<http://creativecommons.org/publicdomain/zero/1.0/>`__.

Hello World
^^^^^^^^^^^

`Download (example-hello-world.sh) <https://github.com/Tinkerforge/lcd-16x2-bricklet/raw/master/software/examples/shell/example-hello-world.sh>`__

.. literalinclude:: LCD16x2_Bricklet_Shell_example-hello-world.sh
 :language: bash
 :linenos:
 :tab-width: 4

Button Callbacks
^^^^^^^^^^^^^^^^

`Download (example-button-callbacks.sh) <https://github.com/Tinkerforge/lcd-16x2-bricklet/raw/master/software/examples/shell/example-button-callbacks.sh>`__

.. literalinclude:: LCD16x2_Bricklet_Shell_example-button-callbacks.sh
 :language: bash
 :linenos:
 :tab-width: 4

Unicode
^^^^^^^

`Download (example-unicode.sh) <https://github.com/Tinkerforge/lcd-16x2-bricklet/raw/master/software/examples/shell/example-unicode.sh>`__

.. literalinclude:: LCD16x2_Bricklet_Shell_example-unicode.sh
 :language: bash
 :linenos:
 :tab-width: 4

.. _lcd_16x2_bricklet_shell_api:

API
---

Possible exit codes for all ``tinkerforge`` commands are:

* 1: interrupted (ctrl+c)
* 2: syntax error
* 21: Python 2.5 or newer is required
* 22: Python ``argparse`` module is missing
* 23: socket error
* 24: other exception
* 25: invalid placeholder in format string
* 26: authentication error
* 201: timeout occurred
* 209: invalid argument value
* 210: function is not supported
* 211: unknown error



Command Structure
^^^^^^^^^^^^^^^^^

The common options of the ``call`` and ``dispatch`` commands are documented
:ref:`here <ipcon_shell_api>`. The specific command structure is shown below.

.. sh:function:: X Stinkerforge Pcall Nlcd-16x2-bricklet A[<option>..] L<uid> L<function> L[<argument>..]

 :param <uid>: string
 :param <function>: string

 The ``call`` command is used to call a function of the LCD 16x2 Bricklet. It can take several
 options:

 * ``--help`` shows help for the specific ``call`` command and exits
 * ``--list-functions`` shows a list of known functions of the LCD 16x2 Bricklet and exits


.. sh:function:: X Stinkerforge Pdispatch Nlcd-16x2-bricklet A[<option>..] L<uid> L<callback>

 :param <uid>: string
 :param <callback>: string

 The ``dispatch`` command is used to dispatch a callback of the LCD 16x2 Bricklet. It can
 take several options:

 * ``--help`` shows help for the specific ``dispatch`` command and exits
 * ``--list-callbacks`` shows a list of known callbacks of the LCD 16x2 Bricklet and exits


.. sh:function:: X Stinkerforge Scall Plcd-16x2-bricklet L<uid> N<function> A[<option>..] L[<argument>..]

 :param <uid>: string
 :param <function>: string

 The ``<function>`` to be called can take different options depending of its
 kind. All functions can take the following options:

 * ``--help`` shows help for the specific function and exits

 Getter functions can take the following options:

 * ``--execute <command>`` shell command line to execute for each incoming
   response (see section about :ref:`output formatting <ipcon_shell_output>`
   for details)

 Setter functions can take the following options:

 * ``--expect-response`` requests response and waits for it

 The ``--expect-response`` option for setter functions allows to detect
 timeouts and other error conditions calls of setters as well. The device will
 then send a response for this purpose. If this option is not given for a
 setter function then no response is send and errors are silently ignored,
 because they cannot be detected.


.. sh:function:: X Stinkerforge Sdispatch Plcd-16x2-bricklet L<uid> N<callback> A[<option>..]

 :param <uid>: string
 :param <callback>: string

 The ``<callback>`` to be dispatched can take several options:

 * ``--help`` shows help for the specific callback and exits
 * ``--execute <command>`` shell command line to execute for each incoming
   response (see section about :ref:`output formatting <ipcon_shell_output>`
   for details)



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



.. sh:function:: tinkerforge call lcd-16x2-bricklet <uid> write-line <line> <position> <text> 

 :param <line>: int
 :param <position>: int
 :param <text>: string

 :noreturn: no output

 Writes text to a specific line (0 to 1) with a specific position 
 (0 to 15). The text can have a maximum of 16 characters.
 
 For example: (0, 5, "Hello") will write *Hello* in the middle of the
 first line of the display.
 
 The display uses a special charset that includes all ASCII characters except
 backslash and tilde. The LCD charset also includes several other non-ASCII characters, see
 the `charset specification <https://github.com/Tinkerforge/lcd-16x2-bricklet/raw/master/datasheets/standard_charset.pdf>`__
 for details. The Unicode example above shows how to specify non-ASCII characters
 and how to translate from Unicode to the LCD charset.
 
.. sh:function:: tinkerforge call lcd-16x2-bricklet <uid> clear-display  


 :noreturn: no output

 Deletes all characters from the display.
 
.. sh:function:: tinkerforge call lcd-16x2-bricklet <uid> backlight-on  


 :noreturn: no output

 Turns the backlight on.
 
.. sh:function:: tinkerforge call lcd-16x2-bricklet <uid> backlight-off  


 :noreturn: no output

 Turns the backlight off.
 
.. sh:function:: tinkerforge call lcd-16x2-bricklet <uid> is-backlight-on  


 :returns backlight: bool

 Returns *true* if the backlight is on and *false* otherwise.
 


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

.. sh:function:: tinkerforge call lcd-16x2-bricklet <uid> set-config <cursor> <blinking> 

 :param <cursor>: bool
 :param <blinking>: bool

 :noreturn: no output

 Configures if the cursor (shown as "_") should be visible and if it
 should be blinking (shown as a blinking block). The cursor position
 is one character behind the the last text written with 
 :sh:func:`write-line <lcd-16x2-bricklet write-line>`.
 
 The default is (false, false).
 
.. sh:function:: tinkerforge call lcd-16x2-bricklet <uid> get-config  


 :returns cursor: bool
 :returns blinking: bool

 Returns the configuration as set by :sh:func:`set-config <lcd-16x2-bricklet set-config>`.
 
.. sh:function:: tinkerforge call lcd-16x2-bricklet <uid> is-button-pressed <button> 

 :param <button>: int

 :returns pressed: bool

 Returns *true* if the button (0 to 2) is pressed. If you want to react
 on button presses and releases it is recommended to use the
 :sh:func:`button-pressed <lcd-16x2-bricklet button-pressed>` and :sh:func:`button-released <lcd-16x2-bricklet button-released>` callbacks.
 
.. sh:function:: tinkerforge call lcd-16x2-bricklet <uid> set-custom-character <index> <character> 

 :param <index>: int
 :param <character>: int,int,int,int,int,int,int,int

 :noreturn: no output

 The LCD 16x2 Bricklet can store up to 8 custom characters. The characters
 consist of 5x8 pixels and can be addressed with the index 0-7. To describe
 the pixels, the first 5 bits of 8 bytes are used. For example, to make
 a custom character "H", you should transfer the following:
 
 * ``character[0] = 0b00010001`` (decimal value 17)
 * ``character[1] = 0b00010001`` (decimal value 17)
 * ``character[2] = 0b00010001`` (decimal value 17)
 * ``character[3] = 0b00011111`` (decimal value 31)
 * ``character[4] = 0b00010001`` (decimal value 17)
 * ``character[5] = 0b00010001`` (decimal value 17)
 * ``character[6] = 0b00010001`` (decimal value 17)
 * ``character[7] = 0b00000000`` (decimal value 0)
 
 The characters can later be written with :sh:func:`write-line <lcd-16x2-bricklet write-line>` by using the
 characters with the byte representation 8 to 15.
 
 You can play around with the custom characters in Brick Viewer since
 version 2.0.1.
 
 Custom characters are stored by the LCD in RAM, so they have to be set
 after each startup.
 
 .. versionadded:: 2.0.1~(Plugin)
 
.. sh:function:: tinkerforge call lcd-16x2-bricklet <uid> get-custom-character <index> 

 :param <index>: int

 :returns character: int,int,int,int,int,int,int,int

 Returns the custom character for a given index, as set with
 :sh:func:`set-custom-character <lcd-16x2-bricklet set-custom-character>`.
 
 .. versionadded:: 2.0.1~(Plugin)
 
.. sh:function:: tinkerforge call lcd-16x2-bricklet <uid> get-identity  


 :returns uid: string
 :returns connected-uid: string
 :returns position: char
 :returns hardware-version: int,int,int
 :returns firmware-version: int,int,int
 :returns device-identifier: int (has symbols)

 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|
 


.. _lcd_16x2_bricklet_shell_callbacks:

Callbacks
^^^^^^^^^

Callbacks can be used to receive time critical or recurring data from the
device:

.. code-block:: bash

    tinkerforge dispatch lcd-16x2-bricklet <uid> example

The available callbacks are described below.

.. note::
 Using callbacks for recurring events is *always* preferred
 compared to using getters. It will use less USB bandwidth and the latency
 will be a lot better, since there is no round trip time.

.. sh:function::  tinkerforge dispatch lcd-16x2-bricklet <uid> button-pressed

 :returns button: int


 This callback is triggered when a button is pressed. The parameter is
 the number of the button (0 to 2).
 
.. sh:function::  tinkerforge dispatch lcd-16x2-bricklet <uid> button-released

 :returns button: int


 This callback is triggered when a button is released. The parameter is
 the number of the button (0 to 2).
 


