Compare commits
No commits in common. "389ced492ccbe1caffc52e445455f525d7bed0d8" and "b8a55d0433afef5848b865078345b4c4f47c649a" have entirely different histories.
389ced492c
...
b8a55d0433
21 changed files with 225 additions and 558 deletions
103
Cargo.lock
generated
103
Cargo.lock
generated
|
@ -8,15 +8,6 @@ version = "2.0.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.18"
|
||||
|
@ -182,29 +173,6 @@ dependencies = [
|
|||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_filter"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0"
|
||||
dependencies = [
|
||||
"log",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.11.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13c863f0904021b108aa8b2f55046443e6b1ebde8fd4a15c399893aae4fa069f"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"env_filter",
|
||||
"jiff",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.2"
|
||||
|
@ -289,30 +257,6 @@ version = "1.0.15"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||
|
||||
[[package]]
|
||||
name = "jiff"
|
||||
version = "0.2.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f02000660d30638906021176af16b17498bd0d12813dbfe7b276d8bc7f3c0806"
|
||||
dependencies = [
|
||||
"jiff-static",
|
||||
"log",
|
||||
"portable-atomic",
|
||||
"portable-atomic-util",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jiff-static"
|
||||
version = "0.2.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3c30758ddd7188629c6713fc45d1188af4f44c90582311d0c8d8c9907f60c48"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jobserver"
|
||||
version = "0.1.33"
|
||||
|
@ -368,21 +312,6 @@ version = "0.3.32"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e"
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic-util"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507"
|
||||
dependencies = [
|
||||
"portable-atomic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.95"
|
||||
|
@ -413,35 +342,6 @@ version = "0.7.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09"
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||
|
||||
[[package]]
|
||||
name = "rust-lzma"
|
||||
version = "0.6.0"
|
||||
|
@ -515,6 +415,8 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "servicepoint"
|
||||
version = "0.14.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f6bd5cfa49c73aeecb344680ffbf697abf73e0563a441b93b9723ae43867500f"
|
||||
dependencies = [
|
||||
"bitvec",
|
||||
"bzip2",
|
||||
|
@ -531,7 +433,6 @@ name = "servicepoint_binding_c"
|
|||
version = "0.14.1"
|
||||
dependencies = [
|
||||
"cbindgen",
|
||||
"env_logger",
|
||||
"servicepoint",
|
||||
]
|
||||
|
||||
|
|
|
@ -18,17 +18,13 @@ crate-type = ["staticlib", "cdylib", "rlib"]
|
|||
cbindgen = "0.28.0"
|
||||
|
||||
[dependencies.servicepoint]
|
||||
package = "servicepoint"
|
||||
version = "0.14.1"
|
||||
default-features = false
|
||||
|
||||
[dependencies.env_logger]
|
||||
version = "0.11.8"
|
||||
optional = true
|
||||
|
||||
[features]
|
||||
all_compressions = ["servicepoint/all_compressions"]
|
||||
default = ["all_compressions", "servicepoint/default", "env_logger"]
|
||||
env_logger = ["dep:env_logger"]
|
||||
default = ["all_compressions", "servicepoint/default"]
|
||||
|
||||
[lints.rust]
|
||||
missing-docs = "warn"
|
||||
|
|
|
@ -16,18 +16,16 @@ line_endings = "LF"
|
|||
|
||||
############################# Codegen Options ##################################
|
||||
|
||||
style = "both"
|
||||
style = "type"
|
||||
usize_is_size_t = true
|
||||
|
||||
# this is needed because otherwise the order in the C bindings is different on different machines
|
||||
sort_by = "Name"
|
||||
|
||||
include_guard = "SERVICEPOINT_BINDINGS_C"
|
||||
|
||||
[parse]
|
||||
parse_deps = true
|
||||
include = ["servicepoint", "std"]
|
||||
extra_bindings = ["servicepoint", "servicepoint_binding_c"]
|
||||
extra_bindings = ["servicepoint"]
|
||||
|
||||
[parse.expand]
|
||||
features = ["full"]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
CARGO ?= cargo
|
||||
STRIP ?= strip
|
||||
|
||||
FEATURES := "env_logger"
|
||||
FEATURES := ""
|
||||
|
||||
THIS_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||
REPO_ROOT := $(realpath $(THIS_DIR)/..)
|
||||
|
@ -10,7 +10,7 @@ export SERVICEPOINT_HEADER_OUT := $(REPO_ROOT)/include
|
|||
override CFG_MUSL := $(if $(CFG_MUSL),$(CFG_MUSL),$(if $(MUSL),$(MUSL),0))
|
||||
override CFG_PROFILE := $(if $(CFG_PROFILE),$(CFG_PROFILE),$(if $(PROFILE),$(PROFILE),release))
|
||||
|
||||
CCFLAGS += -Wall -Wextra -pedantic -fwhole-program -fPIE -pie
|
||||
CCFLAGS += -Wall -fwhole-program -fPIE -pie
|
||||
|
||||
STRIPFLAGS := -s --strip-unneeded -R .comment -R .gnu.version -R .note -R .note.gnu.build-id -R .note.ABI-tag
|
||||
|
||||
|
@ -99,7 +99,7 @@ clean-rust:
|
|||
|
||||
.PHONY: all clean sizes $(_run_programs) clean-c clean-rust
|
||||
|
||||
$(_unstripped_bins): out/%_unstripped: src/%.c $(SERVICEPOINT_HEADER_OUT)/servicepoint.h src/helpers.h $(_sp_artifacts)
|
||||
$(_unstripped_bins): out/%_unstripped: src/%.c $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(_sp_artifacts)
|
||||
mkdir -p out || true
|
||||
$(CC) $< \
|
||||
-I $(SERVICEPOINT_HEADER_OUT) \
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
#include "helpers.h"
|
||||
#include <stdio.h>
|
||||
#include "servicepoint.h"
|
||||
|
||||
|
||||
int main(void) {
|
||||
sock_init();
|
||||
printf("test\n");
|
||||
|
||||
sp_udp_send_header(sock, (Header) {.command_code = COMMAND_CODE_CLEAR});
|
||||
UdpSocket *connection = sp_udp_open_ipv4(172, 23, 42, 29, 2342);
|
||||
//UdpSocket *connection = sp_udp_open_ipv4(127, 0, 0, 1, 2342);
|
||||
if (connection == NULL)
|
||||
return 1;
|
||||
|
||||
sp_udp_send_header(connection, (Header) {.command_code = COMMAND_CODE_CLEAR});
|
||||
|
||||
CharGrid *grid = sp_char_grid_new(5, 2);
|
||||
if (grid == NULL)
|
||||
|
@ -23,7 +30,8 @@ int main(void) {
|
|||
Packet *packet = sp_char_grid_into_packet(grid, 0, 0);
|
||||
if (packet == NULL)
|
||||
return 1;
|
||||
sp_udp_send_packet(sock, packet);
|
||||
sp_udp_send_packet(connection, packet);
|
||||
|
||||
sp_udp_free(connection);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "servicepoint.h"
|
||||
#include "helpers.h"
|
||||
|
||||
static UdpSocket *connection = NULL;
|
||||
|
||||
void enable_all_pixels(void) {
|
||||
Bitmap *all_on = sp_bitmap_new_max_sized();
|
||||
|
@ -8,7 +9,7 @@ void enable_all_pixels(void) {
|
|||
BitmapCommand *bitmapCommand = sp_cmd_bitmap_from_bitmap(all_on);
|
||||
Packet *packet = sp_cmd_bitmap_try_into_packet(bitmapCommand);
|
||||
if (packet != NULL)
|
||||
sp_udp_send_packet(sock, packet);
|
||||
sp_udp_send_packet(connection, packet);
|
||||
}
|
||||
|
||||
void make_brightness_pattern(BrightnessGrid *grid) {
|
||||
|
@ -18,8 +19,16 @@ void make_brightness_pattern(BrightnessGrid *grid) {
|
|||
}
|
||||
}
|
||||
|
||||
void run_at_exit() {
|
||||
sp_udp_free(connection);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
sock_init();
|
||||
//UdpSocket *connection = sp_udp_open_ipv4(172, 23, 42, 29, 2342);
|
||||
connection = sp_udp_open_ipv4(127, 0, 0, 1, 2342);
|
||||
if (connection == NULL)
|
||||
return -1;
|
||||
atexit(run_at_exit);
|
||||
|
||||
enable_all_pixels();
|
||||
|
||||
|
@ -30,6 +39,6 @@ int main(void) {
|
|||
if (packet == NULL)
|
||||
return -2;
|
||||
|
||||
sp_udp_send_packet(sock, packet);
|
||||
sp_udp_send_packet(connection, packet);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <string.h>
|
||||
#include "servicepoint.h"
|
||||
|
||||
#define DEFAULT_LISTEN_IP "127.0.0.1"
|
||||
|
||||
void handle_error(const char *msg) {
|
||||
perror(msg);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
init_env_logger();
|
||||
|
||||
int udp_socket = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (udp_socket == -1)
|
||||
handle_error("socket could not be created\n");
|
||||
|
||||
char *listen_addr_arg;
|
||||
if (argc > 1) {
|
||||
listen_addr_arg = argv[1];
|
||||
} else {
|
||||
listen_addr_arg = DEFAULT_LISTEN_IP;
|
||||
}
|
||||
|
||||
struct in_addr addr;
|
||||
if (inet_aton(listen_addr_arg, &addr) == 0)
|
||||
handle_error("listen ip could not be parsed\n");
|
||||
|
||||
struct sockaddr_in sockaddrIn = {
|
||||
.sin_addr = addr,
|
||||
.sin_family = AF_INET,
|
||||
.sin_port = htons(2342),
|
||||
};
|
||||
memset(sockaddrIn.sin_zero, 0, sizeof(sockaddrIn.sin_zero));
|
||||
|
||||
if (bind(udp_socket, (struct sockaddr *) &sockaddrIn, sizeof(sockaddrIn)) == -1)
|
||||
handle_error("could not bind socket\n");
|
||||
|
||||
printf("socket ready to receive on %s\n", listen_addr_arg);
|
||||
|
||||
uint8_t buffer[10000];
|
||||
bool done = false;
|
||||
while (!done) {
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
|
||||
ssize_t num_bytes = recv(udp_socket, (void *) buffer, sizeof(buffer), 0);
|
||||
if (num_bytes == -1)
|
||||
handle_error("could not read from client");
|
||||
|
||||
Packet *packet = sp_packet_try_load((ByteSlice) {
|
||||
.start = buffer,
|
||||
.length = num_bytes,
|
||||
});
|
||||
if (packet == NULL) {
|
||||
printf("received invalid packet\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
struct Header *header = sp_packet_get_header(packet);
|
||||
ByteSlice payload = sp_packet_get_payload(packet);
|
||||
printf("Received packet: cc=%d, a=%d, b=%d, c=%d, d=%d, payload=%p (len %zu)\n",
|
||||
header->command_code, header->a, header->b, header->c, header->d,
|
||||
payload.start, payload.length);
|
||||
|
||||
done = header->command_code == COMMAND_CODE_HARD_RESET;
|
||||
sp_packet_free(packet);
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
#pragma once
|
||||
#ifndef SERVICEPOINT_BINDING_C_MSLEEP_H
|
||||
#define SERVICEPOINT_BINDING_C_MSLEEP_H
|
||||
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include "servicepoint.h"
|
||||
|
||||
static UdpSocket *sock = NULL;
|
||||
|
||||
void sock_free() {
|
||||
sp_udp_free(sock);
|
||||
}
|
||||
|
||||
void sock_init() {
|
||||
//sock = sp_udp_open_ipv4(127, 0, 0, 1, 2342);
|
||||
sock = sp_udp_open_ipv4(172, 23, 42, 29, 2342);
|
||||
if (sock == NULL)
|
||||
exit(-1);
|
||||
atexit(sock_free);
|
||||
}
|
||||
|
||||
/// TODO: all of this for sleeping n ms? There should be a better way!
|
||||
int msleep(long msec) {
|
||||
int res;
|
||||
|
||||
if (msec < 0) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct timespec ts = {
|
||||
.tv_sec = msec / 1000,
|
||||
.tv_nsec = (msec % 1000) * 1000000,
|
||||
};
|
||||
|
||||
do {
|
||||
res = nanosleep(&ts, &ts);
|
||||
} while (res && errno == EINTR);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif //SERVICEPOINT_BINDING_C_MSLEEP_H
|
|
@ -1,34 +0,0 @@
|
|||
#include "servicepoint.h"
|
||||
#include "helpers.h"
|
||||
|
||||
int main(void) {
|
||||
sock_init();
|
||||
|
||||
int result = 0;
|
||||
Bitmap *bitmap = sp_bitmap_new_max_sized();
|
||||
for (size_t x = 0; x < sp_bitmap_width(bitmap); x++) {
|
||||
sp_bitmap_fill(bitmap, false);
|
||||
|
||||
for (size_t y = 0; y < sp_bitmap_height(bitmap); y++) {
|
||||
sp_bitmap_set(bitmap, (y + x) % PIXEL_WIDTH, y, true);
|
||||
}
|
||||
|
||||
BitmapCommand *command = sp_cmd_bitmap_from_bitmap(sp_bitmap_clone(bitmap));
|
||||
Packet *packet = sp_cmd_bitmap_try_into_packet(command);
|
||||
if (packet == NULL) {
|
||||
result = -2;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!sp_udp_send_packet(sock, packet)) {
|
||||
result = -3;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
msleep(SP_FRAME_PACING_MS);
|
||||
}
|
||||
|
||||
exit:
|
||||
sp_bitmap_free(bitmap);
|
||||
return result;
|
||||
}
|
|
@ -1,9 +1,10 @@
|
|||
#include <stdio.h>
|
||||
#include "servicepoint.h"
|
||||
#include "helpers.h"
|
||||
|
||||
int main(void) {
|
||||
sock_init();
|
||||
UdpSocket *connection = sp_udp_open_ipv4(127, 0, 0, 1, 2342);
|
||||
if (connection == NULL)
|
||||
return 1;
|
||||
|
||||
Bitmap *pixels = sp_bitmap_new(PIXEL_WIDTH, PIXEL_HEIGHT);
|
||||
if (pixels == NULL)
|
||||
|
@ -18,6 +19,8 @@ int main(void) {
|
|||
Header *header = sp_packet_get_header(packet);
|
||||
printf("[%d, %d, %d, %d, %d]\n", header->command_code, header->a, header->b, header->c, header->d);
|
||||
|
||||
sp_udp_send_packet(sock, packet);
|
||||
sp_udp_send_packet(connection, packet);
|
||||
|
||||
sp_udp_free(connection);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
#include "servicepoint.h"
|
||||
#include "helpers.h"
|
||||
|
||||
int main() {
|
||||
sock_init();
|
||||
|
||||
Bitmap *enabled_pixels = sp_bitmap_new_max_sized();
|
||||
sp_bitmap_fill(enabled_pixels, true);
|
||||
|
||||
int result = 0;
|
||||
for (int x = 0; x < PIXEL_WIDTH; x++) {
|
||||
for (int y = 0; y < PIXEL_HEIGHT; y++) {
|
||||
sp_bitmap_set(enabled_pixels, x, y, false);
|
||||
}
|
||||
|
||||
BitVec *bitvec = sp_bitmap_into_bitvec(sp_bitmap_clone(enabled_pixels));
|
||||
BitVecCommand *command = sp_cmd_bitvec_new(bitvec, 0, BINARY_OPERATION_AND, COMPRESSION_CODE_LZMA);
|
||||
Packet *packet = sp_cmd_bitvec_try_into_packet(command);
|
||||
if (packet == NULL) {
|
||||
result = -2;
|
||||
goto exit;
|
||||
}
|
||||
if (!sp_udp_send_packet(sock, packet)) {
|
||||
result = -3;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
msleep(SP_FRAME_PACING_MS);
|
||||
}
|
||||
|
||||
exit:
|
||||
sp_bitmap_free(enabled_pixels);
|
||||
return result;
|
||||
}
|
|
@ -1,6 +1,3 @@
|
|||
#ifndef SERVICEPOINT_BINDINGS_C
|
||||
#define SERVICEPOINT_BINDINGS_C
|
||||
|
||||
/* Generated with cbindgen:0.28.0 */
|
||||
|
||||
/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */
|
||||
|
@ -449,19 +446,12 @@ typedef struct ValueGrid_u8 ValueGrid_u8;
|
|||
* - 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.
|
||||
* - if `start` is NULL or `length` is 0, do not dereference `start`.
|
||||
*
|
||||
* # Examples
|
||||
*
|
||||
* ```c
|
||||
* ByteSlice empty = {.start: NULL, .length = 0};
|
||||
* ```
|
||||
*/
|
||||
typedef struct ByteSlice {
|
||||
typedef struct {
|
||||
/**
|
||||
* The start address of the memory.
|
||||
*/
|
||||
uint8_t *start;
|
||||
uint8_t */*notnull*/ start;
|
||||
/**
|
||||
* The amount of memory in bytes.
|
||||
*/
|
||||
|
@ -486,7 +476,7 @@ typedef struct ByteSlice {
|
|||
* }).unwrap()
|
||||
* ```
|
||||
*/
|
||||
typedef struct ValueGrid_Brightness BrightnessGrid;
|
||||
typedef ValueGrid_Brightness BrightnessGrid;
|
||||
|
||||
/**
|
||||
* A display brightness value, checked for correct value range
|
||||
|
@ -532,7 +522,7 @@ typedef uint8_t Brightness;
|
|||
* connection.send_command(command).unwrap()
|
||||
* ```
|
||||
*/
|
||||
typedef struct ValueGrid_char CharGrid;
|
||||
typedef ValueGrid_char CharGrid;
|
||||
|
||||
/**
|
||||
* Type alias for documenting the meaning of the u16 in enum values
|
||||
|
@ -544,23 +534,23 @@ typedef size_t Offset;
|
|||
*
|
||||
* The encoding is currently not enforced.
|
||||
*/
|
||||
typedef struct ValueGrid_u8 Cp437Grid;
|
||||
typedef ValueGrid_u8 Cp437Grid;
|
||||
|
||||
/**
|
||||
* Pointer to one of the available command structs.
|
||||
*/
|
||||
typedef union CommandUnion {
|
||||
typedef union {
|
||||
uint8_t *null;
|
||||
struct BitmapCommand */*notnull*/ bitmap;
|
||||
struct BitVecCommand */*notnull*/ bitvec;
|
||||
struct BrightnessGridCommand */*notnull*/ brightness_grid;
|
||||
struct CharGridCommand */*notnull*/ char_grid;
|
||||
struct Cp437GridCommand */*notnull*/ cp437_grid;
|
||||
struct GlobalBrightnessCommand */*notnull*/ global_brightness;
|
||||
struct ClearCommand */*notnull*/ clear;
|
||||
struct BitmapLegacyCommand */*notnull*/ bitmap_legacy;
|
||||
struct HardResetCommand */*notnull*/ hard_reset;
|
||||
struct FadeOutCommand */*notnull*/ fade_out;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -570,7 +560,7 @@ typedef union CommandUnion {
|
|||
*
|
||||
* Rust equivalent: [TypedCommand].
|
||||
*/
|
||||
typedef struct Command {
|
||||
typedef struct {
|
||||
/**
|
||||
* Specifies which kind of command struct is contained in `data`
|
||||
*/
|
||||
|
@ -578,7 +568,7 @@ typedef struct Command {
|
|||
/**
|
||||
* The pointer to the command struct
|
||||
*/
|
||||
union CommandUnion data;
|
||||
CommandUnion data;
|
||||
} Command;
|
||||
|
||||
/**
|
||||
|
@ -591,7 +581,7 @@ typedef struct Command {
|
|||
*
|
||||
* The contained values are in platform endian-ness and may need to be converted before sending.
|
||||
*/
|
||||
typedef struct Header {
|
||||
typedef struct {
|
||||
/**
|
||||
* The first two bytes specify which command this packet represents.
|
||||
*/
|
||||
|
@ -616,23 +606,14 @@ typedef struct Header {
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* Actual hardware limit is around 28-29ms/frame. Rounded up for less dropped packets.
|
||||
*/
|
||||
#define SP_FRAME_PACING_MS 30
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
void init_env_logger(void);
|
||||
|
||||
/**
|
||||
* Clones a [Bitmap].
|
||||
*/
|
||||
struct Bitmap */*notnull*/ sp_bitmap_clone(struct Bitmap */*notnull*/ bitmap);
|
||||
Bitmap */*notnull*/ sp_bitmap_clone(Bitmap */*notnull*/ bitmap);
|
||||
|
||||
/**
|
||||
* Sets the state of all pixels in the [Bitmap].
|
||||
|
@ -642,12 +623,12 @@ struct Bitmap */*notnull*/ sp_bitmap_clone(struct Bitmap */*notnull*/ bitmap);
|
|||
* - `bitmap`: instance to write to
|
||||
* - `value`: the value to set all pixels to
|
||||
*/
|
||||
void sp_bitmap_fill(struct Bitmap */*notnull*/ bitmap, bool value);
|
||||
void sp_bitmap_fill(Bitmap */*notnull*/ bitmap, bool value);
|
||||
|
||||
/**
|
||||
* Deallocates a [Bitmap].
|
||||
*/
|
||||
void sp_bitmap_free(struct Bitmap */*notnull*/ bitmap);
|
||||
void sp_bitmap_free(Bitmap */*notnull*/ bitmap);
|
||||
|
||||
/**
|
||||
* Tries to convert the BitVec to a Bitmap.
|
||||
|
@ -656,7 +637,7 @@ void sp_bitmap_free(struct Bitmap */*notnull*/ bitmap);
|
|||
*
|
||||
* Returns NULL in case of error.
|
||||
*/
|
||||
struct Bitmap *sp_bitmap_from_bitvec(size_t width, BitVec */*notnull*/ bitvec);
|
||||
Bitmap *sp_bitmap_from_bitvec(size_t width, BitVec */*notnull*/ bitvec);
|
||||
|
||||
/**
|
||||
* Gets the current value at the specified position in the [Bitmap].
|
||||
|
@ -670,7 +651,7 @@ struct Bitmap *sp_bitmap_from_bitvec(size_t width, BitVec */*notnull*/ bitvec);
|
|||
*
|
||||
* - when accessing `x` or `y` out of bounds
|
||||
*/
|
||||
bool sp_bitmap_get(struct Bitmap */*notnull*/ bitmap, size_t x, size_t y);
|
||||
bool sp_bitmap_get(Bitmap */*notnull*/ bitmap, size_t x, size_t y);
|
||||
|
||||
/**
|
||||
* Gets the height in pixels of the [Bitmap] instance.
|
||||
|
@ -679,12 +660,12 @@ bool sp_bitmap_get(struct Bitmap */*notnull*/ bitmap, size_t x, size_t y);
|
|||
*
|
||||
* - `bitmap`: instance to read from
|
||||
*/
|
||||
size_t sp_bitmap_height(struct Bitmap */*notnull*/ bitmap);
|
||||
size_t sp_bitmap_height(Bitmap */*notnull*/ bitmap);
|
||||
|
||||
/**
|
||||
* Consumes the Bitmap and returns the contained BitVec
|
||||
*/
|
||||
BitVec */*notnull*/ sp_bitmap_into_bitvec(struct Bitmap */*notnull*/ bitmap);
|
||||
BitVec */*notnull*/ sp_bitmap_into_bitvec(Bitmap */*notnull*/ bitmap);
|
||||
|
||||
/**
|
||||
* Creates a [BitmapCommand] and immediately turns that into a [Packet].
|
||||
|
@ -693,7 +674,7 @@ BitVec */*notnull*/ sp_bitmap_into_bitvec(struct Bitmap */*notnull*/ bitmap);
|
|||
*
|
||||
* Returns NULL in case of an error.
|
||||
*/
|
||||
struct Packet *sp_bitmap_into_packet(struct Bitmap */*notnull*/ bitmap,
|
||||
Packet *sp_bitmap_into_packet(Bitmap */*notnull*/ bitmap,
|
||||
size_t x,
|
||||
size_t y,
|
||||
CompressionCode compression);
|
||||
|
@ -708,9 +689,9 @@ struct Packet *sp_bitmap_into_packet(struct Bitmap */*notnull*/ bitmap,
|
|||
*
|
||||
* returns: [Bitmap] that contains a copy of the provided data, or NULL in case of an error.
|
||||
*/
|
||||
struct Bitmap *sp_bitmap_load(size_t width,
|
||||
Bitmap *sp_bitmap_load(size_t width,
|
||||
size_t height,
|
||||
struct ByteSlice data);
|
||||
ByteSlice data);
|
||||
|
||||
/**
|
||||
* Creates a new [Bitmap] with the specified dimensions.
|
||||
|
@ -737,14 +718,14 @@ struct Bitmap *sp_bitmap_load(size_t width,
|
|||
* sp_bitmap_free(grid);
|
||||
* ```
|
||||
*/
|
||||
struct Bitmap *sp_bitmap_new(size_t width, size_t height);
|
||||
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.
|
||||
*/
|
||||
struct Bitmap */*notnull*/ sp_bitmap_new_max_sized(void);
|
||||
Bitmap */*notnull*/ sp_bitmap_new_max_sized(void);
|
||||
|
||||
/**
|
||||
* Sets the value of the specified position in the [Bitmap].
|
||||
|
@ -759,17 +740,14 @@ struct Bitmap */*notnull*/ sp_bitmap_new_max_sized(void);
|
|||
*
|
||||
* - when accessing `x` or `y` out of bounds
|
||||
*/
|
||||
void sp_bitmap_set(struct Bitmap */*notnull*/ bitmap,
|
||||
size_t x,
|
||||
size_t y,
|
||||
bool value);
|
||||
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.
|
||||
*/
|
||||
struct ByteSlice sp_bitmap_unsafe_data_ref(struct Bitmap */*notnull*/ bitmap);
|
||||
ByteSlice sp_bitmap_unsafe_data_ref(Bitmap */*notnull*/ bitmap);
|
||||
|
||||
/**
|
||||
* Gets the width in pixels of the [Bitmap] instance.
|
||||
|
@ -788,7 +766,7 @@ struct ByteSlice sp_bitmap_unsafe_data_ref(struct Bitmap */*notnull*/ bitmap);
|
|||
*
|
||||
* - `bitmap` points to a valid [Bitmap]
|
||||
*/
|
||||
size_t sp_bitmap_width(struct Bitmap */*notnull*/ bitmap);
|
||||
size_t sp_bitmap_width(Bitmap */*notnull*/ bitmap);
|
||||
|
||||
/**
|
||||
* Clones a [DisplayBitVec].
|
||||
|
@ -833,7 +811,7 @@ bool sp_bitvec_get(BitVec */*notnull*/ bit_vec, size_t index);
|
|||
*
|
||||
* Returns NULL in case of an error.
|
||||
*/
|
||||
struct Packet *sp_bitvec_into_packet(BitVec */*notnull*/ bitvec,
|
||||
Packet *sp_bitvec_into_packet(BitVec */*notnull*/ bitvec,
|
||||
size_t offset,
|
||||
BinaryOperation operation,
|
||||
CompressionCode compression);
|
||||
|
@ -861,7 +839,7 @@ size_t sp_bitvec_len(BitVec */*notnull*/ bit_vec);
|
|||
*
|
||||
* returns: [DisplayBitVec] instance containing data.
|
||||
*/
|
||||
BitVec */*notnull*/ sp_bitvec_load(struct ByteSlice data);
|
||||
BitVec */*notnull*/ sp_bitvec_load(ByteSlice data);
|
||||
|
||||
/**
|
||||
* Creates a new [DisplayBitVec] instance.
|
||||
|
@ -902,7 +880,7 @@ void sp_bitvec_set(BitVec */*notnull*/ bit_vec, size_t index, bool value);
|
|||
*
|
||||
* - `bit_vec`: instance to write to
|
||||
*/
|
||||
struct ByteSlice sp_bitvec_unsafe_data_ref(BitVec */*notnull*/ bit_vec);
|
||||
ByteSlice sp_bitvec_unsafe_data_ref(BitVec */*notnull*/ bit_vec);
|
||||
|
||||
/**
|
||||
* Clones a [BrightnessGrid].
|
||||
|
@ -960,7 +938,7 @@ size_t sp_brightness_grid_height(BrightnessGrid */*notnull*/ brightness_grid);
|
|||
*
|
||||
* Returns NULL in case of an error.
|
||||
*/
|
||||
struct Packet *sp_brightness_grid_into_packet(BrightnessGrid */*notnull*/ grid,
|
||||
Packet *sp_brightness_grid_into_packet(BrightnessGrid */*notnull*/ grid,
|
||||
size_t x,
|
||||
size_t y);
|
||||
|
||||
|
@ -973,7 +951,7 @@ struct Packet *sp_brightness_grid_into_packet(BrightnessGrid */*notnull*/ grid,
|
|||
*/
|
||||
BrightnessGrid *sp_brightness_grid_load(size_t width,
|
||||
size_t height,
|
||||
struct ByteSlice data);
|
||||
ByteSlice data);
|
||||
|
||||
/**
|
||||
* Creates a new [BrightnessGrid] with the specified dimensions.
|
||||
|
@ -1027,7 +1005,7 @@ void sp_brightness_grid_set(BrightnessGrid */*notnull*/ brightness_grid,
|
|||
*
|
||||
* returns: slice of bytes underlying the `brightness_grid`.
|
||||
*/
|
||||
struct ByteSlice sp_brightness_grid_unsafe_data_ref(BrightnessGrid */*notnull*/ brightness_grid);
|
||||
ByteSlice sp_brightness_grid_unsafe_data_ref(BrightnessGrid */*notnull*/ brightness_grid);
|
||||
|
||||
/**
|
||||
* Gets the width of the [BrightnessGrid] instance.
|
||||
|
@ -1090,7 +1068,7 @@ size_t sp_char_grid_height(CharGrid */*notnull*/ char_grid);
|
|||
*
|
||||
* Returns NULL in case of an error.
|
||||
*/
|
||||
struct Packet *sp_char_grid_into_packet(CharGrid */*notnull*/ grid,
|
||||
Packet *sp_char_grid_into_packet(CharGrid */*notnull*/ grid,
|
||||
size_t x,
|
||||
size_t y);
|
||||
|
||||
|
@ -1099,7 +1077,7 @@ struct Packet *sp_char_grid_into_packet(CharGrid */*notnull*/ grid,
|
|||
*
|
||||
* returns: new CharGrid or NULL in case of an error
|
||||
*/
|
||||
CharGrid *sp_char_grid_load(size_t width, size_t height, struct ByteSlice data);
|
||||
CharGrid *sp_char_grid_load(size_t width, size_t height, ByteSlice data);
|
||||
|
||||
/**
|
||||
* Creates a new [CharGrid] with the specified dimensions.
|
||||
|
@ -1151,12 +1129,12 @@ size_t sp_char_grid_width(CharGrid */*notnull*/ char_grid);
|
|||
*
|
||||
* returns: a new [BitmapCommand] instance.
|
||||
*/
|
||||
struct BitmapCommand */*notnull*/ sp_cmd_bitmap_clone(struct BitmapCommand */*notnull*/ command);
|
||||
BitmapCommand */*notnull*/ sp_cmd_bitmap_clone(BitmapCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Deallocates a [BitmapCommand] instance.
|
||||
*/
|
||||
void sp_cmd_bitmap_free(struct BitmapCommand */*notnull*/ command);
|
||||
void sp_cmd_bitmap_free(BitmapCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Move the provided [Bitmap] into a new [BitmapCommand],
|
||||
|
@ -1164,7 +1142,7 @@ void sp_cmd_bitmap_free(struct BitmapCommand */*notnull*/ command);
|
|||
*
|
||||
* Rust equivalent: `BitmapCommand::from(bitmap)`
|
||||
*/
|
||||
struct BitmapCommand */*notnull*/ sp_cmd_bitmap_from_bitmap(struct Bitmap */*notnull*/ bitmap);
|
||||
BitmapCommand */*notnull*/ sp_cmd_bitmap_from_bitmap(Bitmap */*notnull*/ bitmap);
|
||||
|
||||
/**
|
||||
* Returns a pointer to the provided `BitmapCommand`.
|
||||
|
@ -1174,17 +1152,17 @@ struct BitmapCommand */*notnull*/ sp_cmd_bitmap_from_bitmap(struct Bitmap */*not
|
|||
* - 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.
|
||||
*/
|
||||
struct Bitmap */*notnull*/ sp_cmd_bitmap_get(struct BitmapCommand */*notnull*/ command);
|
||||
Bitmap */*notnull*/ sp_cmd_bitmap_get(BitmapCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Reads the compression kind of the [BitmapCommand].
|
||||
*/
|
||||
CompressionCode sp_cmd_bitmap_get_compression(struct BitmapCommand */*notnull*/ command);
|
||||
CompressionCode sp_cmd_bitmap_get_compression(BitmapCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Reads the origin field of the [BitmapCommand].
|
||||
*/
|
||||
void sp_cmd_bitmap_get_origin(struct BitmapCommand */*notnull*/ command,
|
||||
void sp_cmd_bitmap_get_origin(BitmapCommand */*notnull*/ command,
|
||||
size_t */*notnull*/ origin_x,
|
||||
size_t */*notnull*/ origin_y);
|
||||
|
||||
|
@ -1195,7 +1173,7 @@ void sp_cmd_bitmap_get_origin(struct BitmapCommand */*notnull*/ command,
|
|||
*
|
||||
* Returns: a new [BitmapCommand] instance.
|
||||
*/
|
||||
struct BitmapCommand */*notnull*/ sp_cmd_bitmap_new(struct Bitmap */*notnull*/ bitmap,
|
||||
BitmapCommand */*notnull*/ sp_cmd_bitmap_new(Bitmap */*notnull*/ bitmap,
|
||||
size_t origin_x,
|
||||
size_t origin_y,
|
||||
CompressionCode compression);
|
||||
|
@ -1203,19 +1181,19 @@ struct BitmapCommand */*notnull*/ sp_cmd_bitmap_new(struct Bitmap */*notnull*/ b
|
|||
/**
|
||||
* Moves the provided [Bitmap] to be contained in the [BitmapCommand].
|
||||
*/
|
||||
void sp_cmd_bitmap_set(struct BitmapCommand */*notnull*/ command,
|
||||
struct Bitmap */*notnull*/ bitmap);
|
||||
void sp_cmd_bitmap_set(BitmapCommand */*notnull*/ command,
|
||||
Bitmap */*notnull*/ bitmap);
|
||||
|
||||
/**
|
||||
* Overwrites the compression kind of the [BitmapCommand].
|
||||
*/
|
||||
void sp_cmd_bitmap_set_compression(struct BitmapCommand */*notnull*/ command,
|
||||
void sp_cmd_bitmap_set_compression(BitmapCommand */*notnull*/ command,
|
||||
CompressionCode compression);
|
||||
|
||||
/**
|
||||
* Overwrites the origin field of the [BitmapCommand].
|
||||
*/
|
||||
void sp_cmd_bitmap_set_origin(struct BitmapCommand */*notnull*/ command,
|
||||
void sp_cmd_bitmap_set_origin(BitmapCommand */*notnull*/ command,
|
||||
size_t origin_x,
|
||||
size_t origin_y);
|
||||
|
||||
|
@ -1224,39 +1202,39 @@ void sp_cmd_bitmap_set_origin(struct BitmapCommand */*notnull*/ command,
|
|||
*
|
||||
* Returns: NULL or a [Packet] containing the command.
|
||||
*/
|
||||
struct Packet *sp_cmd_bitmap_try_into_packet(struct BitmapCommand */*notnull*/ command);
|
||||
Packet *sp_cmd_bitmap_try_into_packet(BitmapCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Clones an [BitVecCommand] instance.
|
||||
*
|
||||
* returns: a new [BitVecCommand] instance.
|
||||
*/
|
||||
struct BitVecCommand */*notnull*/ sp_cmd_bitvec_clone(struct BitVecCommand */*notnull*/ command);
|
||||
BitVecCommand */*notnull*/ sp_cmd_bitvec_clone(BitVecCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Deallocates a [BitVecCommand].
|
||||
*/
|
||||
void sp_cmd_bitvec_free(struct BitVecCommand */*notnull*/ command);
|
||||
void sp_cmd_bitvec_free(BitVecCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Returns a pointer to the [BitVec] contained in the [BitVecCommand].
|
||||
*/
|
||||
BitVec *sp_cmd_bitvec_get(struct BitVecCommand */*notnull*/ command);
|
||||
BitVec *sp_cmd_bitvec_get(BitVecCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Reads the compression kind of the [BitVecCommand].
|
||||
*/
|
||||
CompressionCode sp_cmd_bitvec_get_compression(struct BitVecCommand */*notnull*/ command);
|
||||
CompressionCode sp_cmd_bitvec_get_compression(BitVecCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Reads the offset field of the [BitVecCommand].
|
||||
*/
|
||||
Offset sp_cmd_bitvec_get_offset(struct BitVecCommand */*notnull*/ command);
|
||||
Offset sp_cmd_bitvec_get_offset(BitVecCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Returns the [BinaryOperation] of the command.
|
||||
*/
|
||||
BinaryOperation sp_cmd_bitvec_get_operation(struct BitVecCommand */*notnull*/ command);
|
||||
BinaryOperation sp_cmd_bitvec_get_operation(BitVecCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Set pixel data starting at the pixel offset on screen.
|
||||
|
@ -1272,7 +1250,7 @@ BinaryOperation sp_cmd_bitvec_get_operation(struct BitVecCommand */*notnull*/ co
|
|||
*
|
||||
* The contained [`DisplayBitVec`] is always uncompressed.
|
||||
*/
|
||||
struct BitVecCommand */*notnull*/ sp_cmd_bitvec_new(BitVec */*notnull*/ bitvec,
|
||||
BitVecCommand */*notnull*/ sp_cmd_bitvec_new(BitVec */*notnull*/ bitvec,
|
||||
size_t offset,
|
||||
BinaryOperation operation,
|
||||
CompressionCode compression);
|
||||
|
@ -1280,25 +1258,25 @@ struct BitVecCommand */*notnull*/ sp_cmd_bitvec_new(BitVec */*notnull*/ bitvec,
|
|||
/**
|
||||
* Moves the provided [BitVec] to be contained in the [BitVecCommand].
|
||||
*/
|
||||
void sp_cmd_bitvec_set(struct BitVecCommand */*notnull*/ command,
|
||||
void sp_cmd_bitvec_set(BitVecCommand */*notnull*/ command,
|
||||
BitVec */*notnull*/ bitvec);
|
||||
|
||||
/**
|
||||
* Overwrites the compression kind of the [BitVecCommand].
|
||||
*/
|
||||
void sp_cmd_bitvec_set_compression(struct BitVecCommand */*notnull*/ command,
|
||||
void sp_cmd_bitvec_set_compression(BitVecCommand */*notnull*/ command,
|
||||
CompressionCode compression);
|
||||
|
||||
/**
|
||||
* Overwrites the offset field of the [BitVecCommand].
|
||||
*/
|
||||
void sp_cmd_bitvec_set_offset(struct BitVecCommand */*notnull*/ command,
|
||||
void sp_cmd_bitvec_set_offset(BitVecCommand */*notnull*/ command,
|
||||
Offset offset);
|
||||
|
||||
/**
|
||||
* Overwrites the [BinaryOperation] of the command.
|
||||
*/
|
||||
void sp_cmd_bitvec_set_operation(struct BitVecCommand */*notnull*/ command,
|
||||
void sp_cmd_bitvec_set_operation(BitVecCommand */*notnull*/ command,
|
||||
BinaryOperation operation);
|
||||
|
||||
/**
|
||||
|
@ -1306,32 +1284,32 @@ void sp_cmd_bitvec_set_operation(struct BitVecCommand */*notnull*/ command,
|
|||
*
|
||||
* Returns: NULL or a [Packet] containing the command.
|
||||
*/
|
||||
struct Packet *sp_cmd_bitvec_try_into_packet(struct BitVecCommand */*notnull*/ command);
|
||||
Packet *sp_cmd_bitvec_try_into_packet(BitVecCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Clones an [GlobalBrightnessCommand] instance.
|
||||
*
|
||||
* returns: a new [GlobalBrightnessCommand] instance.
|
||||
*/
|
||||
struct GlobalBrightnessCommand */*notnull*/ sp_cmd_brightness_global_clone(struct GlobalBrightnessCommand */*notnull*/ command);
|
||||
GlobalBrightnessCommand */*notnull*/ sp_cmd_brightness_global_clone(GlobalBrightnessCommand */*notnull*/ command);
|
||||
|
||||
void sp_cmd_brightness_global_free(struct BitmapCommand */*notnull*/ command);
|
||||
void sp_cmd_brightness_global_free(BitmapCommand */*notnull*/ command);
|
||||
|
||||
Brightness *sp_cmd_brightness_global_get(struct GlobalBrightnessCommand */*notnull*/ command);
|
||||
Brightness *sp_cmd_brightness_global_get(GlobalBrightnessCommand */*notnull*/ command);
|
||||
|
||||
struct Packet */*notnull*/ sp_cmd_brightness_global_into_packet(struct GlobalBrightnessCommand */*notnull*/ command);
|
||||
Packet */*notnull*/ sp_cmd_brightness_global_into_packet(GlobalBrightnessCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Set the brightness of all tiles to the same value.
|
||||
*
|
||||
* Returns: a new [GlobalBrightnessCommand] instance.
|
||||
*/
|
||||
struct GlobalBrightnessCommand */*notnull*/ sp_cmd_brightness_global_new(Brightness brightness);
|
||||
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(struct GlobalBrightnessCommand */*notnull*/ command,
|
||||
void sp_cmd_brightness_global_set(GlobalBrightnessCommand */*notnull*/ command,
|
||||
Brightness brightness);
|
||||
|
||||
/**
|
||||
|
@ -1339,28 +1317,28 @@ void sp_cmd_brightness_global_set(struct GlobalBrightnessCommand */*notnull*/ co
|
|||
*
|
||||
* returns: a new [BrightnessGridCommand] instance.
|
||||
*/
|
||||
struct BrightnessGridCommand */*notnull*/ sp_cmd_brightness_grid_clone(struct BrightnessGridCommand */*notnull*/ command);
|
||||
BrightnessGridCommand */*notnull*/ sp_cmd_brightness_grid_clone(BrightnessGridCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Deallocates a [BitmapCommand].
|
||||
*/
|
||||
void sp_cmd_brightness_grid_free(struct BitmapCommand */*notnull*/ command);
|
||||
void sp_cmd_brightness_grid_free(BitmapCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Moves the provided [BrightnessGrid] into a new [BrightnessGridCommand],
|
||||
* leaving other fields as their default values.
|
||||
*/
|
||||
struct BrightnessGridCommand */*notnull*/ sp_cmd_brightness_grid_from_grid(BrightnessGrid */*notnull*/ grid);
|
||||
BrightnessGridCommand */*notnull*/ sp_cmd_brightness_grid_from_grid(BrightnessGrid */*notnull*/ grid);
|
||||
|
||||
/**
|
||||
* Returns a pointer to the [BrightnessGrid] contained in the [BrightnessGridCommand].
|
||||
*/
|
||||
BrightnessGrid *sp_cmd_brightness_grid_get(struct BrightnessGridCommand */*notnull*/ command);
|
||||
BrightnessGrid *sp_cmd_brightness_grid_get(BrightnessGridCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Overwrites the origin field of the [BrightnessGridCommand].
|
||||
*/
|
||||
void sp_cmd_brightness_grid_get_origin(struct BrightnessGridCommand */*notnull*/ command,
|
||||
void sp_cmd_brightness_grid_get_origin(BrightnessGridCommand */*notnull*/ command,
|
||||
size_t */*notnull*/ origin_x,
|
||||
size_t */*notnull*/ origin_y);
|
||||
|
||||
|
@ -1369,7 +1347,7 @@ void sp_cmd_brightness_grid_get_origin(struct BrightnessGridCommand */*notnull*/
|
|||
*
|
||||
* Returns: NULL or a [Packet] containing the command.
|
||||
*/
|
||||
struct Packet *sp_cmd_brightness_grid_into_packet(struct BrightnessGridCommand */*notnull*/ command);
|
||||
Packet *sp_cmd_brightness_grid_into_packet(BrightnessGridCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Set the brightness of individual tiles in a rectangular area of the display.
|
||||
|
@ -1378,20 +1356,20 @@ struct Packet *sp_cmd_brightness_grid_into_packet(struct BrightnessGridCommand *
|
|||
*
|
||||
* Returns: a new [BrightnessGridCommand] instance.
|
||||
*/
|
||||
struct BrightnessGridCommand */*notnull*/ sp_cmd_brightness_grid_new(BrightnessGrid */*notnull*/ grid,
|
||||
BrightnessGridCommand */*notnull*/ sp_cmd_brightness_grid_new(BrightnessGrid */*notnull*/ grid,
|
||||
size_t origin_x,
|
||||
size_t origin_y);
|
||||
|
||||
/**
|
||||
* Moves the provided [BrightnessGrid] to be contained in the [BrightnessGridCommand].
|
||||
*/
|
||||
void sp_cmd_brightness_grid_set(struct BrightnessGridCommand */*notnull*/ command,
|
||||
void sp_cmd_brightness_grid_set(BrightnessGridCommand */*notnull*/ command,
|
||||
BrightnessGrid */*notnull*/ grid);
|
||||
|
||||
/**
|
||||
* Reads the origin field of the [BrightnessGridCommand].
|
||||
*/
|
||||
void sp_cmd_brightness_grid_set_origin(struct BrightnessGridCommand */*notnull*/ command,
|
||||
void sp_cmd_brightness_grid_set_origin(BrightnessGridCommand */*notnull*/ command,
|
||||
size_t origin_x,
|
||||
size_t origin_y);
|
||||
|
||||
|
@ -1400,28 +1378,28 @@ void sp_cmd_brightness_grid_set_origin(struct BrightnessGridCommand */*notnull*/
|
|||
*
|
||||
* returns: a new [CharGridCommand] instance.
|
||||
*/
|
||||
struct CharGridCommand */*notnull*/ sp_cmd_char_grid_clone(struct CharGridCommand */*notnull*/ command);
|
||||
CharGridCommand */*notnull*/ sp_cmd_char_grid_clone(CharGridCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Deallocates a [BitmapCommand].
|
||||
*/
|
||||
void sp_cmd_char_grid_free(struct BitmapCommand */*notnull*/ command);
|
||||
void sp_cmd_char_grid_free(BitmapCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Moves the provided [CharGrid] into a new [CharGridCommand],
|
||||
* leaving other fields as their default values.
|
||||
*/
|
||||
struct CharGridCommand */*notnull*/ sp_cmd_char_grid_from_grid(CharGrid */*notnull*/ grid);
|
||||
CharGridCommand */*notnull*/ sp_cmd_char_grid_from_grid(CharGrid */*notnull*/ grid);
|
||||
|
||||
/**
|
||||
* Returns a pointer to the [CharGrid] contained in the [CharGridCommand].
|
||||
*/
|
||||
CharGrid *sp_cmd_char_grid_get(struct CharGridCommand */*notnull*/ command);
|
||||
CharGrid *sp_cmd_char_grid_get(CharGridCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Reads the origin field of the [CharGridCommand].
|
||||
*/
|
||||
void sp_cmd_char_grid_get_origin(struct CharGridCommand */*notnull*/ command,
|
||||
void sp_cmd_char_grid_get_origin(CharGridCommand */*notnull*/ command,
|
||||
size_t */*notnull*/ origin_x,
|
||||
size_t */*notnull*/ origin_y);
|
||||
|
||||
|
@ -1432,20 +1410,20 @@ void sp_cmd_char_grid_get_origin(struct CharGridCommand */*notnull*/ command,
|
|||
*
|
||||
* Returns: a new [CharGridCommand] instance.
|
||||
*/
|
||||
struct CharGridCommand */*notnull*/ sp_cmd_char_grid_new(CharGrid */*notnull*/ grid,
|
||||
CharGridCommand */*notnull*/ sp_cmd_char_grid_new(CharGrid */*notnull*/ grid,
|
||||
size_t origin_x,
|
||||
size_t origin_y);
|
||||
|
||||
/**
|
||||
* Moves the provided [CharGrid] to be contained in the [CharGridCommand].
|
||||
*/
|
||||
void sp_cmd_char_grid_set(struct CharGridCommand */*notnull*/ command,
|
||||
void sp_cmd_char_grid_set(CharGridCommand */*notnull*/ command,
|
||||
CharGrid */*notnull*/ grid);
|
||||
|
||||
/**
|
||||
* Overwrites the origin field of the [CharGridCommand].
|
||||
*/
|
||||
void sp_cmd_char_grid_set_origin(struct CharGridCommand */*notnull*/ command,
|
||||
void sp_cmd_char_grid_set_origin(CharGridCommand */*notnull*/ command,
|
||||
size_t origin_x,
|
||||
size_t origin_y);
|
||||
|
||||
|
@ -1454,12 +1432,12 @@ void sp_cmd_char_grid_set_origin(struct CharGridCommand */*notnull*/ command,
|
|||
*
|
||||
* Returns: NULL or a [Packet] containing the command.
|
||||
*/
|
||||
struct Packet *sp_cmd_char_grid_try_into_packet(struct CharGridCommand */*notnull*/ command);
|
||||
Packet *sp_cmd_char_grid_try_into_packet(CharGridCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Deallocates a [ClearCommand].
|
||||
*/
|
||||
void sp_cmd_clear_free(struct ClearCommand */*notnull*/ command);
|
||||
void sp_cmd_clear_free(ClearCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Set all pixels to the off state.
|
||||
|
@ -1468,25 +1446,25 @@ void sp_cmd_clear_free(struct ClearCommand */*notnull*/ command);
|
|||
*
|
||||
* Returns: a new [ClearCommand] instance.
|
||||
*/
|
||||
struct ClearCommand */*notnull*/ sp_cmd_clear_new(void);
|
||||
ClearCommand */*notnull*/ sp_cmd_clear_new(void);
|
||||
|
||||
/**
|
||||
* Clones an [Cp437GridCommand] instance.
|
||||
*
|
||||
* returns: a new [Cp437GridCommand] instance.
|
||||
*/
|
||||
struct Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_clone(struct Cp437GridCommand */*notnull*/ command);
|
||||
Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_clone(Cp437GridCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Deallocates a [Cp437GridCommand].
|
||||
*/
|
||||
void sp_cmd_cp437_grid_free(struct BitmapCommand */*notnull*/ command);
|
||||
void sp_cmd_cp437_grid_free(BitmapCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Moves the provided [Cp437Grid] into a new [Cp437GridCommand],
|
||||
* leaving other fields as their default values.
|
||||
*/
|
||||
struct Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_from_grid(Cp437Grid */*notnull*/ grid);
|
||||
Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_from_grid(Cp437Grid */*notnull*/ grid);
|
||||
|
||||
/**
|
||||
* Show text on the screen.
|
||||
|
@ -1496,14 +1474,14 @@ struct Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_from_grid(Cp437Grid */*no
|
|||
*
|
||||
* [CP-437]: https://en.wikipedia.org/wiki/Code_page_437
|
||||
*/
|
||||
Cp437Grid *sp_cmd_cp437_grid_get(struct Cp437GridCommand */*notnull*/ command);
|
||||
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(struct Cp437GridCommand */*notnull*/ command,
|
||||
void sp_cmd_cp437_grid_get_origin(Cp437GridCommand */*notnull*/ command,
|
||||
size_t */*notnull*/ origin_x,
|
||||
size_t */*notnull*/ origin_y);
|
||||
|
||||
|
@ -1514,7 +1492,7 @@ void sp_cmd_cp437_grid_get_origin(struct Cp437GridCommand */*notnull*/ command,
|
|||
*
|
||||
* The origin is relative to the top-left of the display.
|
||||
*/
|
||||
struct Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_new(Cp437Grid */*notnull*/ grid,
|
||||
Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_new(Cp437Grid */*notnull*/ grid,
|
||||
size_t origin_x,
|
||||
size_t origin_y);
|
||||
|
||||
|
@ -1523,7 +1501,7 @@ struct Cp437GridCommand */*notnull*/ sp_cmd_cp437_grid_new(Cp437Grid */*notnull*
|
|||
*
|
||||
* This drops the previously contained [Cp437Grid].
|
||||
*/
|
||||
void sp_cmd_cp437_grid_set(struct Cp437GridCommand */*notnull*/ command,
|
||||
void sp_cmd_cp437_grid_set(Cp437GridCommand */*notnull*/ command,
|
||||
Cp437Grid */*notnull*/ grid);
|
||||
|
||||
/**
|
||||
|
@ -1531,7 +1509,7 @@ void sp_cmd_cp437_grid_set(struct Cp437GridCommand */*notnull*/ command,
|
|||
*
|
||||
* Rust equivalent: `cp437_command.origin = Origin::new(origin_x, origin_y)`
|
||||
*/
|
||||
void sp_cmd_cp437_grid_set_origin(struct Cp437GridCommand */*notnull*/ command,
|
||||
void sp_cmd_cp437_grid_set_origin(Cp437GridCommand */*notnull*/ command,
|
||||
size_t origin_x,
|
||||
size_t origin_y);
|
||||
|
||||
|
@ -1540,26 +1518,26 @@ void sp_cmd_cp437_grid_set_origin(struct Cp437GridCommand */*notnull*/ command,
|
|||
*
|
||||
* Returns: NULL or a [Packet] containing the command.
|
||||
*/
|
||||
struct Packet *sp_cmd_cp437_grid_try_into_packet(struct Cp437GridCommand */*notnull*/ command);
|
||||
Packet *sp_cmd_cp437_grid_try_into_packet(Cp437GridCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Deallocates a [FadeOutCommand].
|
||||
*/
|
||||
void sp_cmd_fade_out_free(struct ClearCommand */*notnull*/ command);
|
||||
void sp_cmd_fade_out_free(ClearCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* A yet-to-be-tested command.
|
||||
*
|
||||
* Returns: a new [FadeOutCommand] instance.
|
||||
*/
|
||||
struct FadeOutCommand */*notnull*/ sp_cmd_fade_out_new(void);
|
||||
FadeOutCommand */*notnull*/ sp_cmd_fade_out_new(void);
|
||||
|
||||
/**
|
||||
* Clones an [SPCommand] instance.
|
||||
*
|
||||
* returns: a new [SPCommand] instance.
|
||||
*/
|
||||
struct Command sp_cmd_generic_clone(struct Command command);
|
||||
Command sp_cmd_generic_clone(Command command);
|
||||
|
||||
/**
|
||||
* Deallocates an [SPCommand].
|
||||
|
@ -1571,7 +1549,7 @@ struct Command sp_cmd_generic_clone(struct Command command);
|
|||
* sp_command_free(c);
|
||||
* ```
|
||||
*/
|
||||
void sp_cmd_generic_free(struct Command command);
|
||||
void sp_cmd_generic_free(Command command);
|
||||
|
||||
/**
|
||||
* Tries to turn a [SPCommand] into a [Packet].
|
||||
|
@ -1579,7 +1557,7 @@ void sp_cmd_generic_free(struct Command command);
|
|||
*
|
||||
* Returns tag [CommandTag::Invalid] in case of an error.
|
||||
*/
|
||||
struct Packet *sp_cmd_generic_into_packet(struct Command command);
|
||||
Packet *sp_cmd_generic_into_packet(Command command);
|
||||
|
||||
/**
|
||||
* Tries to turn a [Packet] into a [SPCommand].
|
||||
|
@ -1588,12 +1566,12 @@ struct Packet *sp_cmd_generic_into_packet(struct Command command);
|
|||
*
|
||||
* Returns: pointer to new [SPCommand] instance or NULL if parsing failed.
|
||||
*/
|
||||
struct Command *sp_cmd_generic_try_from_packet(struct Packet */*notnull*/ packet);
|
||||
Command *sp_cmd_generic_try_from_packet(Packet */*notnull*/ packet);
|
||||
|
||||
/**
|
||||
* Deallocates a [HardResetCommand].
|
||||
*/
|
||||
void sp_cmd_hard_reset_free(struct ClearCommand */*notnull*/ command);
|
||||
void sp_cmd_hard_reset_free(ClearCommand */*notnull*/ command);
|
||||
|
||||
/**
|
||||
* Kills the udp daemon on the display, which usually results in a restart.
|
||||
|
@ -1602,7 +1580,7 @@ void sp_cmd_hard_reset_free(struct ClearCommand */*notnull*/ command);
|
|||
*
|
||||
* Returns: a new [HardResetCommand] instance.
|
||||
*/
|
||||
struct HardResetCommand */*notnull*/ sp_cmd_hard_reset_new(void);
|
||||
HardResetCommand */*notnull*/ sp_cmd_hard_reset_new(void);
|
||||
|
||||
/**
|
||||
* Clones a [Cp437Grid].
|
||||
|
@ -1656,16 +1634,14 @@ size_t sp_cp437_grid_height(Cp437Grid */*notnull*/ cp437_grid);
|
|||
*
|
||||
* Returns NULL in case of an error.
|
||||
*/
|
||||
struct Packet *sp_cp437_grid_into_packet(Cp437Grid */*notnull*/ grid,
|
||||
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,
|
||||
struct ByteSlice data);
|
||||
Cp437Grid *sp_cp437_grid_load(size_t width, size_t height, ByteSlice data);
|
||||
|
||||
/**
|
||||
* Creates a new [Cp437Grid] with the specified dimensions.
|
||||
|
@ -1699,7 +1675,7 @@ void sp_cp437_grid_set(Cp437Grid */*notnull*/ cp437_grid,
|
|||
*
|
||||
* The returned memory is valid for the lifetime of the grid.
|
||||
*/
|
||||
struct ByteSlice sp_cp437_grid_unsafe_data_ref(Cp437Grid */*notnull*/ cp437_grid);
|
||||
ByteSlice sp_cp437_grid_unsafe_data_ref(Cp437Grid */*notnull*/ cp437_grid);
|
||||
|
||||
/**
|
||||
* Gets the width of the [Cp437Grid] instance.
|
||||
|
@ -1715,36 +1691,34 @@ size_t sp_cp437_grid_width(Cp437Grid */*notnull*/ cp437_grid);
|
|||
*
|
||||
* returns: a new [Packet] instance.
|
||||
*/
|
||||
struct Packet */*notnull*/ sp_packet_clone(struct Packet */*notnull*/ packet);
|
||||
Packet */*notnull*/ sp_packet_clone(Packet */*notnull*/ packet);
|
||||
|
||||
/**
|
||||
* Deallocates a [Packet].
|
||||
*/
|
||||
void sp_packet_free(struct Packet */*notnull*/ packet);
|
||||
void sp_packet_free(Packet */*notnull*/ packet);
|
||||
|
||||
/**
|
||||
* Creates a raw [Packet] from parts.
|
||||
*
|
||||
* returns: new instance. Will never return null.
|
||||
*/
|
||||
struct Packet */*notnull*/ sp_packet_from_parts(struct Header header,
|
||||
struct ByteSlice payload);
|
||||
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.
|
||||
*/
|
||||
struct Header */*notnull*/ sp_packet_get_header(struct Packet */*notnull*/ packet);
|
||||
Header */*notnull*/ sp_packet_get_header(Packet */*notnull*/ packet);
|
||||
|
||||
/**
|
||||
* Returns a pointer to the current payload of the provided packet.
|
||||
*
|
||||
* Returns an [ByteSlice::INVALID] instance in case the packet does not have any payload.
|
||||
*
|
||||
* The returned memory can be changed and will be valid until a new payload is set.
|
||||
*/
|
||||
struct ByteSlice sp_packet_get_payload(struct Packet */*notnull*/ packet);
|
||||
ByteSlice sp_packet_get_payload(Packet */*notnull*/ packet);
|
||||
|
||||
/**
|
||||
* Serialize the packet into the provided buffer.
|
||||
|
@ -1753,23 +1727,21 @@ struct ByteSlice sp_packet_get_payload(struct Packet */*notnull*/ packet);
|
|||
*
|
||||
* - if the buffer is not big enough to hold header+payload.
|
||||
*/
|
||||
void sp_packet_serialize_to(struct Packet */*notnull*/ packet,
|
||||
struct ByteSlice buffer);
|
||||
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(struct Packet */*notnull*/ packet,
|
||||
struct ByteSlice data);
|
||||
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
|
||||
*/
|
||||
struct Packet *sp_packet_try_load(struct ByteSlice data);
|
||||
Packet *sp_packet_try_load(ByteSlice data);
|
||||
|
||||
/**
|
||||
* Converts u16 into [CommandCode].
|
||||
|
@ -1782,7 +1754,7 @@ bool sp_u16_to_command_code(uint16_t code,
|
|||
/**
|
||||
* Closes and deallocates a [UdpSocket].
|
||||
*/
|
||||
void sp_udp_free(struct UdpSocket */*notnull*/ connection);
|
||||
void sp_udp_free(UdpSocket */*notnull*/ connection);
|
||||
|
||||
/**
|
||||
* Creates a new instance of [UdpSocket].
|
||||
|
@ -1797,7 +1769,7 @@ void sp_udp_free(struct UdpSocket */*notnull*/ connection);
|
|||
* sp_udp_send_command(connection, sp_command_clear());
|
||||
* ```
|
||||
*/
|
||||
struct UdpSocket *sp_udp_open(char */*notnull*/ host);
|
||||
UdpSocket *sp_udp_open(char */*notnull*/ host);
|
||||
|
||||
/**
|
||||
* Creates a new instance of [UdpSocket].
|
||||
|
@ -1812,7 +1784,7 @@ struct UdpSocket *sp_udp_open(char */*notnull*/ host);
|
|||
* sp_udp_send_command(connection, sp_command_clear());
|
||||
* ```
|
||||
*/
|
||||
struct UdpSocket *sp_udp_open_ipv4(uint8_t ip1,
|
||||
UdpSocket *sp_udp_open_ipv4(uint8_t ip1,
|
||||
uint8_t ip2,
|
||||
uint8_t ip3,
|
||||
uint8_t ip4,
|
||||
|
@ -1831,8 +1803,7 @@ struct UdpSocket *sp_udp_open_ipv4(uint8_t ip1,
|
|||
* sp_udp_send_command(connection, sp_command_brightness(5));
|
||||
* ```
|
||||
*/
|
||||
bool sp_udp_send_command(struct UdpSocket */*notnull*/ connection,
|
||||
struct Command command);
|
||||
bool sp_udp_send_command(UdpSocket */*notnull*/ connection, Command command);
|
||||
|
||||
/**
|
||||
* Sends a [Header] to the display using the [UdpSocket].
|
||||
|
@ -1845,8 +1816,7 @@ bool sp_udp_send_command(struct UdpSocket */*notnull*/ connection,
|
|||
* sp_udp_send_header(connection, sp_command_brightness(5));
|
||||
* ```
|
||||
*/
|
||||
bool sp_udp_send_header(struct UdpSocket */*notnull*/ udp_connection,
|
||||
struct Header header);
|
||||
bool sp_udp_send_header(UdpSocket */*notnull*/ udp_connection, Header header);
|
||||
|
||||
/**
|
||||
* Sends a [Packet] to the display using the [UdpSocket].
|
||||
|
@ -1855,11 +1825,9 @@ bool sp_udp_send_header(struct UdpSocket */*notnull*/ udp_connection,
|
|||
*
|
||||
* returns: true in case of success
|
||||
*/
|
||||
bool sp_udp_send_packet(struct UdpSocket */*notnull*/ connection,
|
||||
struct Packet */*notnull*/ packet);
|
||||
bool sp_udp_send_packet(UdpSocket */*notnull*/ connection,
|
||||
Packet */*notnull*/ packet);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif /* SERVICEPOINT_BINDINGS_C */
|
||||
|
|
|
@ -65,7 +65,7 @@ pub unsafe extern "C" fn sp_cmd_bitvec_free(command: NonNull<BitVecCommand>) {
|
|||
pub unsafe extern "C" fn sp_cmd_bitvec_get(
|
||||
mut command: NonNull<BitVecCommand>,
|
||||
) -> *mut DisplayBitVec {
|
||||
unsafe { &mut command.as_mut().bitvec }
|
||||
&mut unsafe { command.as_mut() }.bitvec
|
||||
}
|
||||
|
||||
/// Moves the provided [BitVec] to be contained in the [BitVecCommand].
|
||||
|
@ -103,7 +103,7 @@ pub unsafe extern "C" fn sp_cmd_bitvec_set_offset(
|
|||
pub unsafe extern "C" fn sp_cmd_bitvec_get_operation(
|
||||
command: NonNull<BitVecCommand>,
|
||||
) -> BinaryOperation {
|
||||
unsafe { command.as_ref().operation }
|
||||
unsafe { command.as_ref().operation.clone() } // TODO remove clone
|
||||
}
|
||||
|
||||
/// Overwrites the [BinaryOperation] of the command.
|
||||
|
|
|
@ -76,7 +76,7 @@ pub unsafe extern "C" fn sp_cmd_brightness_grid_set(
|
|||
pub unsafe extern "C" fn sp_cmd_brightness_grid_get(
|
||||
mut command: NonNull<BrightnessGridCommand>,
|
||||
) -> *mut BrightnessGrid {
|
||||
unsafe { &mut command.as_mut().grid }
|
||||
&mut unsafe { command.as_mut() }.grid
|
||||
}
|
||||
|
||||
/// Overwrites the origin field of the [BrightnessGridCommand].
|
||||
|
|
|
@ -74,7 +74,7 @@ pub unsafe extern "C" fn sp_cmd_char_grid_set(
|
|||
pub unsafe extern "C" fn sp_cmd_char_grid_get(
|
||||
mut command: NonNull<CharGridCommand>,
|
||||
) -> *mut CharGrid {
|
||||
unsafe { &mut command.as_mut().grid }
|
||||
&mut unsafe { command.as_mut() }.grid
|
||||
}
|
||||
|
||||
/// Reads the origin field of the [CharGridCommand].
|
||||
|
|
|
@ -83,7 +83,7 @@ pub unsafe extern "C" fn sp_cmd_cp437_grid_set(
|
|||
pub unsafe extern "C" fn sp_cmd_cp437_grid_get(
|
||||
mut command: NonNull<Cp437GridCommand>,
|
||||
) -> *mut Cp437Grid {
|
||||
unsafe { &mut command.as_mut().grid }
|
||||
&mut unsafe { command.as_mut() }.grid
|
||||
}
|
||||
|
||||
/// Gets the origin field of the [Cp437GridCommand].
|
||||
|
|
|
@ -53,5 +53,5 @@ pub unsafe extern "C" fn sp_cmd_brightness_global_set(
|
|||
pub unsafe extern "C" fn sp_cmd_brightness_global_get(
|
||||
mut command: NonNull<GlobalBrightnessCommand>,
|
||||
) -> *mut Brightness {
|
||||
unsafe { &mut command.as_mut().brightness }
|
||||
&mut unsafe { command.as_mut() }.brightness
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
//! FFI slice helper
|
||||
|
||||
use std::ptr::NonNull;
|
||||
|
||||
/// Represents a span of memory (`&mut [u8]` ) as a struct.
|
||||
///
|
||||
/// # Safety
|
||||
|
@ -9,39 +11,28 @@
|
|||
/// - 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.
|
||||
/// - if `start` is NULL or `length` is 0, do not dereference `start`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```c
|
||||
/// ByteSlice empty = {.start: NULL, .length = 0};
|
||||
/// ```
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub struct ByteSlice {
|
||||
/// The start address of the memory.
|
||||
pub start: *mut u8,
|
||||
pub start: NonNull<u8>,
|
||||
/// The amount of memory in bytes.
|
||||
pub length: usize,
|
||||
}
|
||||
|
||||
impl ByteSlice {
|
||||
pub(crate) const INVALID: ByteSlice = ByteSlice {
|
||||
start: std::ptr::null_mut(),
|
||||
length: 0,
|
||||
};
|
||||
|
||||
pub(crate) unsafe fn as_slice(&self) -> &[u8] {
|
||||
unsafe { std::slice::from_raw_parts(self.start, self.length) }
|
||||
unsafe { std::slice::from_raw_parts(self.start.as_ptr(), self.length) }
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn as_slice_mut(&mut self) -> &mut [u8] {
|
||||
unsafe { std::slice::from_raw_parts_mut(self.start, self.length) }
|
||||
unsafe {
|
||||
std::slice::from_raw_parts_mut(self.start.as_ptr(), self.length)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn from_slice(slice: &mut [u8]) -> Self {
|
||||
Self {
|
||||
start: slice.as_mut_ptr(),
|
||||
start: NonNull::new(slice.as_mut_ptr()).unwrap(),
|
||||
length: slice.len(),
|
||||
}
|
||||
}
|
||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -35,19 +35,13 @@ pub mod packet;
|
|||
/// Functions related to [UdpSocket].
|
||||
pub mod udp;
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
/// Actual hardware limit is around 28-29ms/frame. Rounded up for less dropped packets.
|
||||
pub const SP_FRAME_PACING_MS: u128 = 30;
|
||||
pub const SP_FRAME_PACING_MS: u128 = Duration::from_millis(30).as_millis();
|
||||
|
||||
/// This is a type only used by cbindgen to have a type for pointers.
|
||||
pub struct UdpSocket;
|
||||
|
||||
/// This is a type only used by cbindgen to have a type for pointers.
|
||||
pub struct DisplayBitVec;
|
||||
|
||||
#[cfg(feature = "env_logger")]
|
||||
pub mod feature_env_logger {
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn init_env_logger() {
|
||||
env_logger::init();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,13 @@ pub unsafe extern "C" fn sp_packet_try_load(data: ByteSlice) -> *mut Packet {
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_packet_from_parts(
|
||||
header: Header,
|
||||
payload: ByteSlice,
|
||||
payload: *const ByteSlice,
|
||||
) -> NonNull<Packet> {
|
||||
let payload = if payload == ByteSlice::INVALID {
|
||||
None
|
||||
let payload = if payload.is_null() {
|
||||
vec![]
|
||||
} else {
|
||||
Some(Vec::from(unsafe { payload.as_slice() }))
|
||||
let payload = unsafe { (*payload).as_slice() };
|
||||
Vec::from(payload)
|
||||
};
|
||||
|
||||
heap_move_nonnull(Packet { header, payload })
|
||||
|
@ -38,24 +39,17 @@ pub unsafe extern "C" fn sp_packet_from_parts(
|
|||
pub unsafe extern "C" fn sp_packet_get_header(
|
||||
packet: NonNull<Packet>,
|
||||
) -> NonNull<Header> {
|
||||
NonNull::from(unsafe { &mut (*packet.as_ptr()).header })
|
||||
NonNull::from(&mut unsafe { (*packet.as_ptr()).header })
|
||||
}
|
||||
|
||||
/// Returns a pointer to the current payload of the provided packet.
|
||||
///
|
||||
/// Returns an [ByteSlice::INVALID] instance in case the packet does not have any payload.
|
||||
///
|
||||
/// The returned memory can be changed and will be valid until a new payload is set.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_packet_get_payload(
|
||||
packet: NonNull<Packet>,
|
||||
) -> ByteSlice {
|
||||
unsafe {
|
||||
match &mut (*packet.as_ptr()).payload {
|
||||
None => ByteSlice::INVALID,
|
||||
Some(payload) => ByteSlice::from_slice(payload),
|
||||
}
|
||||
}
|
||||
unsafe { ByteSlice::from_slice(&mut (*packet.as_ptr()).payload) }
|
||||
}
|
||||
|
||||
/// Sets the payload of the provided packet to the provided data.
|
||||
|
@ -66,13 +60,7 @@ pub unsafe extern "C" fn sp_packet_set_payload(
|
|||
packet: NonNull<Packet>,
|
||||
data: ByteSlice,
|
||||
) {
|
||||
unsafe {
|
||||
(*packet.as_ptr()).payload = if data == ByteSlice::INVALID {
|
||||
None
|
||||
} else {
|
||||
Some(data.as_slice().to_vec())
|
||||
}
|
||||
}
|
||||
unsafe { (*packet.as_ptr()).payload = data.as_slice().to_vec() }
|
||||
}
|
||||
|
||||
/// Serialize the packet into the provided buffer.
|
||||
|
|
|
@ -136,7 +136,7 @@ pub unsafe extern "C" fn sp_udp_send_header(
|
|||
) -> bool {
|
||||
let packet = Packet {
|
||||
header,
|
||||
payload: None,
|
||||
payload: vec![],
|
||||
};
|
||||
unsafe { udp_connection.as_ref() }
|
||||
.send(&Vec::from(packet))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue