|
libtinylor
Single-file header library for controlling Light-O-Rama hardware
|
Protocol encoding functions implementation. More...
#include "tinylor.h"
Macros | |
| #define | LOR_MAX_UNIT_LIST 256 |
The size of the unit ID space scanned when encoding a unit list, i.e. one bit per possible lor_unit value (0-255). The protocol's count byte allows at most 255 entries, but valid unit IDs are limited to [1, 0xF0] so a list can never exceed 240 entries in practice. | |
Functions | |
| void | lor_unit_set_add (lor_unit_set *s, const lor_unit unit) |
| Adds a single unit ID to the set. Adding an ID that is already a member has no effect. | |
| void | lor_unit_set_all (lor_unit_set *s, const lor_unit *u, const size_t us) |
| Adds each unit ID in an array to the set. | |
| void | lor_unit_set_clear (lor_unit_set *s) |
| Removes every unit ID from the set, leaving it empty. Also serves to initialize a set whose storage has not been zeroed. | |
| void | lor_set_channel (lor_req_s *req, lor_channel c) |
| Configures the request to use a single channel, addressed by its 0-based index (index 0 is channel 1 in LOR software). The index is encoded as '0x80 | index' in the single-channel format, so the controller receives it directly. | |
| void | lor_set_channels (lor_req_s *req, lor_channel first, const uint16_t cbits) |
| Configures the request to use a channel set, in the form of a 16-bit bitset of channels, "starting at" the first channel offset used. | |
| void | lor_set_unit (lor_req_s *req, const lor_unit u) |
| Configures the request to be sent to, and accepted by, the specified unit. A unit is required for all requests. A magic value of 0xFF may be used to broadcast the request to all units. | |
| void | lor_set_units (lor_req_s *req, lor_unit_set *units) |
Configures the request to be sent to, and accepted by, every unit in the provided set, using the LOR_UNIT_ID_LIST addressing form. This replaces any unit previously configured with lor_set_unit. The encoded frame grows by one count byte plus one byte per member. | |
| int | lor_set_effect (lor_req_s *req, const lor_effect e, const lor_effect_args_u *args) |
| Configures the request to apply the specified effect. The effect may require additional arguments, which are provided in the args field as a union. If provided, the args field is copied into the request at which point the caller may safely discard the original args. Any non-NULL arguments will be copied into the request, even if the effect does not require them. This allows future expansion of usable effects without modifying the behavior of the function. | |
| void | lor_set_intensity (lor_req_s *req, const lor_intensity i) |
| Configures the request to set the intensity of the lights to the provided value. | |
| void | lor_set_fade (lor_req_s *req, const lor_intensity start, const lor_intensity end, const lor_decisec ds) |
| Configures the request to fade from one intensity to another over a specified duration in deciseconds. | |
| static lor_channel_format | lor_get_cset_format (const lor_channel_set *const cset) |
| Determines the compressed format of the channel set for encoding. | |
| static int | lor_encode_channel (uint8_t *const b, const lor_channel_set *const cset) |
| Encodes a single-channel set as one byte: the channel's 0-based index with bit 7 set, as expected by the single-channel mode (0x00). Bit 7 carries no information for the controller; it only ensures channel index 0 is not encoded as 0x00, the frame delimiter. | |
| static int | lor_encode_cset (uint8_t *const b, const lor_channel_set *const cset) |
| Encodes a channel set into a buffer. | |
| static int | lor_encode_decis (uint8_t *b, const lor_decisec ds) |
| Encodes a decisecond value. | |
| static int | lor_encode_fade_rate (uint8_t *b, const lor_effect_args_u *args) |
| Encodes a fade effect as an intensity delta relative to the duration of the effect in deciseconds. | |
| static int | lor_encode_effect (uint8_t *const b, const lor_effect e, const lor_effect_args_u *const d) |
| Encodes an effect into a buffer, including any required arguments for the effect type. | |
| size_t | lor_write (uint8_t *b, const size_t bs, const lor_req_s *r, const size_t rs, size_t *wb) |
Encodes and writes up to rs requests to the provided buffer b as binary data. Requests are first encoded into a scratch buffer to ensure the buffer has enough space to hold the encoded data. The function will attempt to write as many requests as possible to the buffer, up to the provided request count. | |
| lor_intensity | lor_get_intensity (const uint8_t b) |
| Encodes a [0,0xFF] value into a roughly equivalent LOR intensity value (precision is lossy) that is compatible with the protocol. | |
Protocol encoding functions implementation.
| #define LOR_MAX_UNIT_LIST 256 |
The size of the unit ID space scanned when encoding a unit list, i.e. one bit per possible lor_unit value (0-255). The protocol's count byte allows at most 255 entries, but valid unit IDs are limited to [1, 0xF0] so a list can never exceed 240 entries in practice.
|
static |
Encodes a single-channel set as one byte: the channel's 0-based index with bit 7 set, as expected by the single-channel mode (0x00). Bit 7 carries no information for the controller; it only ensures channel index 0 is not encoded as 0x00, the frame delimiter.
| b | The buffer to write the channel byte to. |
| cset | The channel set to encode. Must have a zero offset and exactly one bit set (see lor_get_cset_format, LOR_FMT_SINGLE). |

|
static |
Encodes a channel set into a buffer.
| b | The buffer to write the channel set to. |
| cset | The channel set to encode. |


|
static |
Encodes a decisecond value.
| b | The buffer to write the decisecond value to. |
| ds | The decisecond value to encode. |

|
static |
Encodes an effect into a buffer, including any required arguments for the effect type.
| b | The buffer to write the effect to. |
| e | The effect to encode. |
| d | Optional effect arguments to encode. |


|
static |
Encodes a fade effect as an intensity delta relative to the duration of the effect in deciseconds.
| b | The buffer to write the fade value to. |


|
static |
Determines the compressed format of the channel set for encoding.
| cset | The channel set to determine the format of. |

| lor_intensity lor_get_intensity | ( | uint8_t | b | ) |
Encodes a [0,0xFF] value into a roughly equivalent LOR intensity value (precision is lossy) that is compatible with the protocol.
| b | The byte value to convert. |
| void lor_set_channel | ( | lor_req_s * | req, |
| lor_channel | c | ||
| ) |
Configures the request to use a single channel, addressed by its 0-based index (index 0 is channel 1 in LOR software). The index is encoded as '0x80 | index' in the single-channel format, so the controller receives it directly.
| req | The request to configure. |
| c | The 0-based channel index to apply the effect to, less than 1024. |

| void lor_set_channels | ( | lor_req_s * | req, |
| lor_channel | first, | ||
| uint16_t | cbits | ||
| ) |
Configures the request to use a channel set, in the form of a 16-bit bitset of channels, "starting at" the first channel offset used.
| req | The request to configure. |
| first | The 0-based index of the first channel in the set, i.e. the channel selected by bit 0 of cbits (see lor_channel). |
| cbits | The 16-bit bitset of channels to apply the effect to; bit n selects channel index first + n. |

| int lor_set_effect | ( | lor_req_s * | req, |
| lor_effect | e, | ||
| const lor_effect_args_u * | args | ||
| ) |
Configures the request to apply the specified effect. The effect may require additional arguments, which are provided in the args field as a union. If provided, the args field is copied into the request at which point the caller may safely discard the original args. Any non-NULL arguments will be copied into the request, even if the effect does not require them. This allows future expansion of usable effects without modifying the behavior of the function.
| req | The request to configure. |
| e | The effect to apply. |
| args | The effect arguments, required if effect is LOR_SET_INTENSITY, LOR_FADE, LOR_PULSE, or LOR_SET_DMX_INTENSITY. Should likely be NULL for other effect types. |

| void lor_set_fade | ( | lor_req_s * | req, |
| lor_intensity | start, | ||
| lor_intensity | end, | ||
| lor_decisec | ds | ||
| ) |
Configures the request to fade from one intensity to another over a specified duration in deciseconds.
| req | The request to configure. |
| start | The starting intensity. |
| end | The ending intensity. |
| ds | The duration of the fade in deciseconds. |

| void lor_set_intensity | ( | lor_req_s * | req, |
| lor_intensity | i | ||
| ) |
Configures the request to set the intensity of the lights to the provided value.
| req | The request to configure. |
| i | The intensity to use. This value should likely pass through a intensity conversion function before being passed to this function. |


Configures the request to be sent to, and accepted by, the specified unit. A unit is required for all requests. A magic value of 0xFF may be used to broadcast the request to all units.
| req | The request to configure. |
| u | The unit to send the request to, or 0xFF to broadcast to all units. |

| void lor_set_units | ( | lor_req_s * | req, |
| lor_unit_set * | units | ||
| ) |
Configures the request to be sent to, and accepted by, every unit in the provided set, using the LOR_UNIT_ID_LIST addressing form. This replaces any unit previously configured with lor_set_unit. The encoded frame grows by one count byte plus one byte per member.
lor_write. The set must contain at least one unit: an empty set encodes a count byte of 0x00, which terminates the frame before the command byte. | req | The request to configure. |
| units | The set of unit IDs to send the request to. |

| void lor_unit_set_add | ( | lor_unit_set * | s, |
| lor_unit | unit | ||
| ) |
Adds a single unit ID to the set. Adding an ID that is already a member has no effect.
| s | The set to modify. |
| unit | The unit ID to add, in [1, 0xF0]. |

| void lor_unit_set_all | ( | lor_unit_set * | s, |
| const lor_unit * | u, | ||
| size_t | us | ||
| ) |
Adds each unit ID in an array to the set.
lor_unit_set_add once per element of u. | s | The set to modify. |
| u | The array of unit IDs to add, each in [1, 0xF0]. |
| us | The number of unit IDs in u. |

| void lor_unit_set_clear | ( | lor_unit_set * | s | ) |
Removes every unit ID from the set, leaving it empty. Also serves to initialize a set whose storage has not been zeroed.
| s | The set to clear. |

| size_t lor_write | ( | uint8_t * | b, |
| size_t | bs, | ||
| const lor_req_s * | r, | ||
| size_t | rs, | ||
| size_t * | wb | ||
| ) |
Encodes and writes up to rs requests to the provided buffer b as binary data. Requests are first encoded into a scratch buffer to ensure the buffer has enough space to hold the encoded data. The function will attempt to write as many requests as possible to the buffer, up to the provided request count.
| b | The buffer to write the encoded requests to. |
| bs | The size of b in bytes. |
| r | The requests to encode, an array of at least rs elements. |
| rs | The number of requests in r to encode. |
| wb | Written byte count accumulator, may be NULL. |
wb if it is not NULL. 
