^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) .. c:namespace:: RC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) .. _lirc-write:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) ************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) LIRC write()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) ************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) Name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) ====
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) lirc-write - Write to a LIRC device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) Synopsis
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) ========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) .. code-block:: c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) .. c:function:: ssize_t write( int fd, void *buf, size_t count )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) Arguments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) =========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) ``fd``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) File descriptor returned by ``open()``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) ``buf``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) Buffer with data to be written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) ``count``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) Number of bytes at the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) Description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) ===========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) :c:func:`write()` writes up to ``count`` bytes to the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) referenced by the file descriptor ``fd`` from the buffer starting at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) ``buf``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) The exact format of the data depends on what mode a driver is in, use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) :ref:`lirc_get_features` to get the supported modes and use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) :ref:`lirc_set_send_mode` set the mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) When in :ref:`LIRC_MODE_PULSE <lirc-mode-PULSE>` mode, the data written to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) the chardev is a pulse/space sequence of integer values. Pulses and spaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) are only marked implicitly by their position. The data must start and end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) with a pulse, therefore, the data must always include an uneven number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) samples. The write function blocks until the data has been transmitted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) by the hardware. If more data is provided than the hardware can send, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) driver returns ``EINVAL``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) When in :ref:`LIRC_MODE_SCANCODE <lirc-mode-scancode>` mode, one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) ``struct lirc_scancode`` must be written to the chardev at a time, else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) ``EINVAL`` is returned. Set the desired scancode in the ``scancode`` member,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) and the :ref:`IR protocol <Remote_controllers_Protocols>` in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) :c:type:`rc_proto`: member. All other members must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) set to 0, else ``EINVAL`` is returned. If there is no protocol encoder
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) for the protocol or the scancode is not valid for the specified protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ``EINVAL`` is returned. The write function blocks until the scancode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) is transmitted by the hardware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) Return Value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) ============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) On success, the number of bytes written is returned. It is not an error if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) this number is smaller than the number of bytes requested, or the amount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) of data required for one frame. On error, -1 is returned, and the ``errno``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) variable is set appropriately. The generic error codes are described at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) :ref:`Generic Error Codes <gen-errors>` chapter.