improve c build

This commit is contained in:
Vinzenz Schroeter 2024-05-26 11:40:52 +02:00
parent f2d98af532
commit edcad6fd03
11 changed files with 77 additions and 320 deletions

View file

@ -7,7 +7,7 @@ license = "GPL-3.0-or-later"
description = "A rust library for the CCCB Service Point Display."
homepage = "https://docs.rs/crate/servicepoint"
repository = "https://github.com/cccb/servicepoint"
readme = "../README.md"
readme = "../../README.md"
[lib]
crate-type = ["staticlib", "rlib", "cdylib"]

View file

@ -7,7 +7,8 @@ license = "GPL-3.0-or-later"
description = "C bindings for the servicepoint crate."
homepage = "https://docs.rs/crate/servicepoint"
repository = "https://github.com/cccb/servicepoint"
readme = "../README.md"
readme = "../../README.md"
links = "servicepoint"
[build-dependencies]
cbindgen = "0.26.0"

View file

@ -1,13 +1,28 @@
use std::env;
use std::{env, fs::copy};
use cbindgen::{generate_with_config, Config};
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let config = Config::from_file(crate_dir.clone() + "/cbindgen.toml").unwrap();
println!("cargo::rerun-if-changed={crate_dir}");
let config =
Config::from_file(crate_dir.clone() + "/cbindgen.toml").unwrap();
let servicepoint_dir = crate_dir.clone() + "/../servicepoint";
let output_dir = env::var("OUT_DIR").unwrap();
let header_file = output_dir.clone() + "/servicepoint.h";
generate_with_config(servicepoint_dir, config)
.unwrap()
.write_to_file("servicepoint.h");
.unwrap()
.write_to_file(&header_file);
println!("cargo:include={output_dir}");
println!("cargo::rerun-if-env-changed=SERVICEPOINT_HEADER_OUT");
if let Ok(header_out) = env::var("SERVICEPOINT_HEADER_OUT") {
let header_copy = header_out + "/servicepoint.h";
println!("cargo:warning=Copying header to {header_copy}");
copy(header_file, &header_copy).unwrap();
println!("cargo::rerun-if-changed={header_copy}");
}
}

View file

