..
 #############################################################
 # 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 - Piezo Speaker Bricklet

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

.. _piezo_speaker_bricklet_shell:

Shell - Piezo Speaker Bricklet
==============================

This is the description of the :ref:`Shell API bindings <api_bindings_shell>` for the :ref:`Piezo Speaker Bricklet <piezo_speaker_bricklet>`. General information and technical
specifications for the Piezo Speaker Bricklet are summarized in its :ref:`hardware description
<piezo_speaker_bricklet_description>`.

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

.. _piezo_speaker_bricklet_shell_examples:


Examples
--------

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

Beep
^^^^

`Download (example-beep.sh) <https://github.com/Tinkerforge/piezo-speaker-bricklet/raw/master/software/examples/shell/example-beep.sh>`__

.. literalinclude:: PiezoSpeaker_Bricklet_Shell_example-beep.sh
 :language: bash
 :linenos:
 :tab-width: 4

Morse Code
^^^^^^^^^^

`Download (example-morse-code.sh) <https://github.com/Tinkerforge/piezo-speaker-bricklet/raw/master/software/examples/shell/example-morse-code.sh>`__

.. literalinclude:: PiezoSpeaker_Bricklet_Shell_example-morse-code.sh
 :language: bash
 :linenos:
 :tab-width: 4

.. _piezo_speaker_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 Npiezo-speaker-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 Piezo Speaker 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 Piezo Speaker Bricklet and exits


.. sh:function:: X Stinkerforge Pdispatch Npiezo-speaker-bricklet A[<option>..] L<uid> L<callback>

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

 The ``dispatch`` command is used to dispatch a callback of the Piezo Speaker 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 Piezo Speaker Bricklet and exits


.. sh:function:: X Stinkerforge Scall Ppiezo-speaker-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 Ppiezo-speaker-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 piezo-speaker-bricklet <uid> beep <duration> <frequency> 

 :param <duration>: int (has symbols)
 :param <frequency>: int

 :noreturn: no output

 Beeps with the given frequency for the duration in ms. For example: 
 If you set a duration of 1000, with a frequency value of 2000
 the piezo buzzer will beep for one second with a frequency of
 approximately 2 kHz.
 
 .. versionchanged:: 2.0.2~(Plugin)
    A duration of 0 stops the current beep if any, the frequency parameter is
    ignored. A duration of 4294967295 results in an infinite beep.
 
 The *frequency* parameter can be set between 585 and 7100.
 
 The Piezo Speaker Bricklet can only approximate the frequency, it will play
 the best possible match by applying the calibration (see :sh:func:`calibrate <piezo-speaker-bricklet calibrate>`).
 
 The following symbols are available for this function:
 
 * ``off`` = 0, for <duration>
 * ``infinite`` = 4294967295, for <duration>
 
.. sh:function:: tinkerforge call piezo-speaker-bricklet <uid> morse-code <morse> <frequency> 

 :param <morse>: string
 :param <frequency>: int

 :noreturn: no output

 Sets morse code that will be played by the piezo buzzer. The morse code
 is given as a string consisting of "." (dot), "-" (minus) and " " (space)
 for *dits*, *dahs* and *pauses*. Every other character is ignored.
 The second parameter is the frequency (see :sh:func:`beep <piezo-speaker-bricklet beep>`).
 
 For example: If you set the string "...---...", the piezo buzzer will beep
 nine times with the durations "short short short long long long short 
 short short".
 
 The maximum string size is 60.
 


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

.. sh:function:: tinkerforge call piezo-speaker-bricklet <uid> calibrate  


 :returns calibration: bool

 The Piezo Speaker Bricklet can play 512 different tones. This function
 plays each tone and measures the exact frequency back. The result is a
 mapping between setting value and frequency. This mapping is stored
 in the EEPROM and loaded on startup.
 
 The Bricklet should come calibrated, you only need to call this
 function (once) every time you reflash the Bricklet plugin.
 
 Returns *true* after the calibration finishes.
 
.. sh:function:: tinkerforge call piezo-speaker-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|
 


.. _piezo_speaker_bricklet_shell_callbacks:

Callbacks
^^^^^^^^^

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

.. code-block:: bash

    tinkerforge dispatch piezo-speaker-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 piezo-speaker-bricklet <uid> beep-finished

 :noreturn: no output


 This callback is triggered if a beep set by :sh:func:`beep <piezo-speaker-bricklet beep>` is finished
 
.. sh:function::  tinkerforge dispatch piezo-speaker-bricklet <uid> morse-code-finished

 :noreturn: no output


 This callback is triggered if the playback of the morse code set by
 :sh:func:`morse-code <piezo-speaker-bricklet morse-code>` is finished.
 


