libtinylor
Single-file header library for controlling Light-O-Rama hardware
Loading...
Searching...
No Matches
tinylor.h
Go to the documentation of this file.
1
3#ifndef TINYLOR_H
4#define TINYLOR_H
5
6#include <stddef.h>
7#include <stdint.h>
8
16typedef uint16_t lor_channel;
17
22typedef uint8_t lor_intensity;
23
33typedef uint8_t lor_unit;
34
37typedef uint16_t lor_decisec;
38
42typedef struct lor_channel_set {
45 uint8_t offset;
52 uint16_t cbits;
54
72
87
118
121#define LOR_HEARTBEAT_BYTES ((uint8_t[]) {0, 0xFF, 0x81, 0x56, 0})
122
125#define LOR_HEARTBEAT_SIZE 5
126
129#define LOR_HEARTBEAT_DELAY_MS 500
130
133#define LOR_HEARTBEAT_DELAY_NS 500000000
134
138#define LOR_UNIT_ID_ALL 0xFF
139
144#define LOR_UNIT_ID_HOST 0xFE
145
150#define LOR_UNIT_ID_LIST 0xF2
151
159typedef struct lor_unit_set {
162 uint64_t bits[4];
164
170
176void lor_unit_set_all(lor_unit_set* s, const lor_unit* u, size_t us);
177
182
201
212
224void lor_set_channels(lor_req_s* req, lor_channel first, uint16_t cbits);
225
231void lor_set_unit(lor_req_s* req, lor_unit u);
232
243void lor_set_units(lor_req_s* req, lor_unit_set* units);
244
258int lor_set_effect(lor_req_s* req, lor_effect e, const lor_effect_args_u* args);
259
268
278 lor_decisec ds);
279
293size_t lor_write(uint8_t* b, size_t bs, const lor_req_s* r, size_t rs,
294 size_t* wb);
295
299typedef lor_intensity (*lor_intensity_fn)(uint8_t b);
300
309
310#endif// TINYLOR_H
Represents a grouping of 16 channels, as a bit set, aligned to a 16-channel boundary (via a multiplie...
Definition tinylor.h:42
uint8_t offset
The offset of the first channel in the set.
Definition tinylor.h:45
uint16_t cbits
The 16-bit bitset of channels to apply the effect to relative to the offset.
Definition tinylor.h:52
Represents a request to apply an effect to a set of channels on a specific unit. The effect may requi...
Definition tinylor.h:189
lor_effect effect
The effect type to apply.
Definition tinylor.h:191
lor_effect_args_u args
The effect data, if required by the effect type, otherwise zero.
Definition tinylor.h:193
lor_unit_set * units
The units to apply the effect to.
Definition tinylor.h:199
lor_unit unit
The unit to apply the effect to.
Definition tinylor.h:197
lor_channel_set cset
The channel set to apply the effect to, may be a single channel.
Definition tinylor.h:195
Represents a set of unit IDs as a 256-bit bitset, used to address a request to an arbitrary subset of...
Definition tinylor.h:159
uint64_t bits[4]
Membership bits. Unit ID u is a member when bit (u % 64) of bits[u / 64] is set.
Definition tinylor.h:162
lor_effect
Represents the various effects that may be applied to a set of channels on a specific unit....
Definition tinylor.h:62
@ LOR_SHIMMER
Shimmer the lights using hardware controls.
Definition tinylor.h:69
@ LOR_PULSE
Cycle the lights between two intensities.
Definition tinylor.h:67
@ LOR_SET_OFF
Turn the lights off.
Definition tinylor.h:64
@ LOR_SET_INTENSITY
Set the lights to a specific intensity.
Definition tinylor.h:65
@ LOR_SET_LIGHTS
Set the lights to full intensity.
Definition tinylor.h:63
@ LOR_SET_DMX_INTENSITY
Write raw DMX protocol data.
Definition tinylor.h:70
@ LOR_FADE
Fade between two intensities over time.
Definition tinylor.h:66
@ LOR_TWINKLE
Twinkle the lights using hardware controls.
Definition tinylor.h:68
uint8_t lor_unit
Represents a unit ID, which is a unique identifier for a piece of LOR hardware. Valid unit IDs are [1...
Definition tinylor.h:33
uint16_t lor_decisec
Represents a duration in deciseconds, which is 1/10th of a second.
Definition tinylor.h:37
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,...
Definition tinylor.c:34
struct lor_req lor_req_s
union lor_effect_data lor_effect_args_u
void lor_set_unit(lor_req_s *req, lor_unit u)
Configures the request to be sent to, and accepted by, the specified unit. A unit is required for all...
Definition tinylor.c:41
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 ...
Definition tinylor.c:27
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...
Definition tinylor.c:73
uint16_t lor_channel
Represents a 0-based channel index, which is a unique identifier for a specific light or group of lig...
Definition tinylor.h:16
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 enco...
Definition tinylor.c:207
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,...
Definition tinylor.c:46
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 c...
Definition tinylor.c:243
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 h...
Definition tinylor.c:20
lor_intensity(* lor_intensity_fn)(uint8_t b)
Represents a function that converts an arbitrary byte value to a a scaled intensity value used by the...
Definition tinylor.h:299
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.
Definition tinylor.c:68
uint8_t lor_intensity
Represents a scaled intensity value used by the LOR protocol.
Definition tinylor.h:22
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.
Definition tinylor.c:12
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.
Definition tinylor.c:7
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,...
Definition tinylor.c:51
lor_channel_format
Represents the various formats that a channel set may be encoded in for the LOR protocol....
Definition tinylor.h:79
@ LOR_FMT_16
16-bit bitset of channels.
Definition tinylor.h:81
@ LOR_FMT_UNIT
Unit number, no channels.
Definition tinylor.h:84
@ LOR_FMT_MULTIPART
Multi-part channel set.
Definition tinylor.h:85
@ LOR_FMT_8H
8-bit bitset of channels, high byte (9-16).
Definition tinylor.h:82
@ LOR_FMT_8L
8-bit bitset of channels, low byte (1-8).
Definition tinylor.h:83
@ LOR_FMT_SINGLE
Single channel.
Definition tinylor.h:80
Union of effect argument structures that may be required by assorted effect types: LOR_SET_LIGHTS,...
Definition tinylor.h:92
uint8_t output
The output value to set the DMX channel to (likely brightness).
Definition tinylor.h:115
lor_intensity intensity
The intensity to set the lights to.
Definition tinylor.h:96
struct lor_effect_data::@1 fade
Required effect arguments for LOR_FADE.
struct lor_effect_data::@3 set_dmx_intensity
Required effect arguments for LOR_SET_DMX_INTENSITY.
lor_intensity start_intensity
The starting intensity.
Definition tinylor.h:101
struct lor_effect_data::@0 set_intensity
Required effect arguments for LOR_SET_LIGHTS.
lor_intensity end_intensity
The ending intensity.
Definition tinylor.h:103
lor_decisec deciseconds
The duration of the fade in deciseconds.
Definition tinylor.h:105
struct lor_effect_data::@2 pulse
Required effect arguments for LOR_PULSE.