@ -1,463 +0,0 @@
/* Generated with cbindgen:0.26.0 */
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
/**
* pixel count on whole screen
*/
#define sp2_PIXEL_COUNT (sp2_PIXEL_WIDTH * sp2_PIXEL_HEIGHT)
/**
* screen height in pixels
*/
#define sp2_PIXEL_HEIGHT (sp2_TILE_HEIGHT * sp2_TILE_SIZE)
/**
* screen width in pixels
*/
#define sp2_PIXEL_WIDTH (sp2_TILE_WIDTH * sp2_TILE_SIZE)
/**
* tile count in the y-direction
*/
#define sp2_TILE_HEIGHT 20
/**
* size of a single tile in one dimension
*/
#define sp2_TILE_SIZE 8
/**
* tile count in the x-direction
*/
#define sp2_TILE_WIDTH 56
/**
* Specifies the kind of compression to use. Availability depends on features.
*/
enum sp2_CompressionCode
#ifdef __cplusplus
: uint16_t
#endif // __cplusplus
{
Uncompressed = 0,
#if defined(SP2_FEATURE_compression_zlib)
Zlib = 26490,
#endif
#if defined(SP2_FEATURE_compression_bzip2)
Bzip2 = 25210,
#endif
#if defined(SP2_FEATURE_compression_lzma)
Lzma = 27770,
#endif
#if defined(SP2_FEATURE_compression_zstd)
Zstd = 31347,
#endif
};
#ifndef __cplusplus
typedef uint16_t sp2_CompressionCode;
#endif // __cplusplus
/**
* A vector of bits
*/
typedef struct sp2_BitVec sp2_BitVec;
/**
* A 2D grid of bytes
*/
typedef struct sp2_ByteGrid sp2_ByteGrid;
/**
* A command to send to the display.
*/
typedef struct sp2_Command sp2_Command;
/**
* A connection to the display.
*/
typedef struct sp2_Connection sp2_Connection;
/**
* The raw packet. Should probably not be used directly.
*/
typedef struct sp2_Packet sp2_Packet;
/**
* A grid of pixels stored in packed bytes.
*/
typedef struct sp2_PixelGrid sp2_PixelGrid;
/**
* Represents a span of memory (`&mut [u8]` ) as a struct usable by C code.
*
* Usage of this type is inherently unsafe.
*/
typedef struct sp2_CByteSlice {
/**
* The start address of the memory
*/
uint8_t *start;
/**
* The amount of memory in bytes
*/
size_t length;
} sp2_CByteSlice;
/**
* Type alias for documenting the meaning of the u16 in enum values
*/
typedef size_t sp2_Offset;
/**
* Type alias for documenting the meaning of the u16 in enum values
*/
typedef uint8_t sp2_Brightness;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/**
* Clones a `BitVec`.
* The returned instance has to be freed with `bit_vec_dealloc`.
*/
struct sp2_BitVec *sp2_bit_vec_clone(const struct sp2_BitVec *this_);
/**
* Deallocates a `BitVec`.
*
* Note: do not call this if the grid has been consumed in another way, e.g. to create a command.
*/
void sp2_bit_vec_dealloc(struct sp2_BitVec *this_);
/**
* Sets the value of all bits in the `BitVec`.
*/
void sp2_bit_vec_fill(struct sp2_BitVec *this_, bool value);
/**
* Gets the value of a bit from the `BitVec`.
*/
bool sp2_bit_vec_get(const struct sp2_BitVec *this_, size_t index);
/**
* Returns true if length is 0.
*/
bool sp2_bit_vec_is_empty(const struct sp2_BitVec *this_);
/**
* Gets the length of the `BitVec` in bits.
*/
size_t sp2_bit_vec_len(const struct sp2_BitVec *this_);
/**
* Loads a `BitVec` from the provided data.
* The returned instance has to be freed with `bit_vec_dealloc`.
*/
struct sp2_BitVec *sp2_bit_vec_load(const uint8_t *data, size_t data_length);
/**
* Creates a new `BitVec` instance.
* The returned instance has to be freed with `bit_vec_dealloc`.
*/
struct sp2_BitVec *sp2_bit_vec_new(size_t size);
/**
* Sets the value of a bit in the `BitVec`.
*/
bool sp2_bit_vec_set(struct sp2_BitVec *this_, size_t index, bool value);
/**
* Gets an unsafe reference to the data of the `BitVec` instance.
*
* ## Safety
*
* The caller has to make sure to never access the returned memory after the `BitVec`
* instance has been consumed or manually deallocated.
*
* Reading and writing concurrently to either the original instance or the returned data will
* result in undefined behavior.
*/
struct sp2_CByteSlice sp2_bit_vec_unsafe_data_ref(struct sp2_BitVec *this_);
/**
* Clones a `ByteGrid`.
* The returned instance has to be freed with `byte_grid_dealloc`.
*/
struct sp2_ByteGrid *sp2_byte_grid_clone(const struct sp2_ByteGrid *this_);
/**
* Deallocates a `ByteGrid`.
*
* Note: do not call this if the grid has been consumed in another way, e.g. to create a command.
*/
void sp2_byte_grid_dealloc(struct sp2_ByteGrid *this_);
/**
* Fills the whole `ByteGrid` with the specified value
*/
void sp2_byte_grid_fill(struct sp2_ByteGrid *this_, uint8_t value);
/**
* Get the current value at the specified position
*/
uint8_t sp2_byte_grid_get(const struct sp2_ByteGrid *this_, size_t x, size_t y);
/**
* Gets the height in pixels of the `ByteGrid` instance.
*/
size_t sp2_byte_grid_height(const struct sp2_ByteGrid *this_);
/**
* Loads a `ByteGrid` with the specified dimensions from the provided data.
* The returned instance has to be freed with `byte_grid_dealloc`.
*/
struct sp2_ByteGrid *sp2_byte_grid_load(size_t width,
size_t height,
const uint8_t *data,
size_t data_length);
/**
* Creates a new `ByteGrid` instance.
* The returned instance has to be freed with `byte_grid_dealloc`.
*/
struct sp2_ByteGrid *sp2_byte_grid_new(size_t width, size_t height);
/**
* Sets the current value at the specified position
*/
void sp2_byte_grid_set(struct sp2_ByteGrid *this_,
size_t x,
size_t y,
uint8_t value);
/**
* Gets an unsafe reference to the data of the `ByteGrid` instance.
*
* ## Safety
*
* The caller has to make sure to never access the returned memory after the `ByteGrid`
* instance has been consumed or manually deallocated.
*
* Reading and writing concurrently to either the original instance or the returned data will
* result in undefined behavior.
*/
struct sp2_CByteSlice sp2_byte_grid_unsafe_data_ref(struct sp2_ByteGrid *this_);
/**
* Gets the width in pixels of the `ByteGrid` instance.
*/
size_t sp2_byte_grid_width(const struct sp2_ByteGrid *this_);
/**
* Allocates a new `Command::BitmapLinear` instance.
* The passed `BitVec` gets deallocated in the process.
*/
struct sp2_Command *sp2_command_bitmap_linear(sp2_Offset offset,
struct sp2_BitVec *bit_vec,
sp2_CompressionCode compression);
/**
* Allocates a new `Command::BitmapLinearAnd` instance.
* The passed `BitVec` gets deallocated in the process.
*/
struct sp2_Command *sp2_command_bitmap_linear_and(sp2_Offset offset,
struct sp2_BitVec *bit_vec,
sp2_CompressionCode compression);
/**
* Allocates a new `Command::BitmapLinearOr` instance.
* The passed `BitVec` gets deallocated in the process.
*/
struct sp2_Command *sp2_command_bitmap_linear_or(sp2_Offset offset,
struct sp2_BitVec *bit_vec,
sp2_CompressionCode compression);
/**
* Allocates a new `Command::BitmapLinearWin` instance.
* The passed `PixelGrid` gets deallocated in the process.
*/
struct sp2_Command *sp2_command_bitmap_linear_win(size_t x,
size_t y,
struct sp2_PixelGrid *byte_grid,
sp2_CompressionCode compression_code);
/**
* Allocates a new `Command::BitmapLinearXor` instance.
* The passed `BitVec` gets deallocated in the process.
*/
struct sp2_Command *sp2_command_bitmap_linear_xor(sp2_Offset offset,
struct sp2_BitVec *bit_vec,
sp2_CompressionCode compression);
/**
* Allocates a new `Command::Brightness` instance
*/
struct sp2_Command *sp2_command_brightness(sp2_Brightness brightness);
/**
* Allocates a new `Command::CharBrightness` instance.
* The passed `ByteGrid` gets deallocated in the process.
*/
struct sp2_Command *sp2_command_char_brightness(size_t x,
size_t y,
struct sp2_ByteGrid *byte_grid);
/**
* Allocates a new `Command::Clear` instance
*/
struct sp2_Command *sp2_command_clear(void);
/**
* Clones a `Command` instance
*/
struct sp2_Command *sp2_command_clone(const struct sp2_Command *original);
/**
* Allocates a new `Command::Cp437Data` instance.
* The passed `ByteGrid` gets deallocated in the process.
*/
struct sp2_Command *sp2_command_cp437_data(size_t x,
size_t y,
struct sp2_ByteGrid *byte_grid);
/**
* Deallocates a `Command`. Note that connection_send does this implicitly, so you only need
* to do this if you use the library for parsing commands.
*/
void sp2_command_dealloc(struct sp2_Command *ptr);
/**
* Allocates a new `Command::FadeOut` instance
*/
struct sp2_Command *sp2_command_fade_out(void);
/**
* Allocates a new `Command::HardReset` instance
*/
struct sp2_Command *sp2_command_hard_reset(void);
/**
* Tries to turn a `Packet` into a `Command`. The packet is gets deallocated in the process.
*
* Returns: pointer to command or NULL
*/
struct sp2_Command *sp2_command_try_from_packet(struct sp2_Packet *packet);
/**
* Closes and deallocates a connection instance
*/
void sp2_connection_dealloc(struct sp2_Connection *ptr);
/**
* Creates a new instance of Connection.
* The returned instance has to be deallocated with `connection_dealloc`.
*
* returns: NULL if connection fails or connected instance
*
* Panics: bad string encoding
*/
struct sp2_Connection *sp2_connection_open(const char *host);
/**
* Sends the command instance. The instance is consumed / destroyed and cannot be used after this call.
*/
bool sp2_connection_send(const struct sp2_Connection *connection,
struct sp2_Packet *command_ptr);
/**
* Deallocates a `Packet`.
*
* Note: do not call this if the instance has been consumed in another way, e.g. by sending it.
*/
void sp2_packet_dealloc(struct sp2_Packet *this_);
/**
* Turns a `Command` into a `Packet`. The command gets deallocated in the process.
*/
struct sp2_Packet *sp2_packet_from_command(struct sp2_Command *command);
/**
* 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
*/
struct sp2_Packet *sp2_packet_try_load(const uint8_t *data, size_t length);
/**
* Clones a `PixelGrid`.
* The returned instance has to be freed with `pixel_grid_dealloc`.
*/
struct sp2_PixelGrid *sp2_pixel_grid_clone(const struct sp2_PixelGrid *this_);
/**
* Deallocates a `PixelGrid`.
*
* Note: do not call this if the grid has been consumed in another way, e.g. to create a command.
*/
void sp2_pixel_grid_dealloc(struct sp2_PixelGrid *this_);
/**
* Fills the whole `PixelGrid` with the specified value
*/
void sp2_pixel_grid_fill(struct sp2_PixelGrid *this_, bool value);
/**
* Get the current value at the specified position
*/
bool sp2_pixel_grid_get(const struct sp2_PixelGrid *this_, size_t x, size_t y);
/**
* Gets the height in pixels of the `PixelGrid` instance.
*/
size_t sp2_pixel_grid_height(const struct sp2_PixelGrid *this_);
/**
* Loads a `PixelGrid` with the specified dimensions from the provided data.
* The returned instance has to be freed with `pixel_grid_dealloc`.
*/
struct sp2_PixelGrid *sp2_pixel_grid_load(size_t width,
size_t height,
const uint8_t *data,
size_t data_length);
/**
* Creates a new `PixelGrid` instance.
* The returned instance has to be freed with `pixel_grid_dealloc`.
*/
struct sp2_PixelGrid *sp2_pixel_grid_new(size_t width, size_t height);
/**
* Sets the current value at the specified position
*/
void sp2_pixel_grid_set(struct sp2_PixelGrid *this_,
size_t x,
size_t y,
bool value);
/**
* Gets an unsafe reference to the data of the `PixelGrid` instance.
*
* ## Safety
*
* The caller has to make sure to never access the returned memory after the `PixelGrid`
* instance has been consumed or manually deallocated.
*
* Reading and writing concurrently to either the original instance or the returned data will
* result in undefined behavior.
*/
struct sp2_CByteSlice sp2_pixel_grid_unsafe_data_ref(struct sp2_PixelGrid *this_);
/**
* Gets the width in pixels of the `PixelGrid` instance.
*/
size_t sp2_pixel_grid_width(const struct sp2_PixelGrid *this_);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus

