18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
28c2ecf20Sopenharmony_ci.. c:namespace:: RC
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci.. _lirc-write:
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci************
78c2ecf20Sopenharmony_ciLIRC write()
88c2ecf20Sopenharmony_ci************
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ciName
118c2ecf20Sopenharmony_ci====
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_cilirc-write - Write to a LIRC device
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciSynopsis
168c2ecf20Sopenharmony_ci========
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci.. code-block:: c
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci    #include <unistd.h>
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci.. c:function:: ssize_t write( int fd, void *buf, size_t count )
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ciArguments
258c2ecf20Sopenharmony_ci=========
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci``fd``
288c2ecf20Sopenharmony_ci    File descriptor returned by ``open()``.
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci``buf``
318c2ecf20Sopenharmony_ci    Buffer with data to be written
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci``count``
348c2ecf20Sopenharmony_ci    Number of bytes at the buffer
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ciDescription
378c2ecf20Sopenharmony_ci===========
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci:c:func:`write()` writes up to ``count`` bytes to the device
408c2ecf20Sopenharmony_cireferenced by the file descriptor ``fd`` from the buffer starting at
418c2ecf20Sopenharmony_ci``buf``.
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ciThe exact format of the data depends on what mode a driver is in, use
448c2ecf20Sopenharmony_ci:ref:`lirc_get_features` to get the supported modes and use
458c2ecf20Sopenharmony_ci:ref:`lirc_set_send_mode` set the mode.
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ciWhen in :ref:`LIRC_MODE_PULSE <lirc-mode-PULSE>` mode, the data written to
488c2ecf20Sopenharmony_cithe chardev is a pulse/space sequence of integer values. Pulses and spaces
498c2ecf20Sopenharmony_ciare only marked implicitly by their position. The data must start and end
508c2ecf20Sopenharmony_ciwith a pulse, therefore, the data must always include an uneven number of
518c2ecf20Sopenharmony_cisamples. The write function blocks until the data has been transmitted
528c2ecf20Sopenharmony_ciby the hardware. If more data is provided than the hardware can send, the
538c2ecf20Sopenharmony_cidriver returns ``EINVAL``.
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ciWhen in :ref:`LIRC_MODE_SCANCODE <lirc-mode-scancode>` mode, one
568c2ecf20Sopenharmony_ci``struct lirc_scancode`` must be written to the chardev at a time, else
578c2ecf20Sopenharmony_ci``EINVAL`` is returned. Set the desired scancode in the ``scancode`` member,
588c2ecf20Sopenharmony_ciand the :ref:`IR protocol <Remote_controllers_Protocols>` in the
598c2ecf20Sopenharmony_ci:c:type:`rc_proto`: member. All other members must be
608c2ecf20Sopenharmony_ciset to 0, else ``EINVAL`` is returned. If there is no protocol encoder
618c2ecf20Sopenharmony_cifor the protocol or the scancode is not valid for the specified protocol,
628c2ecf20Sopenharmony_ci``EINVAL`` is returned. The write function blocks until the scancode
638c2ecf20Sopenharmony_ciis transmitted by the hardware.
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ciReturn Value
668c2ecf20Sopenharmony_ci============
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ciOn success, the number of bytes written is returned. It is not an error if
698c2ecf20Sopenharmony_cithis number is smaller than the number of bytes requested, or the amount
708c2ecf20Sopenharmony_ciof data required for one frame.  On error, -1 is returned, and the ``errno``
718c2ecf20Sopenharmony_civariable is set appropriately. The generic error codes are described at the
728c2ecf20Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter.
73