%%% This file is part of the RayActor Lighting Software.
%%%
%%% RayActor is free software: you can redistribute it and/or modify it under
%%% the terms of the GNU Affero General Public License as published by the Free
%%% Software Foundation, either version 3 of the License, or (at your option)
%%% any later version.
%%%
%%% RayActor is distributed in the hope that it will be useful, but WITHOUT ANY
%%% WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
%%% FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
%%% more details.
%%%
%%% You should have received a copy of the GNU Affero General Public License
%%% along with Rayactor. If not, see <http://www.gnu.org/licenses/>.
%%%
-module(rayactor_dmx).

-export([new/0, set/3]).
-export_type([dmx/0]).

-type dmx() :: binary().
-type channel() :: integer().

-spec new() -> dmx().

new() -> binary:copy(<<0>>, 512).

-spec set(integer(), channel(), dmx()) -> dmx().

set(Pos, Chan, Data) ->
    <<Left:Pos/binary, _:8, Right/binary>> = Data,
    <<Left:Pos/binary, Chan:8, Right/binary>>.

Add a small library for a dmx() data type
Add a small library for a dmx() data type

Currently, this is implemented on Erlang binaries and only has one
helper function set() and nothing more so far (more coming soon of
course).

The goal is to only use this library for handling DMX packets,
especially if it comes to only changing a subset of a packet.

We have to see whether using Erlang binaries is sufficient enough in
terms of performance and memory usage and probably implement it as a
NIF at some point in the future.

Signed-off-by: aszlig <ee1aa092358634f9c53f01b5a783726c9e21b35a@redmoonstudios.org>