View file

@ -3,6 +3,7 @@ name = "servicepoint_binding_cs"
version = "0.4.2"
edition = "2021"
publish = false
readme = "../../README.md"
[lib]
crate-type = ["cdylib"]

View file

@ -1,286 +0,0 @@
// <auto-generated>
// This code is generated by csbindgen.
// DON'T CHANGE THIS DIRECTLY.
// </auto-generated>
#pragma warning disable CS8500
#pragma warning disable CS8981
using System;
using System.Runtime.InteropServices;
namespace ServicePoint.BindGen
{
public static unsafe partial class NativeMethods
{
const string __DllName = "servicepoint";
/// <summary>Creates a new `BitVec` instance. The returned instance has to be freed with `bit_vec_dealloc`.</summary>
[DllImport(__DllName, EntryPoint = "sp2_bit_vec_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern BitVec* sp2_bit_vec_new(nuint size);
/// <summary>Loads a `BitVec` from the provided data. The returned instance has to be freed with `bit_vec_dealloc`.</summary>
[DllImport(__DllName, EntryPoint = "sp2_bit_vec_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern BitVec* sp2_bit_vec_load(byte* data, nuint data_length);
/// <summary>Clones a `BitVec`. The returned instance has to be freed with `bit_vec_dealloc`.</summary>
[DllImport(__DllName, EntryPoint = "sp2_bit_vec_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern BitVec* sp2_bit_vec_clone(BitVec* @this);
/// <summary>Deallocates a `BitVec`. Note: do not call this if the grid has been consumed in another way, e.g. to create a command.</summary>
[DllImport(__DllName, EntryPoint = "sp2_bit_vec_dealloc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void sp2_bit_vec_dealloc(BitVec* @this);
/// <summary>Gets the value of a bit from the `BitVec`.</summary>
[DllImport(__DllName, EntryPoint = "sp2_bit_vec_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.U1)]
public static extern bool sp2_bit_vec_get(BitVec* @this, nuint index);
/// <summary>Sets the value of a bit in the `BitVec`.</summary>
[DllImport(__DllName, EntryPoint = "sp2_bit_vec_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.U1)]
public static extern bool sp2_bit_vec_set(BitVec* @this, nuint index, [MarshalAs(UnmanagedType.U1)] bool value);
/// <summary>Sets the value of all bits in the `BitVec`.</summary>
[DllImport(__DllName, EntryPoint = "sp2_bit_vec_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void sp2_bit_vec_fill(BitVec* @this, [MarshalAs(UnmanagedType.U1)] bool value);
/// <summary>Gets the length of the `BitVec` in bits.</summary>
[DllImport(__DllName, EntryPoint = "sp2_bit_vec_len", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern nuint sp2_bit_vec_len(BitVec* @this);
/// <summary>Returns true if length is 0.</summary>
[DllImport(__DllName, EntryPoint = "sp2_bit_vec_is_empty", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.U1)]
public static extern bool sp2_bit_vec_is_empty(BitVec* @this);
/// <summary>Gets an unsafe reference to the data of the `BitVec` instance. ## Safety The caller has to make sure to never access the returned memory after the `BitVec` instance has been consumed or manually deallocated. Reading and writing concurrently to either the original instance or the returned data will result in undefined behavior.</summary>
[DllImport(__DllName, EntryPoint = "sp2_bit_vec_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern CByteSlice sp2_bit_vec_unsafe_data_ref(BitVec* @this);
/// <summary>Creates a new `ByteGrid` instance. The returned instance has to be freed with `byte_grid_dealloc`.</summary>
[DllImport(__DllName, EntryPoint = "sp2_byte_grid_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ByteGrid* sp2_byte_grid_new(nuint width, nuint height);
/// <summary>Loads a `ByteGrid` with the specified dimensions from the provided data. The returned instance has to be freed with `byte_grid_dealloc`.</summary>
[DllImport(__DllName, EntryPoint = "sp2_byte_grid_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ByteGrid* sp2_byte_grid_load(nuint width, nuint height, byte* data, nuint data_length);
/// <summary>Clones a `ByteGrid`. The returned instance has to be freed with `byte_grid_dealloc`.</summary>
[DllImport(__DllName, EntryPoint = "sp2_byte_grid_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern ByteGrid* sp2_byte_grid_clone(ByteGrid* @this);
/// <summary>Deallocates a `ByteGrid`. Note: do not call this if the grid has been consumed in another way, e.g. to create a command.</summary>
[DllImport(__DllName, EntryPoint = "sp2_byte_grid_dealloc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void sp2_byte_grid_dealloc(ByteGrid* @this);
/// <summary>Get the current value at the specified position</summary>
[DllImport(__DllName, EntryPoint = "sp2_byte_grid_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern byte sp2_byte_grid_get(ByteGrid* @this, nuint x, nuint y);
/// <summary>Sets the current value at the specified position</summary>
[DllImport(__DllName, EntryPoint = "sp2_byte_grid_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void sp2_byte_grid_set(ByteGrid* @this, nuint x, nuint y, byte value);
/// <summary>Fills the whole `ByteGrid` with the specified value</summary>
[DllImport(__DllName, EntryPoint = "sp2_byte_grid_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void sp2_byte_grid_fill(ByteGrid* @this, byte value);
/// <summary>Gets the width in pixels of the `ByteGrid` instance.</summary>
[DllImport(__DllName, EntryPoint = "sp2_byte_grid_width", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern nuint sp2_byte_grid_width(ByteGrid* @this);
/// <summary>Gets the height in pixels of the `ByteGrid` instance.</summary>
[DllImport(__DllName, EntryPoint = "sp2_byte_grid_height", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern nuint sp2_byte_grid_height(ByteGrid* @this);
/// <summary>Gets an unsafe reference to the data of the `ByteGrid` instance. ## Safety The caller has to make sure to never access the returned memory after the `ByteGrid` instance has been consumed or manually deallocated. Reading and writing concurrently to either the original instance or the returned data will result in undefined behavior.</summary>
[DllImport(__DllName, EntryPoint = "sp2_byte_grid_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern CByteSlice sp2_byte_grid_unsafe_data_ref(ByteGrid* @this);
/// <summary>Tries to turn a `Packet` into a `Command`. The packet is gets deallocated in the process. Returns: pointer to command or NULL</summary>
[DllImport(__DllName, EntryPoint = "sp2_command_try_from_packet", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern Command* sp2_command_try_from_packet(Packet* packet);
/// <summary>Clones a `Command` instance</summary>
[DllImport(__DllName, EntryPoint = "sp2_command_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern Command* sp2_command_clone(Command* original);
/// <summary>Allocates a new `Command::Clear` instance</summary>
[DllImport(__DllName, EntryPoint = "sp2_command_clear", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern Command* sp2_command_clear();
/// <summary>Allocates a new `Command::HardReset` instance</summary>
[DllImport(__DllName, EntryPoint = "sp2_command_hard_reset", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern Command* sp2_command_hard_reset();
/// <summary>Allocates a new `Command::FadeOut` instance</summary>
[DllImport(__DllName, EntryPoint = "sp2_command_fade_out", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern Command* sp2_command_fade_out();
/// <summary>Allocates a new `Command::Brightness` instance</summary>
[DllImport(__DllName, EntryPoint = "sp2_command_brightness", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern Command* sp2_command_brightness(byte brightness);
/// <summary>Allocates a new `Command::CharBrightness` instance. The passed `ByteGrid` gets deallocated in the process.</summary>
[DllImport(__DllName, EntryPoint = "sp2_command_char_brightness", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern Command* sp2_command_char_brightness(nuint x, nuint y, ByteGrid* byte_grid);
/// <summary>Allocates a new `Command::BitmapLinear` instance. The passed `BitVec` gets deallocated in the process.</summary>
[DllImport(__DllName, EntryPoint = "sp2_command_bitmap_linear", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern Command* sp2_command_bitmap_linear(nuint offset, BitVec* bit_vec, CompressionCode compression);
/// <summary>Allocates a new `Command::BitmapLinearAnd` instance. The passed `BitVec` gets deallocated in the process.</summary>
[DllImport(__DllName, EntryPoint = "sp2_command_bitmap_linear_and", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern Command* sp2_command_bitmap_linear_and(nuint offset, BitVec* bit_vec, CompressionCode compression);
/// <summary>Allocates a new `Command::BitmapLinearOr` instance. The passed `BitVec` gets deallocated in the process.</summary>
[DllImport(__DllName, EntryPoint = "sp2_command_bitmap_linear_or", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern Command* sp2_command_bitmap_linear_or(nuint offset, BitVec* bit_vec, CompressionCode compression);
/// <summary>Allocates a new `Command::BitmapLinearXor` instance. The passed `BitVec` gets deallocated in the process.</summary>
[DllImport(__DllName, EntryPoint = "sp2_command_bitmap_linear_xor", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern Command* sp2_command_bitmap_linear_xor(nuint offset, BitVec* bit_vec, CompressionCode compression);
/// <summary>Allocates a new `Command::Cp437Data` instance. The passed `ByteGrid` gets deallocated in the process.</summary>
[DllImport(__DllName, EntryPoint = "sp2_command_cp437_data", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern Command* sp2_command_cp437_data(nuint x, nuint y, ByteGrid* byte_grid);
/// <summary>Allocates a new `Command::BitmapLinearWin` instance. The passed `PixelGrid` gets deallocated in the process.</summary>
[DllImport(__DllName, EntryPoint = "sp2_command_bitmap_linear_win", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern Command* sp2_command_bitmap_linear_win(nuint x, nuint y, PixelGrid* byte_grid, CompressionCode compression_code);
/// <summary>Deallocates a `Command`. Note that connection_send does this implicitly, so you only need to do this if you use the library for parsing commands.</summary>
[DllImport(__DllName, EntryPoint = "sp2_command_dealloc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void sp2_command_dealloc(Command* ptr);
/// <summary>Creates a new instance of Connection. The returned instance has to be deallocated with `connection_dealloc`. returns: NULL if connection fails or connected instance Panics: bad string encoding</summary>
[DllImport(__DllName, EntryPoint = "sp2_connection_open", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern Connection* sp2_connection_open(byte* host);
/// <summary>Sends the command instance. The instance is consumed / destroyed and cannot be used after this call.</summary>
[DllImport(__DllName, EntryPoint = "sp2_connection_send", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.U1)]
public static extern bool sp2_connection_send(Connection* connection, Packet* command_ptr);
/// <summary>Closes and deallocates a connection instance</summary>
[DllImport(__DllName, EntryPoint = "sp2_connection_dealloc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void sp2_connection_dealloc(Connection* ptr);
/// <summary>Creates a new `PixelGrid` instance. The returned instance has to be freed with `pixel_grid_dealloc`.</summary>
[DllImport(__DllName, EntryPoint = "sp2_pixel_grid_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern PixelGrid* sp2_pixel_grid_new(nuint width, nuint height);
/// <summary>Loads a `PixelGrid` with the specified dimensions from the provided data. The returned instance has to be freed with `pixel_grid_dealloc`.</summary>
[DllImport(__DllName, EntryPoint = "sp2_pixel_grid_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern PixelGrid* sp2_pixel_grid_load(nuint width, nuint height, byte* data, nuint data_length);
/// <summary>Clones a `PixelGrid`. The returned instance has to be freed with `pixel_grid_dealloc`.</summary>
[DllImport(__DllName, EntryPoint = "sp2_pixel_grid_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern PixelGrid* sp2_pixel_grid_clone(PixelGrid* @this);
/// <summary>Deallocates a `PixelGrid`. Note: do not call this if the grid has been consumed in another way, e.g. to create a command.</summary>
[DllImport(__DllName, EntryPoint = "sp2_pixel_grid_dealloc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void sp2_pixel_grid_dealloc(PixelGrid* @this);
/// <summary>Get the current value at the specified position</summary>
[DllImport(__DllName, EntryPoint = "sp2_pixel_grid_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.U1)]
public static extern bool sp2_pixel_grid_get(PixelGrid* @this, nuint x, nuint y);
/// <summary>Sets the current value at the specified position</summary>
[DllImport(__DllName, EntryPoint = "sp2_pixel_grid_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void sp2_pixel_grid_set(PixelGrid* @this, nuint x, nuint y, [MarshalAs(UnmanagedType.U1)] bool value);
/// <summary>Fills the whole `PixelGrid` with the specified value</summary>
[DllImport(__DllName, EntryPoint = "sp2_pixel_grid_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void sp2_pixel_grid_fill(PixelGrid* @this, [MarshalAs(UnmanagedType.U1)] bool value);
/// <summary>Gets the width in pixels of the `PixelGrid` instance.</summary>
[DllImport(__DllName, EntryPoint = "sp2_pixel_grid_width", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern nuint sp2_pixel_grid_width(PixelGrid* @this);
/// <summary>Gets the height in pixels of the `PixelGrid` instance.</summary>
[DllImport(__DllName, EntryPoint = "sp2_pixel_grid_height", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern nuint sp2_pixel_grid_height(PixelGrid* @this);
/// <summary>Gets an unsafe reference to the data of the `PixelGrid` instance. ## Safety The caller has to make sure to never access the returned memory after the `PixelGrid` instance has been consumed or manually deallocated. Reading and writing concurrently to either the original instance or the returned data will result in undefined behavior.</summary>
[DllImport(__DllName, EntryPoint = "sp2_pixel_grid_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern CByteSlice sp2_pixel_grid_unsafe_data_ref(PixelGrid* @this);
/// <summary>Turns a `Command` into a `Packet`. The command gets deallocated in the process.</summary>
[DllImport(__DllName, EntryPoint = "sp2_packet_from_command", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern Packet* sp2_packet_from_command(Command* command);
/// <summary>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</summary>
[DllImport(__DllName, EntryPoint = "sp2_packet_try_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern Packet* sp2_packet_try_load(byte* data, nuint length);
/// <summary>Deallocates a `Packet`. Note: do not call this if the instance has been consumed in another way, e.g. by sending it.</summary>
[DllImport(__DllName, EntryPoint = "sp2_packet_dealloc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void sp2_packet_dealloc(Packet* @this);
}
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct BitVec
{
}
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct ByteGrid
{
}
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct Connection
{
}
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct PixelGrid
{
}
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct CByteSlice
{
public byte* start;
public nuint length;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe partial struct Packet
{
}
public enum Command
{
Clear,
HardReset,
FadeOut,
CharBrightness,
Brightness,
BitmapLegacy,
BitmapLinear,
BitmapLinearAnd,
BitmapLinearOr,
BitmapLinearXor,
Cp437Data,
BitmapLinearWin,
}
public enum CompressionCode : ushort
{
Uncompressed = 0,
Zlib = 26490,
Bzip2 = 25210,
Lzma = 27770,
Zstd = 31347,
}
}