servicepoint-binding-c/include/servicepoint.h
Vinzenz Schroeter e7cad5b5a3 doc changes
2025-05-07 08:29:43 +02:00

1664 lines
43 KiB
C

/* Generated with cbindgen:0.28.0 */
/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
/**
* pixel count on whole screen
*/
#define PIXEL_COUNT (PIXEL_WIDTH * PIXEL_HEIGHT)
/**
* Display height in pixels
*
* # Examples
*
* ```rust
* # use servicepoint::{PIXEL_HEIGHT, PIXEL_WIDTH, Bitmap};
* let grid = Bitmap::new(PIXEL_WIDTH, PIXEL_HEIGHT);
* ```
*/
#define PIXEL_HEIGHT (TILE_HEIGHT * TILE_SIZE)
/**
* Display width in pixels
*
* # Examples
*
* ```rust
* # use servicepoint::{PIXEL_HEIGHT, PIXEL_WIDTH, Bitmap};
* let grid = Bitmap::new(PIXEL_WIDTH, PIXEL_HEIGHT);
* ```
*/
#define PIXEL_WIDTH (TILE_WIDTH * TILE_SIZE)
/**
* Display tile count in the y-direction
*
* # Examples
*
* ```rust
* # use servicepoint::{Cp437Grid, TILE_HEIGHT, TILE_WIDTH};
* let grid = Cp437Grid::new(TILE_WIDTH, TILE_HEIGHT);
* ```
*/
#define TILE_HEIGHT 20
/**
* size of a single tile in one dimension
*/
#define TILE_SIZE 8
/**
* Display tile count in the x-direction
*
* # Examples
*
* ```rust
* # use servicepoint::{Cp437Grid, TILE_HEIGHT, TILE_WIDTH};
* let grid = Cp437Grid::new(TILE_WIDTH, TILE_HEIGHT);
* ```
*/
#define TILE_WIDTH 56
/**
* Binary operations for use with the [`BitVecCommand`] command.
*/
enum BinaryOperation
#ifdef __cplusplus
: uint8_t
#endif // __cplusplus
{
/**
* r := a
*/
BINARY_OPERATION_OVERWRITE,
/**
* r := a && b
*/
BINARY_OPERATION_AND,
/**
* r := a || b
*/
BINARY_OPERATION_OR,
/**
* r := (a || b) && (a != b)
*/
BINARY_OPERATION_XOR,
};
#ifndef __cplusplus
typedef uint8_t BinaryOperation;
#endif // __cplusplus
/**
* The u16 command codes used for the [Command]s.
*/
enum CommandCode
#ifdef __cplusplus
: uint16_t
#endif // __cplusplus
{
COMMAND_CODE_CLEAR = 2,
COMMAND_CODE_CP437_DATA = 3,
COMMAND_CODE_CHAR_BRIGHTNESS = 5,
COMMAND_CODE_BRIGHTNESS = 7,
COMMAND_CODE_HARD_RESET = 11,
COMMAND_CODE_FADE_OUT = 13,
COMMAND_CODE_BITMAP_LEGACY = 16,
COMMAND_CODE_BITMAP_LINEAR = 18,
COMMAND_CODE_BITMAP_LINEAR_WIN_UNCOMPRESSED = 19,
COMMAND_CODE_BITMAP_LINEAR_AND = 20,
COMMAND_CODE_BITMAP_LINEAR_OR = 21,
COMMAND_CODE_BITMAP_LINEAR_XOR = 22,
COMMAND_CODE_BITMAP_LINEAR_WIN_ZLIB = 23,
COMMAND_CODE_BITMAP_LINEAR_WIN_BZIP2 = 24,
COMMAND_CODE_BITMAP_LINEAR_WIN_LZMA = 25,
COMMAND_CODE_UTF8_DATA = 32,
COMMAND_CODE_BITMAP_LINEAR_WIN_ZSTD = 26,
};
#ifndef __cplusplus
typedef uint16_t CommandCode;
#endif // __cplusplus
/**
* Specifies the kind of command struct.
*
* This is _not_ equivalent to the [servicepoint::CommandCode]s.
*/
enum CommandTag
#ifdef __cplusplus
: uint8_t
#endif // __cplusplus
{
COMMAND_TAG_INVALID = 0,
COMMAND_TAG_BITMAP,
COMMAND_TAG_BIT_VEC,
COMMAND_TAG_BRIGHTNESS_GRID,
COMMAND_TAG_CHAR_GRID,
COMMAND_TAG_CP437_GRID,
COMMAND_TAG_GLOBAL_BRIGHTNESS,
COMMAND_TAG_CLEAR,
COMMAND_TAG_HARD_RESET,
COMMAND_TAG_FADE_OUT,
COMMAND_TAG_BITMAP_LEGACY,
};
#ifndef __cplusplus
typedef uint8_t CommandTag;
#endif // __cplusplus
/**
* Specifies the kind of compression to use. Availability depends on features.
*
* # Examples
*
* ```rust
* # use servicepoint::*;
* // create command without payload compression
* # let pixels = Bitmap::max_sized();
* _ = BitmapCommand {
* origin: Origin::ZERO,
* bitmap: pixels,
* compression: CompressionCode::Uncompressed
* };
*
* // create command with payload compressed with lzma and appropriate header flags
* # let pixels = Bitmap::max_sized();
* _ = BitmapCommand {
* origin: Origin::ZERO,
* bitmap: pixels,
* compression: CompressionCode::Lzma
* };
* ```
*/
enum CompressionCode
#ifdef __cplusplus
: uint16_t
#endif // __cplusplus
{
/**
* no compression
*/
COMPRESSION_CODE_UNCOMPRESSED = 0,
/**
* compress using flate2 with zlib header
*/
COMPRESSION_CODE_ZLIB = 26490,
/**
* compress using bzip2
*/
COMPRESSION_CODE_BZIP2 = 25210,
/**
* compress using lzma
*/
COMPRESSION_CODE_LZMA = 27770,
/**
* compress using Zstandard
*/
COMPRESSION_CODE_ZSTD = 31347,
};
#ifndef __cplusplus
typedef uint16_t CompressionCode;
#endif // __cplusplus
/**
* Set pixel data starting at the pixel offset on screen.
*
* The screen will continuously overwrite more pixel data without regarding the offset, meaning
* once the starting row is full, overwriting will continue on column 0.
*
* The [`BinaryOperation`] will be applied on the display comparing old and sent bit.
*
* `new_bit = old_bit op sent_bit`
*
* For example, [`BinaryOperation::Or`] can be used to turn on some pixels without affecting other pixels.
*
* The contained [`DisplayBitVec`] is always uncompressed.
*/
typedef struct BitVecCommand BitVecCommand;
/**
* A fixed-size 2D grid of booleans.
*
* The values are stored in packed bytes (8 values per byte) in the same order as used by the display for storing pixels.
* This means that no conversion is necessary for sending the data to the display.
* The downside is that the width has to be a multiple of 8.
*
* # Examples
*
* ```rust
* use servicepoint::Bitmap;
* let mut bitmap = Bitmap::new(8, 2);
*
* ```
*/
typedef struct Bitmap Bitmap;
/**
* Overwrites a rectangular region of pixels.
*
* Origin coordinates must be divisible by 8.
*
* # Examples
*
* ```rust
* # use servicepoint::*;
* # let connection = FakeConnection;
* #
* let mut bitmap = Bitmap::max_sized();
* // draw something to the pixels here
* # bitmap.set(2, 5, true);
*
* // create command to send pixels
* let command = BitmapCommand {
* bitmap,
* origin: Origin::ZERO,
* compression: CompressionCode::Uncompressed
* };
*
* connection.send_command(command).expect("send failed");
* ```
*/
typedef struct BitmapCommand BitmapCommand;
/**
* Legacy command code, gets ignored by the real display.
*
* Might be useful as a noop package.
*
* # Examples
*
* ```rust
* # use servicepoint::*;
* # let connection = FakeConnection;
* // this sends a packet that does nothing
* # #[allow(deprecated)]
* connection.send_command(BitmapLegacyCommand).unwrap();
* ```
*/
typedef struct BitmapLegacyCommand BitmapLegacyCommand;
/**
* Set the brightness of individual tiles in a rectangular area of the display.
*/
typedef struct BrightnessGridCommand BrightnessGridCommand;
/**
* Show text on the screen.
*
* The text is sent in the form of a 2D grid of UTF-8 encoded characters (the default encoding in rust).
*
* # Examples
*
* ```rust
* # use servicepoint::*;
* # let connection = FakeConnection;
* let grid = CharGrid::from("Hello,\nWorld!");
* connection.send_command(CharGridCommand { origin: Origin::ZERO, grid }).expect("send failed");
* ```
*/
typedef struct CharGridCommand CharGridCommand;
/**
* Set all pixels to the off state. Does not affect brightness.
*
* # Examples
*
* ```rust
* # use servicepoint::*;
* # let connection = FakeConnection;
* connection.send_command(ClearCommand).unwrap();
* ```
*/
typedef struct ClearCommand ClearCommand;
/**
* Show text on the screen.
*
* The text is sent in the form of a 2D grid of [CP-437] encoded characters.
*
* <div class="warning">You probably want to use [Command::Utf8Data] instead</div>
*
* # Examples
*
* ```rust
* # use servicepoint::*;
* # let connection = FakeConnection;
* let grid = CharGrid::from("Hello,\nWorld!");
* let grid = Cp437Grid::from(&grid);
* connection.send_command(Cp437GridCommand{ origin: Origin::ZERO, grid }).expect("send failed");
* ```
*
* ```rust
* # use servicepoint::*;
* # let connection = FakeConnection;
* let grid = Cp437Grid::load_ascii("Hello\nWorld", 5, false).unwrap();
* connection.send_command(Cp437GridCommand{ origin: Origin::new(2, 2), grid }).unwrap();
* ```
* [CP-437]: https://en.wikipedia.org/wiki/Code_page_437
*/
typedef struct Cp437GridCommand Cp437GridCommand;
/**
* This is a type only used by cbindgen to have a type for pointers.
*/
typedef struct DisplayBitVec DisplayBitVec;
/**
* <div class="warning">Untested</div>
*
* Slowly decrease brightness until off or something like that?
*
* # Examples
*
* ```rust
* # use servicepoint::*;
* # let connection = FakeConnection;
* connection.send_command(FadeOutCommand).unwrap();
* ```
*/
typedef struct FadeOutCommand FadeOutCommand;
/**
* Set the brightness of all tiles to the same value.
*
* # Examples
*
* ```rust
* # use servicepoint::*;
* # let connection = FakeConnection;
* let command = GlobalBrightnessCommand { brightness: Brightness::MAX };
* connection.send_command(command).unwrap();
* ```
*/
typedef struct GlobalBrightnessCommand GlobalBrightnessCommand;
/**
* Kills the udp daemon on the display, which usually results in a restart.
*
* Please do not send this in your normal program flow.
*
* # Examples
*
* ```rust
* # use servicepoint::*;
* # let connection = FakeConnection;
* connection.send_command(HardResetCommand).unwrap();
* ```
*/
typedef struct HardResetCommand HardResetCommand;
/**
* The raw packet.
*
* Contents should probably only be used directly to use features not exposed by the library.
*
* You may want to use [`crate::Command`] or [`crate::TypedCommand`] instead.
*/
typedef struct Packet Packet;
/**
* This is a type only used by cbindgen to have a type for pointers.
*/
typedef struct UdpSocket UdpSocket;
/**
* A 2D grid of values.
*
* The memory layout is the one the display expects in [`crate::Command`]s.
*
* This structure can be used with any type that implements the [Value] trait.
* You can also use the concrete type aliases provided in this crate, e.g. [`crate::CharGrid`] and [`crate::ByteGrid`].
*/
typedef struct ValueGrid_Brightness ValueGrid_Brightness;
/**
* A 2D grid of values.
*
* The memory layout is the one the display expects in [`crate::Command`]s.
*
* This structure can be used with any type that implements the [Value] trait.
* You can also use the concrete type aliases provided in this crate, e.g. [`crate::CharGrid`] and [`crate::ByteGrid`].
*/
typedef struct ValueGrid_char ValueGrid_char;
/**
* A 2D grid of values.
*
* The memory layout is the one the display expects in [`crate::Command`]s.
*
* This structure can be used with any type that implements the [Value] trait.
* You can also use the concrete type aliases provided in this crate, e.g. [`crate::CharGrid`] and [`crate::ByteGrid`].
*/
typedef struct ValueGrid_u8 ValueGrid_u8;
/**
* Represents a span of memory (`&mut [u8]` ) as a struct.
*
* # Safety
*
* The caller has to make sure that:
*
* - accesses to the memory pointed to with `start` is never accessed outside `length`
* - the lifetime of the `CByteSlice` does not outlive the memory it points to, as described in
* the function returning this type.
*/
typedef struct {
/**
* The start address of the memory.
*/
uint8_t */*notnull*/ start;
/**
* The amount of memory in bytes.
*/
size_t length;
} ByteSlice;
/**
* A grid containing brightness values.
*
* # Examples
*
* ```rust
* # use servicepoint::*;
* let mut grid = BrightnessGrid::new(2,2);
* grid.set(0, 0, Brightness::MIN);
* grid.set(1, 1, Brightness::MIN);
*
* # let connection = FakeConnection;
* connection.send_command(BrightnessGridCommand {
* origin: Origin::new(3, 7),
* grid
* }).unwrap()
* ```
*/
typedef ValueGrid_Brightness BrightnessGrid;
/**
* A display brightness value, checked for correct value range
*
* # Examples
*
* ```
* # use servicepoint::*;
* let b = Brightness::MAX;
* let val: u8 = b.into();
*
* let b = Brightness::try_from(7).unwrap();
* # let connection = FakeConnection;
* let result = connection.send_command(GlobalBrightnessCommand::from(b));
* ```
*/
typedef uint8_t Brightness;
/**
* highest possible brightness value, 11
*/
#define Brightness_MAX 11
/**
* lowest possible brightness value, 0
*/
#define Brightness_MIN 0
/**
* A grid containing UTF-8 characters.
*
* To send a `CharGrid` to the display, use a [`crate::CharGridCommand`].
*
* Also see [`ValueGrid`] for the non-specialized operations and examples.
*
* # Examples
*
* ```rust
* # use servicepoint::*;
* let grid = CharGrid::from("You can\nload multiline\nstrings directly");
* assert_eq!(grid.get_row_str(1), Some("load multiline\0\0".to_string()));
*
* # let connection = FakeConnection;
* let command = CharGridCommand { origin: Origin::ZERO, grid };
* connection.send_command(command).unwrap()
* ```
*/
typedef ValueGrid_char CharGrid;
/**
* Type alias for documenting the meaning of the u16 in enum values
*/
typedef size_t Offset;
/**
* A grid containing codepage 437 characters.
*
* The encoding is currently not enforced.
*/
typedef ValueGrid_u8 Cp437Grid;
/**
* Pointer to one of the available command structs.
*/
typedef union {
uint8_t *null;
BitmapCommand */*notnull*/ bitmap;
BitVecCommand */*notnull*/ bitvec;
BrightnessGridCommand */*notnull*/ brightness_grid;
CharGridCommand */*notnull*/ char_grid;
Cp437GridCommand */*notnull*/ cp437_grid;
GlobalBrightnessCommand */*notnull*/ global_brightness;
ClearCommand */*notnull*/ clear;
BitmapLegacyCommand */*notnull*/ bitmap_legacy;
HardResetCommand */*notnull*/ hard_reset;
FadeOutCommand */*notnull*/ fade_out;
} CommandUnion;
/**
* This struct represents a pointer to one of the possible command structs.
*
* Only ever access `data` with the correct data type as specified by `tag`!
*
* Rust equivalent: [TypedCommand].
*/
typedef struct {
/**
* Specifies which kind of command struct is contained in `data`
*/
CommandTag tag;
/**
* The pointer to the command struct
*/
CommandUnion data;
} SPCommand;
/**
* A raw header.
*
* The header specifies the kind of command, the size of the payload and where to display the
* payload, where applicable.
*
* Because the meaning of most fields depend on the command, there are no speaking names for them.
*
* The contained values are in platform endian-ness and may need to be converted before sending.
*/
typedef struct {
/**
* The first two bytes specify which command this packet represents.
*/
uint16_t command_code;
/**
* First command-specific value
*/
uint16_t a;
/**
* Second command-specific value
*/
uint16_t b;
/**
* Third command-specific value
*/
uint16_t c;
/**
* Fourth command-specific value
*/
uint16_t d;
} Header;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/**
* Clones a [Bitmap].
*/
Bitmap */*notnull*/ sp_bitmap_clone(Bitmap */*notnull*/ bitmap);
/**
* Sets the state of all pixels in the [Bitmap].
*
* # Arguments
*
* - `bitmap`: instance to write to
* - `value`: the value to set all pixels to
*/
void sp_bitmap_fill(Bitmap */*notnull*/ bitmap, bool value);
/**
* Deallocates a [Bitmap].
*/
void sp_bitmap_free(Bitmap */*notnull*/ bitmap);
/**
* Tries to convert the BitVec to a Bitmap.
*
* The provided BitVec gets consumed.
*
* Returns NULL in case of error.
*/
Bitmap *sp_bitmap_from_bitvec(size_t width, DisplayBitVec */*notnull*/ bitvec);
/**
* Gets the current value at the specified position in the [Bitmap].
*
* # Arguments
*
* - `bitmap`: instance to read from
* - `x` and `y`: position of the cell to read
*
* # Panics
*
* - when accessing `x` or `y` out of bounds
*/
bool sp_bitmap_get(Bitmap */*notnull*/ bitmap, size_t x, size_t y);
/**
* Gets the height in pixels of the [Bitmap] instance.
*
* # Arguments
*
* - `bitmap`: instance to read from
*/
size_t sp_bitmap_height(Bitmap */*notnull*/ bitmap);
/**
* Consumes the Bitmap and returns the contained BitVec
*/
DisplayBitVec */*notnull*/ sp_bitmap_into_bitvec(Bitmap */*notnull*/ bitmap);
/**
* Creates a [BitmapCommand] and immediately turns that into a [Packet].
*
* The provided [Bitmap] gets consumed.
*
* Returns NULL in case of an error.
*/
Packet *sp_bitmap_into_packet(Bitmap */*notnull*/ bitmap,
size_t x,
size_t y,
CompressionCode compression);
/**
* Loads a [Bitmap] with the specified dimensions from the provided data.
*
* # Arguments
*
* - `width`: size in pixels in x-direction
* - `height`: size in pixels in y-direction
*
* returns: [Bitmap] that contains a copy of the provided data, or NULL in case of an error.
*/
Bitmap *sp_bitmap_load(size_t width,
size_t height,
ByteSlice data);
/**
* Creates a new [Bitmap] with the specified dimensions.
*
* # Arguments
*
* - `width`: size in pixels in x-direction
* - `height`: size in pixels in y-direction
*
* returns: [Bitmap] initialized to all pixels off, or NULL in case of an error.
*
* # Errors
*
* In the following cases, this function will return NULL:
*
* - when the width is not dividable by 8
*
* # Examples
*
* ```C
* Cp437Grid grid = sp_bitmap_new(8, 3);
* sp_bitmap_fill(grid, true);
* sp_bitmap_set(grid, 0, 0, false);
* sp_bitmap_free(grid);
* ```
*/
Bitmap *sp_bitmap_new(size_t width, size_t height);
/**
* Creates a new [Bitmap] with a size matching the screen.
*
* returns: [Bitmap] initialized to all pixels off.
*/
Bitmap */*notnull*/ sp_bitmap_new_max_sized(void);
/**
* Sets the value of the specified position in the [Bitmap].
*
* # Arguments
*
* - `bitmap`: instance to write to
* - `x` and `y`: position of the cell
* - `value`: the value to write to the cell
*
* # Panics
*
* - when accessing `x` or `y` out of bounds
*/
void sp_bitmap_set(Bitmap */*notnull*/ bitmap, size_t x, size_t y, bool value);
/**
* Gets an unsafe reference to the data of the [Bitmap] instance.
*
* The returned memory is valid for the lifetime of the bitmap.
*/
ByteSlice sp_bitmap_unsafe_data_ref(Bitmap */*notnull*/ bitmap);
/**
* Gets the width in pixels of the [Bitmap] instance.
*
* # Arguments
*
* - `bitmap`: instance to read from
*
* # Panics
*
* - when `bitmap` is NULL
*
* # Safety
*
* The caller has to make sure that:
*
* - `bitmap` points to a valid [Bitmap]
*/
size_t sp_bitmap_width(Bitmap */*notnull*/ bitmap);
/**
* Clones a [DisplayBitVec].
*/
DisplayBitVec */*notnull*/ sp_bitvec_clone(DisplayBitVec */*notnull*/ bit_vec);
/**
* Sets the value of all bits in the [DisplayBitVec].
*
* # Arguments
*
* - `bit_vec`: instance to write to
* - `value`: the value to set all bits to
*/
void sp_bitvec_fill(DisplayBitVec */*notnull*/ bit_vec, bool value);
/**
* Deallocates a [DisplayBitVec].
*/
void sp_bitvec_free(DisplayBitVec */*notnull*/ bit_vec);
/**
* Gets the value of a bit from the [DisplayBitVec].
*
* # Arguments
*
* - `bit_vec`: instance to read from
* - `index`: the bit index to read
*
* returns: value of the bit
*
* # Panics
*
* - when accessing `index` out of bounds
*/
bool sp_bitvec_get(DisplayBitVec */*notnull*/ bit_vec, size_t index);
/**
* Creates a [BitVecCommand] and immediately turns that into a [Packet].
*
* The provided [DisplayBitVec] gets consumed.
*
* Returns NULL in case of an error.
*/
Packet *sp_bitvec_into_packet(DisplayBitVec */*notnull*/ bitvec,
size_t offset,
BinaryOperation operation,
CompressionCode compression);
/**
* Returns true if length is 0.
*
* # Arguments
*
* - `bit_vec`: instance to write to
*/
bool sp_bitvec_is_empty(DisplayBitVec */*notnull*/ bit_vec);
/**
* Gets the length of the [DisplayBitVec] in bits.
*
* # Arguments
*
* - `bit_vec`: instance to write to
*/
size_t sp_bitvec_len(DisplayBitVec */*notnull*/ bit_vec);
/**
* Interpret the data as a series of bits and load then into a new [DisplayBitVec] instance.
*
* returns: [DisplayBitVec] instance containing data.
*/
DisplayBitVec */*notnull*/ sp_bitvec_load(ByteSlice data);
/**
* Creates a new [DisplayBitVec] instance.
*
* # Arguments
*
* - `size`: size in bits.
*
* returns: [DisplayBitVec] with all bits set to false.
*
* # Panics
*
* - when `size` is not divisible by 8.
*/
DisplayBitVec */*notnull*/ sp_bitvec_new(size_t size);
/**
* Sets the value of a bit in the [DisplayBitVec].
*
* # Arguments
*
* - `bit_vec`: instance to write to
* - `index`: the bit index to edit
* - `value`: the value to set the bit to
*
* # Panics
*
* - when accessing `index` out of bounds
*/
void sp_bitvec_set(DisplayBitVec */*notnull*/ bit_vec,
size_t index,
bool value);
/**
* Gets an unsafe reference to the data of the [DisplayBitVec] instance.
*
* The returned memory is valid for the lifetime of the bitvec.
*
* # Arguments
*
* - `bit_vec`: instance to write to
*/
ByteSlice sp_bitvec_unsafe_data_ref(DisplayBitVec */*notnull*/ bit_vec);
/**
* Clones a [BrightnessGrid].
*/
BrightnessGrid */*notnull*/ sp_brightness_grid_clone(BrightnessGrid */*notnull*/ grid);
/**
* Sets the value of all cells in the [BrightnessGrid].
*
* # Arguments
*
* - `brightness_grid`: instance to write to
* - `value`: the value to set all cells to
*/
void sp_brightness_grid_fill(BrightnessGrid */*notnull*/ brightness_grid,
Brightness value);
/**
* Deallocates a [BrightnessGrid].
*/
void sp_brightness_grid_free(BrightnessGrid */*notnull*/ brightness_grid);
/**
* Gets the current value at the specified position.
*
* # Arguments
*
* - `brightness_grid`: instance to read from
* - `x` and `y`: position of the cell to read
*
* returns: value at position
*
* # Panics
* - When accessing `x` or `y` out of bounds.
*/
Brightness sp_brightness_grid_get(BrightnessGrid */*notnull*/ brightness_grid,
size_t x,
size_t y);
/**
* Gets the height of the [BrightnessGrid] instance.
*
* # Arguments
*
* - `brightness_grid`: instance to read from
*
* returns: height
*/
size_t sp_brightness_grid_height(BrightnessGrid */*notnull*/ brightness_grid);
/**
* Creates a [BrightnessGridCommand] and immediately turns that into a [Packet].
*
* The provided [BrightnessGrid] gets consumed.
*
* Returns NULL in case of an error.
*/
Packet *sp_brightness_grid_into_packet(BrightnessGrid */*notnull*/ grid,
size_t x,
size_t y);
/**
* Loads a [BrightnessGrid] with the specified dimensions from the provided data.
*
* Any out of range values will be set to [Brightness::MAX] or [Brightness::MIN].
*
* returns: new [BrightnessGrid] instance, or NULL in case of an error.
*/
BrightnessGrid *sp_brightness_grid_load(size_t width,
size_t height,
ByteSlice data);
/**
* Creates a new [BrightnessGrid] with the specified dimensions.
*
* returns: [BrightnessGrid] initialized to 0.
*
* # Examples
* ```C
* UdpSocket *connection = sp_udp_open("127.0.0.1:2342");
* if (connection == NULL)
* return 1;
*
* BrightnessGrid *grid = sp_brightness_grid_new(2, 2);
* sp_brightness_grid_set(grid, 0, 0, 0);
* sp_brightness_grid_set(grid, 1, 1, 10);
*
* TypedCommand *command = sp_command_char_brightness(grid);
* sp_udp_free(connection);
* ```
*/
BrightnessGrid */*notnull*/ sp_brightness_grid_new(size_t width, size_t height);
/**
* Sets the value of the specified position in the [BrightnessGrid].
*
* # Arguments
*
* - `brightness_grid`: instance to write to
* - `x` and `y`: position of the cell
* - `value`: the value to write to the cell
*
* returns: old value of the cell
*
* # Panics
*
* - When accessing `x` or `y` out of bounds.
*/
void sp_brightness_grid_set(BrightnessGrid */*notnull*/ brightness_grid,
size_t x,
size_t y,
Brightness value);
/**
* Gets an unsafe reference to the data of the [BrightnessGrid] instance.
*
* The returned memory is valid for the lifetime of the brightness grid.
*
* # Arguments
*
* - `brightness_grid`: instance to read from
*
* returns: slice of bytes underlying the `brightness_grid`.
*/
ByteSlice sp_brightness_grid_unsafe_data_ref(BrightnessGrid */*notnull*/ brightness_grid);
/**
* Gets the width of the [BrightnessGrid] instance.
*
* # Arguments
*
* - `brightness_grid`: instance to read from
*
* returns: width
*/
size_t sp_brightness_grid_width(BrightnessGrid */*notnull*/ brightness_grid);
/**
* Clones a [CharGrid].
*/
CharGrid */*notnull*/ sp_char_grid_clone(CharGrid */*notnull*/ grid);
/**
* Sets the value of all cells in the [CharGrid].
*
* # Arguments
*
* - `char_grid`: instance to write to
* - `value`: the value to set all cells to
*/
void sp_char_grid_fill(CharGrid */*notnull*/ char_grid, uint32_t value);
/**
* Deallocates a [CharGrid].
*/
void sp_char_grid_free(CharGrid */*notnull*/ char_grid);
/**
* Returns the current value at the specified position.
*
* # Arguments
*
* - `char_grid`: instance to read from
* - `x` and `y`: position of the cell to read
*
* # Panics
*
* - when accessing `x` or `y` out of bounds
*/
uint32_t sp_char_grid_get(CharGrid */*notnull*/ char_grid, size_t x, size_t y);
/**
* Gets the height of the [CharGrid] instance.
*
* # Arguments
*
* - `char_grid`: instance to read from
*/
size_t sp_char_grid_height(CharGrid */*notnull*/ char_grid);
/**
* Creates a [CharGridCommand] and immediately turns that into a [Packet].
*
* The provided [CharGrid] gets consumed.
*
* Returns NULL in case of an error.
*/
Packet *sp_char_grid_into_packet(CharGrid */*notnull*/ grid,
size_t x,
size_t y);
/**
* Loads a [CharGrid] with the specified dimensions from the provided data.
*
* returns: new CharGrid or NULL in case of an error
*/
CharGrid *sp_char_grid_load(size_t width, size_t height, ByteSlice data);
/**
* Creates a new [CharGrid] with the specified dimensions.
*
* returns: [CharGrid] initialized to 0.
*
* # Examples
*
* ```C
* CharGrid grid = sp_char_grid_new(4, 3);
* sp_char_grid_fill(grid, '?');
* sp_char_grid_set(grid, 0, 0, '!');
* sp_char_grid_free(grid);
* ```
*/
CharGrid */*notnull*/ sp_char_grid_new(size_t width, size_t height);
/**
* Sets the value of the specified position in the [CharGrid].
*
* # Arguments
*
* - `char_grid`: instance to write to
* - `x` and `y`: position of the cell
* - `value`: the value to write to the cell
*
* returns: old value of the cell
*
* # Panics
*
* - when accessing `x` or `y` out of bounds
*/
void sp_char_grid_set(CharGrid */*notnull*/ char_grid,
size_t x,
size_t y,
uint32_t value);
/**
* Gets the width of the [CharGrid] instance.
*
* # Arguments
*
* - `char_grid`: instance to read from
*/
size_t sp_char_grid_width(CharGrid */*notnull*/ char_grid);
BitmapCommand */*notnull*/ sp_cmd_bitmap_clone(BitmapCommand */*notnull*/ command);
void sp_cmd_bitmap_free(BitmapCommand */*notnull*/ command);
/**
* Move the provided [Bitmap] into a new [BitmapCommand],
* leaving other fields as their default values.
*
* Rust equivalent: `BitmapCommand::from(bitmap)`
*/
BitmapCommand */*notnull*/ sp_cmd_bitmap_from_bitmap(Bitmap */*notnull*/ bitmap);
/**
* Returns a pointer to the provided `BitmapCommand`.
*
* # Safety
*
* - The returned bitmap inherits the lifetime of the command in which it is contained.
* - The returned pointer may not be used in a function that consumes the instance, e.g. to create a command.
*/
Bitmap */*notnull*/ sp_cmd_bitmap_get(BitmapCommand */*notnull*/ command);
CompressionCode sp_cmd_bitmap_get_compression(BitmapCommand */*notnull*/ command);
void sp_cmd_bitmap_get_origin(BitmapCommand */*notnull*/ command,
size_t */*notnull*/ origin_x,
size_t */*notnull*/ origin_y);
Packet *sp_cmd_bitmap_into_packet(BitmapCommand */*notnull*/ command);
/**
* Sets a window of pixels to the specified values.
*
* The passed [Bitmap] gets consumed.
*
* Returns: a new [BitmapCommand] instance.
*/
BitmapCommand */*notnull*/ sp_cmd_bitmap_new(Bitmap */*notnull*/ bitmap,
size_t origin_x,
size_t origin_y,
CompressionCode compression);
/**
* Moves the provided bitmap to be contained in the command.
*/
void sp_cmd_bitmap_set(BitmapCommand */*notnull*/ command,
Bitmap */*notnull*/ bitmap);
void sp_cmd_bitmap_set_compression(BitmapCommand */*notnull*/ command,
CompressionCode compression);
void sp_cmd_bitmap_set_origin(BitmapCommand */*notnull*/ command,
size_t origin_x,
size_t origin_y);
BitVecCommand */*notnull*/ sp_cmd_bitvec_clone(BitVecCommand */*notnull*/ command);
void sp_cmd_bitvec_free(BitVecCommand */*notnull*/ command);
DisplayBitVec *sp_cmd_bitvec_get(BitVecCommand */*notnull*/ command);
CompressionCode sp_cmd_bitvec_get_compression(BitVecCommand */*notnull*/ command);
Offset sp_cmd_bitvec_get_offset(BitVecCommand */*notnull*/ command);
BinaryOperation sp_cmd_bitvec_get_operation(BitVecCommand */*notnull*/ command);
Packet *sp_cmd_bitvec_into_packet(BitVecCommand */*notnull*/ command);
/**
* Set pixel data starting at the pixel offset on screen.
*
* The screen will continuously overwrite more pixel data without regarding the offset, meaning
* once the starting row is full, overwriting will continue on column 0.
*
* The [`BinaryOperation`] will be applied on the display comparing old and sent bit.
*
* `new_bit = old_bit op sent_bit`
*
* For example, [`BinaryOperation::Or`] can be used to turn on some pixels without affecting other pixels.
*
* The contained [`DisplayBitVec`] is always uncompressed.
*/
BitVecCommand */*notnull*/ sp_cmd_bitvec_new(DisplayBitVec */*notnull*/ bitvec,
size_t offset,
BinaryOperation operation,
CompressionCode compression);
/**
* Moves the provided bitmap to be contained in the command.
*/
void sp_cmd_bitvec_set(BitVecCommand */*notnull*/ command,
DisplayBitVec */*notnull*/ bitvec);
void sp_cmd_bitvec_set_compression(BitVecCommand */*notnull*/ command,
CompressionCode compression);
void sp_cmd_bitvec_set_offset(BitVecCommand */*notnull*/ command,
Offset offset);
void sp_cmd_bitvec_set_operation(BitVecCommand */*notnull*/ command,
BinaryOperation operation);
GlobalBrightnessCommand */*notnull*/ sp_cmd_brightness_global_clone(GlobalBrightnessCommand */*notnull*/ command);
void sp_cmd_brightness_global_free(BitmapCommand */*notnull*/ command);
Brightness *sp_cmd_brightness_global_get(GlobalBrightnessCommand */*notnull*/ command);
Packet *sp_cmd_brightness_global_into_packet(GlobalBrightnessCommand */*notnull*/ command);
GlobalBrightnessCommand */*notnull*/ sp_cmd_brightness_global_new(Brightness brightness);
/**
* Moves the provided bitmap to be contained in the command.
*/
void sp_cmd_brightness_global_set(GlobalBrightnessCommand */*notnull*/ command,
Brightness brightness);
BrightnessGridCommand */*notnull*/ sp_cmd_brightness_grid_clone(BrightnessGridCommand */*notnull*/ command);
void sp_cmd_brightness_grid_free(BitmapCommand */*notnull*/ command);
BrightnessGridCommand */*notnull*/ sp_cmd_brightness_grid_from_grid(BrightnessGrid */*notnull*/ grid);
BrightnessGrid *sp_cmd_brightness_grid_get(BrightnessGridCommand */*notnull*/ command);
void sp_cmd_brightness_grid_get_origin(BrightnessGridCommand */*notnull*/ command,
size_t */*notnull*/ origin_x,
size_t */*notnull*/ origin_y);
Packet *sp_cmd_brightness_grid_into_packet(BrightnessGridCommand */*notnull*/ command);
BrightnessGridCommand */*notnull*/ sp_cmd_brightness_grid_new(BrightnessGrid */*notnull*/ grid,
size_t origin_x,
size_t origin_y);
/**
* Moves the provided bitmap to be contained in the command.
*/
void sp_cmd_brightness_grid_set(BrightnessGridCommand */*notnull*/ command,
BrightnessGrid */*notnull*/ grid);
void sp_cmd_brightness_grid_set_origin(BrightnessGridCommand */*notnull*/ command,
size_t origin_x,
size_t origin_y);
CharGridCommand */*notnull*/ sp_cmd_char_grid_clone(CharGridCommand */*notnull*/ command);
void sp_cmd_char_grid_free(BitmapCommand */*notnull*/ command);
CharGridCommand */*notnull*/ sp_cmd_char_grid_from_grid(CharGrid */*notnull*/ grid);
CharGrid *sp_cmd_char_grid_get(CharGridCommand */*notnull*/ command);
void sp_cmd_char_grid_get_origin(CharGridCommand */*notnull*/ command,
size_t */*notnull*/ origin_x,
size_t */*notnull*/ origin_y);
Packet *sp_cmd_char_grid_into_packet(CharGridCommand */*notnull*/ command);
CharGridCommand */*notnull*/ sp_cmd_char_grid_new(CharGrid */*notnull*/ grid,
size_t origin_x,
size_t origin_y);
/**
* Moves the provided bitmap to be contained in the command.
*/
void sp_cmd_char_grid_set(CharGridCommand */*notnull*/ command,
CharGrid */*notnull*/ grid);
void sp_cmd_char_grid_set_origin(CharGridCommand */*notnull*/ command,
size_t origin_x,
size_t origin_y);
void sp_cmd_clear_free(ClearCommand */*notnull*/ command);
/**
* Set all pixels to the off state.
*
* Does not affect brightness.
*
* Returns: a new [ClearCommand] instance.
*
* # Examples
*
* ```C
* sp_udp_send_command(connection, sp_cmd_clear());
* ```
*/
ClearCommand */*notnull*/ sp_cmd_clear_new(void);
Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_clone(Cp437GridCommand */*notnull*/ command);
void sp_cmd_cp437_grid_free(BitmapCommand */*notnull*/ command);
Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_from_grid(Cp437Grid */*notnull*/ grid);
Cp437Grid *sp_cmd_cp437_grid_get(Cp437GridCommand */*notnull*/ command);
/**
* Gets the origin field of the [Cp437GridCommand].
*
* Rust equivalent: `cp437_command.origin`
*/
void sp_cmd_cp437_grid_get_origin(Cp437GridCommand */*notnull*/ command,
size_t */*notnull*/ origin_x,
size_t */*notnull*/ origin_y);
Packet *sp_cmd_cp437_grid_into_packet(Cp437GridCommand */*notnull*/ command);
Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_new(Cp437Grid */*notnull*/ grid,
size_t origin_x,
size_t origin_y);
/**
* Moves the provided bitmap into the provided command.
*
* This drops the previously contained [Cp437Grid].
*/
void sp_cmd_cp437_grid_set(Cp437GridCommand */*notnull*/ command,
Cp437Grid */*notnull*/ grid);
/**
* Sets the origin field of the [Cp437GridCommand].
*
* Rust equivalent: `cp437_command.origin = Origin::new(origin_x, origin_y)`
*/
void sp_cmd_cp437_grid_set_origin(Cp437GridCommand */*notnull*/ command,
size_t origin_x,
size_t origin_y);
void sp_cmd_fade_out_free(ClearCommand */*notnull*/ command);
/**
* A yet-to-be-tested command.
*
* Returns: a new [FadeOutCommand] instance.
*/
FadeOutCommand */*notnull*/ sp_cmd_fade_out_new(void);
/**
* Clones a [SPCommand] instance.
*
* returns: new [SPCommand] instance.
*/
SPCommand sp_cmd_generic_clone(SPCommand command);
/**
* Deallocates a [SPCommand].
*
* # Examples
*
* ```C
* TypedCommand c = sp_command_clear();
* sp_command_free(c);
* ```
*/
void sp_cmd_generic_free(SPCommand command);
/**
* Turns a [TypedCommand] into a [Packet].
* The [TypedCommand] gets consumed.
*
* Returns NULL in case of an error.
*/
Packet *sp_cmd_generic_into_packet(SPCommand command);
/**
* Tries to turn a [Packet] into a [TypedCommand].
*
* The packet is deallocated in the process.
*
* Returns: pointer to new [TypedCommand] instance or NULL if parsing failed.
*/
SPCommand *sp_cmd_generic_try_from_packet(Packet */*notnull*/ packet);
void sp_cmd_hard_reset_free(ClearCommand */*notnull*/ command);
/**
* Kills the udp daemon on the display, which usually results in a restart.
*
* Please do not send this in your normal program flow.
*
* Returns: a new [HardResetCommand] instance.
*/
HardResetCommand */*notnull*/ sp_cmd_hard_reset_new(void);
/**
* Clones a [Cp437Grid].
*/
Cp437Grid */*notnull*/ sp_cp437_grid_clone(Cp437Grid */*notnull*/ grid);
/**
* Sets the value of all cells in the [Cp437Grid].
*
* # Arguments
*
* - `cp437_grid`: instance to write to
* - `value`: the value to set all cells to
*/
void sp_cp437_grid_fill(Cp437Grid */*notnull*/ cp437_grid, uint8_t value);
/**
* Deallocates a [Cp437Grid].
*/
void sp_cp437_grid_free(Cp437Grid */*notnull*/ cp437_grid);
/**
* Gets the current value at the specified position.
*
* # Arguments
*
* - `cp437_grid`: instance to read from
* - `x` and `y`: position of the cell to read
*
* # Panics
*
* - when accessing `x` or `y` out of bounds
*/
uint8_t sp_cp437_grid_get(Cp437Grid */*notnull*/ cp437_grid,
size_t x,
size_t y);
/**
* Gets the height of the [Cp437Grid] instance.
*
* # Arguments
*
* - `cp437_grid`: instance to read from
*/
size_t sp_cp437_grid_height(Cp437Grid */*notnull*/ cp437_grid);
/**
* Creates a [Cp437GridCommand] and immediately turns that into a [Packet].
*
* The provided [Cp437Grid] gets consumed.
*
* Returns NULL in case of an error.
*/
Packet *sp_cp437_grid_into_packet(Cp437Grid */*notnull*/ grid,
size_t x,
size_t y);
/**
* Loads a [Cp437Grid] with the specified dimensions from the provided data.
*/
Cp437Grid *sp_cp437_grid_load(size_t width, size_t height, ByteSlice data);
/**
* Creates a new [Cp437Grid] with the specified dimensions.
*
* returns: [Cp437Grid] initialized to 0.
*/
Cp437Grid */*notnull*/ sp_cp437_grid_new(size_t width, size_t height);
/**
* Sets the value of the specified position in the [Cp437Grid].
*
* # Arguments
*
* - `cp437_grid`: instance to write to
* - `x` and `y`: position of the cell
* - `value`: the value to write to the cell
*
* returns: old value of the cell
*
* # Panics
*
* - when accessing `x` or `y` out of bounds
*/
void sp_cp437_grid_set(Cp437Grid */*notnull*/ cp437_grid,
size_t x,
size_t y,
uint8_t value);
/**
* Gets an unsafe reference to the data of the [Cp437Grid] instance.
*
* The returned memory is valid for the lifetime of the grid.
*/
ByteSlice sp_cp437_grid_unsafe_data_ref(Cp437Grid */*notnull*/ cp437_grid);
/**
* Gets the width of the [Cp437Grid] instance.
*
* # Arguments
*
* - `cp437_grid`: instance to read from
*/
size_t sp_cp437_grid_width(Cp437Grid */*notnull*/ cp437_grid);
/**
* Clones a [Packet].
*/
Packet */*notnull*/ sp_packet_clone(Packet */*notnull*/ packet);
/**
* Deallocates a [Packet].
*/
void sp_packet_free(Packet */*notnull*/ packet);
/**
* Creates a raw [Packet] from parts.
*
* returns: new instance. Will never return null.
*/
Packet */*notnull*/ sp_packet_from_parts(Header header,
const ByteSlice *payload);
/**
* Returns a pointer to the header field of the provided packet.
*
* The returned header can be changed and will be valid for the lifetime of the packet.
*/
Header */*notnull*/ sp_packet_get_header(Packet */*notnull*/ packet);
/**
* Returns a pointer to the current payload of the provided packet.
*
* The returned memory can be changed and will be valid until a new payload is set.
*/
ByteSlice sp_packet_get_payload(Packet */*notnull*/ packet);
/**
* Serialize the packet into the provided buffer.
*
* # Panics
*
* - if the buffer is not big enough to hold header+payload.
*/
void sp_packet_serialize_to(Packet */*notnull*/ packet, ByteSlice buffer);
/**
* Sets the payload of the provided packet to the provided data.
*
* This makes previous payload pointers invalid.
*/
void sp_packet_set_payload(Packet */*notnull*/ packet, ByteSlice data);
/**
* Tries to load a [Packet] from the passed array with the specified length.
*
* returns: NULL in case of an error, pointer to the allocated packet otherwise
*/
Packet *sp_packet_try_load(ByteSlice data);
/**
* Converts u16 into [CommandCode].
*
* If the provided value is not valid, false is returned and result is not changed.
*/
bool sp_u16_to_command_code(uint16_t code,
CommandCode *result);
/**
* Closes and deallocates a [UdpSocket].
*/
void sp_udp_free(UdpSocket */*notnull*/ connection);
/**
* Creates a new instance of [UdpSocket].
*
* returns: NULL if connection fails, or connected instance
*
* # Examples
*
* ```C
* UdpSocket connection = sp_udp_open("172.23.42.29:2342");
* if (connection != NULL)
* sp_udp_send_command(connection, sp_command_clear());
* ```
*/
UdpSocket *sp_udp_open(char */*notnull*/ host);
/**
* Creates a new instance of [UdpSocket].
*
* returns: NULL if connection fails, or connected instance
*
* # Examples
*
* ```C
* UdpSocket connection = sp_udp_open_ipv4(172, 23, 42, 29, 2342);
* if (connection != NULL)
* sp_udp_send_command(connection, sp_command_clear());
* ```
*/
UdpSocket *sp_udp_open_ipv4(uint8_t ip1,
uint8_t ip2,
uint8_t ip3,
uint8_t ip4,
uint16_t port);
/**
* Sends a [SPCommand] to the display using the [UdpSocket].
*
* The passed `command` gets consumed.
*
* returns: true in case of success
*
* # Examples
*
* ```C
* sp_udp_send_command(connection, sp_command_brightness(5));
* ```
*/
bool sp_udp_send_command(UdpSocket */*notnull*/ connection, SPCommand command);
/**
* Sends a [Header] to the display using the [UdpSocket].
*
* returns: true in case of success
*
* # Examples
*
* ```C
* sp_udp_send_header(connection, sp_command_brightness(5));
* ```
*/
bool sp_udp_send_header(UdpSocket */*notnull*/ udp_connection, Header header);
/**
* Sends a [Packet] to the display using the [UdpSocket].
*
* The passed `packet` gets consumed.
*
* returns: true in case of success
*/
bool sp_udp_send_packet(UdpSocket */*notnull*/ connection,
Packet */*notnull*/ packet);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus