more type name based naming
This commit is contained in:
parent
8f13ba61f0
commit
8116375fd0
|
@ -96,7 +96,7 @@ endif
|
||||||
|
|
||||||
# ADD NEW EXAMPLES HERE
|
# ADD NEW EXAMPLES HERE
|
||||||
_c_src := src/announce.c src/brightness_tester.c src/header_logger.c \
|
_c_src := src/announce.c src/brightness_tester.c src/header_logger.c \
|
||||||
src/moving_line.c src/random_stuff.c src/wiping_clear.c
|
src/moving_line.c src/random_stuff.c src/wiping_clear.c src/undefined.c
|
||||||
_programs := $(basename $(notdir $(_c_src)))
|
_programs := $(basename $(notdir $(_c_src)))
|
||||||
_bins := $(_programs)
|
_bins := $(_programs)
|
||||||
_unstripped_bins := $(addsuffix _unstripped, $(_bins))
|
_unstripped_bins := $(addsuffix _unstripped, $(_bins))
|
||||||
|
|
|
@ -3,27 +3,27 @@
|
||||||
int main(void) {
|
int main(void) {
|
||||||
sock_init();
|
sock_init();
|
||||||
|
|
||||||
sp_udp_send_header(sock, (Header) {.command_code = COMMAND_CODE_CLEAR});
|
sp_udpsocket_send_header(sock, (Header) {.command_code = COMMAND_CODE_CLEAR});
|
||||||
|
|
||||||
CharGrid *grid = sp_char_grid_new(5, 2);
|
CharGrid *grid = sp_chargrid_new(5, 2);
|
||||||
if (grid == NULL)
|
if (grid == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
sp_char_grid_set(grid, 0, 0, 'H');
|
sp_chargrid_set(grid, 0, 0, 'H');
|
||||||
sp_char_grid_set(grid, 1, 0, 'e');
|
sp_chargrid_set(grid, 1, 0, 'e');
|
||||||
sp_char_grid_set(grid, 2, 0, 'l');
|
sp_chargrid_set(grid, 2, 0, 'l');
|
||||||
sp_char_grid_set(grid, 3, 0, 'l');
|
sp_chargrid_set(grid, 3, 0, 'l');
|
||||||
sp_char_grid_set(grid, 4, 0, 'o');
|
sp_chargrid_set(grid, 4, 0, 'o');
|
||||||
sp_char_grid_set(grid, 0, 1, 'W');
|
sp_chargrid_set(grid, 0, 1, 'W');
|
||||||
sp_char_grid_set(grid, 1, 1, 'o');
|
sp_chargrid_set(grid, 1, 1, 'o');
|
||||||
sp_char_grid_set(grid, 2, 1, 'r');
|
sp_chargrid_set(grid, 2, 1, 'r');
|
||||||
sp_char_grid_set(grid, 3, 1, 'l');
|
sp_chargrid_set(grid, 3, 1, 'l');
|
||||||
sp_char_grid_set(grid, 4, 1, 'd');
|
sp_chargrid_set(grid, 4, 1, 'd');
|
||||||
|
|
||||||
Packet *packet = sp_char_grid_into_packet(grid, 0, 0);
|
Packet *packet = sp_chargrid_into_packet(grid, 0, 0);
|
||||||
if (packet == NULL)
|
if (packet == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
sp_udp_send_packet(sock, packet);
|
sp_udpsocket_send_packet(sock, packet);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,14 @@ void enable_all_pixels(void) {
|
||||||
Bitmap *all_on = sp_bitmap_new_max_sized();
|
Bitmap *all_on = sp_bitmap_new_max_sized();
|
||||||
sp_bitmap_fill(all_on, true);
|
sp_bitmap_fill(all_on, true);
|
||||||
|
|
||||||
BitmapCommand *bitmapCommand = sp_cmd_bitmap_from_bitmap(all_on);
|
BitmapCommand *bitmapCommand = sp_bitmapcommand_from_bitmap(all_on);
|
||||||
Packet *packet = sp_cmd_bitmap_try_into_packet(bitmapCommand);
|
Packet *packet = sp_bitmapcommand_try_into_packet(bitmapCommand);
|
||||||
if (packet != NULL)
|
if (packet != NULL)
|
||||||
sp_udp_send_packet(sock, packet);
|
sp_udpsocket_send_packet(sock, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void make_brightness_pattern(BrightnessGrid *grid) {
|
void make_brightness_pattern(BrightnessGrid *grid) {
|
||||||
ByteSlice slice = sp_brightness_grid_data_ref_mut(grid);
|
ByteSlice slice = sp_brightnessgrid_data_ref_mut(grid);
|
||||||
for (size_t index = 0; index < slice.length; index++) {
|
for (size_t index = 0; index < slice.length; index++) {
|
||||||
slice.start[index] = (uint8_t)(index % ((size_t) Brightness_MAX));
|
slice.start[index] = (uint8_t)(index % ((size_t) Brightness_MAX));
|
||||||
}
|
}
|
||||||
|
@ -23,13 +23,13 @@ int main(void) {
|
||||||
|
|
||||||
enable_all_pixels();
|
enable_all_pixels();
|
||||||
|
|
||||||
BrightnessGrid *grid = sp_brightness_grid_new(TILE_WIDTH, TILE_HEIGHT);
|
BrightnessGrid *grid = sp_brightnessgrid_new(TILE_WIDTH, TILE_HEIGHT);
|
||||||
make_brightness_pattern(grid);
|
make_brightness_pattern(grid);
|
||||||
|
|
||||||
Packet *packet = sp_cmd_brightness_grid_into_packet(sp_cmd_brightness_grid_from_grid(grid));
|
Packet *packet = sp_brightnessgridcommand_into_packet(sp_brightnessgridcommand_from_grid(grid));
|
||||||
if (packet == NULL)
|
if (packet == NULL)
|
||||||
return -2;
|
return -2;
|
||||||
|
|
||||||
sp_udp_send_packet(sock, packet);
|
sp_udpsocket_send_packet(sock, packet);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,12 +28,12 @@ bool log_command(struct Command command) {
|
||||||
case COMMAND_TAG_BITMAP: {
|
case COMMAND_TAG_BITMAP: {
|
||||||
BitmapCommand *bitmapCommand = command.data.bitmap;
|
BitmapCommand *bitmapCommand = command.data.bitmap;
|
||||||
|
|
||||||
CompressionCode compression = sp_cmd_bitmap_get_compression(bitmapCommand);
|
CompressionCode compression = sp_bitmapcommand_get_compression(bitmapCommand);
|
||||||
|
|
||||||
size_t x, y;
|
size_t x, y;
|
||||||
sp_cmd_bitmap_get_origin(bitmapCommand, &x, &y);
|
sp_bitmapcommand_get_origin(bitmapCommand, &x, &y);
|
||||||
|
|
||||||
Bitmap *bitmap = sp_cmd_bitmap_get_bitmap_mut(bitmapCommand);
|
Bitmap *bitmap = sp_bitmapcommand_get_bitmap_mut(bitmapCommand);
|
||||||
size_t w = sp_bitmap_width(bitmap);
|
size_t w = sp_bitmap_width(bitmap);
|
||||||
size_t h = sp_bitmap_height(bitmap);
|
size_t h = sp_bitmap_height(bitmap);
|
||||||
|
|
||||||
|
@ -45,11 +45,11 @@ bool log_command(struct Command command) {
|
||||||
BrightnessGridCommand *gridCommand = command.data.brightness_grid;
|
BrightnessGridCommand *gridCommand = command.data.brightness_grid;
|
||||||
|
|
||||||
size_t x, y;
|
size_t x, y;
|
||||||
sp_cmd_brightness_grid_get_origin(gridCommand, &x, &y);
|
sp_brightnessgridcommand_get_origin(gridCommand, &x, &y);
|
||||||
|
|
||||||
BrightnessGrid *grid = sp_cmd_brightness_grid_get_grid_mut(gridCommand);
|
BrightnessGrid *grid = sp_brightnessgridcommand_get_grid_mut(gridCommand);
|
||||||
size_t w = sp_brightness_grid_width(grid);
|
size_t w = sp_brightnessgrid_width(grid);
|
||||||
size_t h = sp_brightness_grid_height(grid);
|
size_t h = sp_brightnessgrid_height(grid);
|
||||||
|
|
||||||
printf("-> BrightnessGridCommand with params: x=%zu, y=%zu, w=%zu, h=%zu\n",
|
printf("-> BrightnessGridCommand with params: x=%zu, y=%zu, w=%zu, h=%zu\n",
|
||||||
x, y, w, h);
|
x, y, w, h);
|
||||||
|
@ -59,11 +59,11 @@ bool log_command(struct Command command) {
|
||||||
CharGridCommand *gridCommand = command.data.char_grid;
|
CharGridCommand *gridCommand = command.data.char_grid;
|
||||||
|
|
||||||
size_t x, y;
|
size_t x, y;
|
||||||
sp_cmd_char_grid_get_origin(gridCommand, &x, &y);
|
sp_chargridcommand_get_origin(gridCommand, &x, &y);
|
||||||
|
|
||||||
CharGrid *grid = sp_cmd_char_grid_get_grid_mut(gridCommand);
|
CharGrid *grid = sp_chargridcommand_get_grid_mut(gridCommand);
|
||||||
size_t w = sp_char_grid_width(grid);
|
size_t w = sp_chargrid_width(grid);
|
||||||
size_t h = sp_char_grid_height(grid);
|
size_t h = sp_chargrid_height(grid);
|
||||||
|
|
||||||
printf("-> CharGridCommand with params: x=%zu, y=%zu, w=%zu, h=%zu\n",
|
printf("-> CharGridCommand with params: x=%zu, y=%zu, w=%zu, h=%zu\n",
|
||||||
x, y, w, h);
|
x, y, w, h);
|
||||||
|
@ -73,11 +73,11 @@ bool log_command(struct Command command) {
|
||||||
Cp437GridCommand *gridCommand = command.data.cp437_grid;
|
Cp437GridCommand *gridCommand = command.data.cp437_grid;
|
||||||
|
|
||||||
size_t x, y;
|
size_t x, y;
|
||||||
sp_cmd_cp437_grid_get_origin(gridCommand, &x, &y);
|
sp_cp437gridcommand_get_origin(gridCommand, &x, &y);
|
||||||
|
|
||||||
Cp437Grid *grid = sp_cmd_cp437_grid_get_grid_mut(gridCommand);
|
Cp437Grid *grid = sp_cp437gridcommand_get_grid_mut(gridCommand);
|
||||||
size_t w = sp_cp437_grid_width(grid);
|
size_t w = sp_cp437grid_width(grid);
|
||||||
size_t h = sp_cp437_grid_height(grid);
|
size_t h = sp_cp437grid_height(grid);
|
||||||
|
|
||||||
printf("-> Cp437GridCommand with params: x=%zu, y=%zu, w=%zu, h=%zu\n",
|
printf("-> Cp437GridCommand with params: x=%zu, y=%zu, w=%zu, h=%zu\n",
|
||||||
x, y, w, h);
|
x, y, w, h);
|
||||||
|
@ -86,10 +86,10 @@ bool log_command(struct Command command) {
|
||||||
case COMMAND_TAG_BIT_VEC: {
|
case COMMAND_TAG_BIT_VEC: {
|
||||||
BitVecCommand *bitvecCommand = command.data.bit_vec;
|
BitVecCommand *bitvecCommand = command.data.bit_vec;
|
||||||
|
|
||||||
size_t offset = sp_cmd_bitvec_get_offset(bitvecCommand);
|
size_t offset = sp_bitveccommand_get_offset(bitvecCommand);
|
||||||
CompressionCode compression = sp_cmd_bitvec_get_compression(bitvecCommand);
|
CompressionCode compression = sp_bitveccommand_get_compression(bitvecCommand);
|
||||||
|
|
||||||
BinaryOperation operation = sp_cmd_bitvec_get_operation(bitvecCommand);
|
BinaryOperation operation = sp_bitveccommand_get_operation(bitvecCommand);
|
||||||
char *operationText;
|
char *operationText;
|
||||||
switch (operation) {
|
switch (operation) {
|
||||||
case BINARY_OPERATION_AND:
|
case BINARY_OPERATION_AND:
|
||||||
|
@ -109,8 +109,8 @@ bool log_command(struct Command command) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
BitVec *bitvec = sp_cmd_bitvec_get_bitvec_mut(bitvecCommand);
|
BitVec *bitvec = sp_bitveccommand_get_bitvec_mut(bitvecCommand);
|
||||||
size_t len = sp_bitvec_len(bitvec);
|
size_t len = sp_displaybitvec_len(bitvec);
|
||||||
|
|
||||||
printf("-> BitVecCommand with params: offset=%zu, length=%zu, compression=%hu, operation=%s\n",
|
printf("-> BitVecCommand with params: offset=%zu, length=%zu, compression=%hu, operation=%s\n",
|
||||||
offset, len, compression, operationText);
|
offset, len, compression, operationText);
|
||||||
|
@ -129,7 +129,7 @@ bool log_command(struct Command command) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case COMMAND_TAG_GLOBAL_BRIGHTNESS: {
|
case COMMAND_TAG_GLOBAL_BRIGHTNESS: {
|
||||||
Brightness brightness = sp_cmd_brightness_global_get_brightness(command.data.global_brightness);
|
Brightness brightness = sp_globalbrightnesscommand_get_brightness(command.data.global_brightness);
|
||||||
printf("-> GlobalBrightnessCommand with params: brightness=%hu\n", brightness);
|
printf("-> GlobalBrightnessCommand with params: brightness=%hu\n", brightness);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,12 @@
|
||||||
static UdpSocket *sock = NULL;
|
static UdpSocket *sock = NULL;
|
||||||
|
|
||||||
void sock_free() {
|
void sock_free() {
|
||||||
sp_udp_free(sock);
|
sp_udpsocket_free(sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sock_init() {
|
void sock_init() {
|
||||||
//sock = sp_udp_open_ipv4(127, 0, 0, 1, 2342);
|
sock = sp_udpsocket_open_ipv4(127, 0, 0, 1, 2342);
|
||||||
sock = sp_udp_open_ipv4(172, 23, 42, 29, 2342);
|
//sock = sp_udp_open_ipv4(172, 23, 42, 29, 2342);
|
||||||
if (sock == NULL)
|
if (sock == NULL)
|
||||||
exit(-1);
|
exit(-1);
|
||||||
atexit(sock_free);
|
atexit(sock_free);
|
||||||
|
|
|
@ -13,14 +13,14 @@ int main(void) {
|
||||||
sp_bitmap_set(bitmap, (y + x) % PIXEL_WIDTH, y, true);
|
sp_bitmap_set(bitmap, (y + x) % PIXEL_WIDTH, y, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
BitmapCommand *command = sp_cmd_bitmap_from_bitmap(sp_bitmap_clone(bitmap));
|
BitmapCommand *command = sp_bitmapcommand_from_bitmap(sp_bitmap_clone(bitmap));
|
||||||
Packet *packet = sp_cmd_bitmap_try_into_packet(command);
|
Packet *packet = sp_bitmapcommand_try_into_packet(command);
|
||||||
if (packet == NULL) {
|
if (packet == NULL) {
|
||||||
result = -2;
|
result = -2;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sp_udp_send_packet(sock, packet)) {
|
if (!sp_udpsocket_send_packet(sock, packet)) {
|
||||||
result = -3;
|
result = -3;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,6 @@ int main(void) {
|
||||||
Header *header = sp_packet_get_header_mut(packet);
|
Header *header = sp_packet_get_header_mut(packet);
|
||||||
printf("[%d, %d, %d, %d, %d]\n", header->command_code, header->a, header->b, header->c, header->d);
|
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_udpsocket_send_packet(sock, packet);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
22
example/src/undefined.c
Normal file
22
example/src/undefined.c
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "servicepoint.h"
|
||||||
|
#include "helpers.h"
|
||||||
|
|
||||||
|
/// DO NOT DO ANY OF THIS!
|
||||||
|
int main(void) {
|
||||||
|
BitmapCommand *bmcmd = sp_bitmapcommand_new(sp_bitmap_new_max_sized(), 0, 0, COMPRESSION_CODE_UNCOMPRESSED);
|
||||||
|
BitVecCommand *bvcmd = (BitVecCommand *) bmcmd;
|
||||||
|
sp_bitveccommand_free(bvcmd);
|
||||||
|
|
||||||
|
uint8_t *data = calloc(1024, 1);
|
||||||
|
struct Command generic = {
|
||||||
|
.tag = COMMAND_TAG_BRIGHTNESS_GRID,
|
||||||
|
.data = {.null = data},
|
||||||
|
};
|
||||||
|
|
||||||
|
sock_init();
|
||||||
|
|
||||||
|
sp_udpsocket_send_command(sock, generic);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -14,13 +14,13 @@ int main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
BitVec *bitvec = sp_bitmap_into_bitvec(sp_bitmap_clone(enabled_pixels));
|
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);
|
BitVecCommand *command = sp_bitveccommand_new(bitvec, 0, BINARY_OPERATION_AND, COMPRESSION_CODE_LZMA);
|
||||||
Packet *packet = sp_cmd_bitvec_try_into_packet(command);
|
Packet *packet = sp_bitveccommand_try_into_packet(command);
|
||||||
if (packet == NULL) {
|
if (packet == NULL) {
|
||||||
result = -2;
|
result = -2;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
if (!sp_udp_send_packet(sock, packet)) {
|
if (!sp_udpsocket_send_packet(sock, packet)) {
|
||||||
result = -3;
|
result = -3;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -8,14 +8,14 @@ use std::ptr::NonNull;
|
||||||
|
|
||||||
wrap_command!(Bitmap);
|
wrap_command!(Bitmap);
|
||||||
|
|
||||||
wrap_fields!(cmd_bitmap::BitmapCommand;
|
wrap_fields!(BitmapCommand;
|
||||||
prop bitmap: Bitmap { mut get(); move set(value); };
|
prop bitmap: Bitmap { mut get(); move set(value); };
|
||||||
prop compression: CompressionCode { get(); set(value); };
|
prop compression: CompressionCode { get(); set(value); };
|
||||||
);
|
);
|
||||||
|
|
||||||
wrap_origin_accessors!(cmd_bitmap::BitmapCommand);
|
wrap_origin_accessors!(BitmapCommand);
|
||||||
|
|
||||||
wrap_functions!(cmd_bitmap;
|
wrap_functions!(associate BitmapCommand;
|
||||||
/// Sets a window of pixels to the specified values.
|
/// Sets a window of pixels to the specified values.
|
||||||
///
|
///
|
||||||
/// The passed [Bitmap] gets consumed.
|
/// The passed [Bitmap] gets consumed.
|
||||||
|
|
|
@ -11,14 +11,14 @@ use std::ptr::NonNull;
|
||||||
|
|
||||||
wrap_command!(BitVec);
|
wrap_command!(BitVec);
|
||||||
|
|
||||||
wrap_fields!(cmd_bitvec::BitVecCommand;
|
wrap_fields!(BitVecCommand;
|
||||||
prop bitvec: DisplayBitVec { mut get(); move set(value); };
|
prop bitvec: DisplayBitVec { mut get(); move set(value); };
|
||||||
prop offset: Offset { get(); set(value); };
|
prop offset: Offset { get(); set(value); };
|
||||||
prop operation: BinaryOperation { get(); set(value); };
|
prop operation: BinaryOperation { get(); set(value); };
|
||||||
prop compression: CompressionCode { get(); set(value); };
|
prop compression: CompressionCode { get(); set(value); };
|
||||||
);
|
);
|
||||||
|
|
||||||
wrap_functions!(cmd_bitvec;
|
wrap_functions!(associate BitVecCommand;
|
||||||
|
|
||||||
/// Set pixel data starting at the pixel offset on screen.
|
/// Set pixel data starting at the pixel offset on screen.
|
||||||
///
|
///
|
||||||
|
|
|
@ -8,13 +8,13 @@ use std::ptr::NonNull;
|
||||||
|
|
||||||
wrap_command!(BrightnessGrid);
|
wrap_command!(BrightnessGrid);
|
||||||
|
|
||||||
wrap_fields!(cmd_brightnessgrid::BrightnessGridCommand;
|
wrap_fields!(BrightnessGridCommand;
|
||||||
prop grid: BrightnessGrid { mut get(); move set(grid); };
|
prop grid: BrightnessGrid { mut get(); move set(grid); };
|
||||||
);
|
);
|
||||||
|
|
||||||
wrap_origin_accessors!(cmd_brightnessgrid::BrightnessGridCommand);
|
wrap_origin_accessors!(BrightnessGridCommand);
|
||||||
|
|
||||||
wrap_functions!(cmd_brightnessgrid;
|
wrap_functions!(associate BrightnessGridCommand;
|
||||||
|
|
||||||
/// Set the brightness of individual tiles in a rectangular area of the display.
|
/// Set the brightness of individual tiles in a rectangular area of the display.
|
||||||
///
|
///
|
||||||
|
|
|
@ -5,22 +5,18 @@ use servicepoint::{ClearCommand, FadeOutCommand, HardResetCommand};
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
macro_rules! wrap_cc_only {
|
macro_rules! wrap_cc_only {
|
||||||
($(#[$meta:meta])*; $command:ident, $prefix:ident, $object_type:ident) => {
|
|
||||||
wrap_command!($command);
|
|
||||||
|
|
||||||
wrap_functions!($prefix;
|
|
||||||
$(#[$meta])*
|
|
||||||
///
|
|
||||||
#[doc = concat!(" Returns: a new [`",stringify!($object_type),"`] instance.")]
|
|
||||||
fn new() -> NonNull<$object_type> {
|
|
||||||
heap_move_nonnull($object_type)
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
($(#[$meta:meta])* $command:ident) => {
|
($(#[$meta:meta])* $command:ident) => {
|
||||||
::paste::paste!{
|
::paste::paste!{
|
||||||
wrap_cc_only!($(#[$meta])*; $command, [< cmd_ $command:lower >], [< $command Command >]);
|
wrap_command!($command);
|
||||||
|
|
||||||
|
wrap_functions!(associate [< $command Command >];
|
||||||
|
$(#[$meta])*
|
||||||
|
///
|
||||||
|
#[doc = " Returns: a new [`" [< $command Command >] "`] instance."]
|
||||||
|
fn new() -> NonNull<[< $command Command >]> {
|
||||||
|
heap_move_nonnull([< $command Command >])
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,11 @@ use std::ptr::NonNull;
|
||||||
|
|
||||||
wrap_command!(CharGrid);
|
wrap_command!(CharGrid);
|
||||||
|
|
||||||
wrap_fields!(cmd_chargrid::CharGridCommand;
|
wrap_fields!(CharGridCommand;
|
||||||
prop grid: CharGrid { mut get(); move set(grid); };
|
prop grid: CharGrid { mut get(); move set(grid); };
|
||||||
);
|
);
|
||||||
|
|
||||||
wrap_origin_accessors!(cmd_chargrid::CharGridCommand);
|
wrap_origin_accessors!(CharGridCommand);
|
||||||
|
|
||||||
wrap_functions!(cmd_chargrid;
|
wrap_functions!(cmd_chargrid;
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,11 @@ use std::ptr::NonNull;
|
||||||
|
|
||||||
wrap_command!(Cp437Grid);
|
wrap_command!(Cp437Grid);
|
||||||
|
|
||||||
wrap_fields!(cmd_cp437grid::Cp437GridCommand;
|
wrap_fields!(Cp437GridCommand;
|
||||||
prop grid: Cp437Grid { mut get(); move set(grid); };
|
prop grid: Cp437Grid { mut get(); move set(grid); };
|
||||||
);
|
);
|
||||||
|
|
||||||
wrap_origin_accessors!(cmd_cp437grid::Cp437GridCommand);
|
wrap_origin_accessors!(Cp437GridCommand);
|
||||||
|
|
||||||
wrap_functions!(cmd_cp437grid;
|
wrap_functions!(cmd_cp437grid;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::{
|
||||||
use servicepoint::{Brightness, GlobalBrightnessCommand, Packet};
|
use servicepoint::{Brightness, GlobalBrightnessCommand, Packet};
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
wrap_functions!(cmd_globalbrightness;
|
wrap_functions!(associate GlobalBrightnessCommand;
|
||||||
|
|
||||||
/// Set the brightness of all tiles to the same value.
|
/// Set the brightness of all tiles to the same value.
|
||||||
///
|
///
|
||||||
|
@ -24,8 +24,7 @@ wrap_functions!(cmd_globalbrightness;
|
||||||
|
|
||||||
wrap_command!(GlobalBrightness);
|
wrap_command!(GlobalBrightness);
|
||||||
|
|
||||||
wrap_fields!(
|
wrap_fields!(GlobalBrightnessCommand;
|
||||||
cmd_globalbrightness::GlobalBrightnessCommand;
|
|
||||||
prop brightness: Brightness {
|
prop brightness: Brightness {
|
||||||
get();
|
get();
|
||||||
set(value);
|
set(value);
|
||||||
|
|
|
@ -15,9 +15,10 @@ pub use cp437_grid_command::*;
|
||||||
pub use generic_command::*;
|
pub use generic_command::*;
|
||||||
|
|
||||||
macro_rules! wrap_origin_accessors {
|
macro_rules! wrap_origin_accessors {
|
||||||
( $prefix:ident :: $object_type:ty ) => {
|
( $object_type:ident ) => {
|
||||||
$crate::macros::wrap_functions!($prefix;
|
::paste::paste! {
|
||||||
#[doc = concat!(" Reads the origin field of the [`", stringify!($object_type), "`].")]
|
$crate::macros::wrap_functions!(associate $object_type;
|
||||||
|
#[doc = " Reads the origin field of the [`" $object_type "`]."]
|
||||||
fn get_origin(
|
fn get_origin(
|
||||||
command: NonNull<$object_type>,
|
command: NonNull<$object_type>,
|
||||||
origin_x: NonNull<usize>,
|
origin_x: NonNull<usize>,
|
||||||
|
@ -30,17 +31,19 @@ macro_rules! wrap_origin_accessors {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc = concat!(" Overwrites the origin field of the [`", stringify!($object_type), "`].")]
|
#[doc = " Overwrites the origin field of the [`" $object_type "`]."]
|
||||||
fn set_origin(
|
fn set_origin(
|
||||||
command: NonNull<$object_type>,
|
command: NonNull<$object_type>,
|
||||||
origin_x: usize,
|
origin_x: usize,
|
||||||
origin_y: usize,
|
origin_y: usize,
|
||||||
) {
|
) {
|
||||||
unsafe {
|
unsafe {
|
||||||
$crate::macros::nonnull_as_mut!(command).origin = ::servicepoint::Origin::new(origin_x, origin_y);
|
$crate::macros::nonnull_as_mut!(command).origin =
|
||||||
|
::servicepoint::Origin::new(origin_x, origin_y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,15 +65,14 @@ macro_rules! derive_command_from {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! wrap_command {
|
macro_rules! wrap_command {
|
||||||
($command:ident, $prefix:ident, $object_type:ident) => {
|
($command:ident, $object_type:ident) => {
|
||||||
$crate::macros::wrap_clone!($prefix::$object_type);
|
$crate::macros::wrap_clone!($object_type);
|
||||||
$crate::macros::wrap_free!($prefix::$object_type);
|
$crate::macros::wrap_free!($object_type);
|
||||||
|
|
||||||
$crate::commands::derive_command_from!($command);
|
$crate::commands::derive_command_from!($command);
|
||||||
};
|
};
|
||||||
($command:ident) => {
|
($command:ident) => {
|
||||||
::paste::paste!{
|
::paste::paste! {
|
||||||
wrap_command!($command, [< cmd_ $command:lower >], [< $command Command >]);
|
wrap_command!($command, [< $command Command >]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ use servicepoint::{
|
||||||
};
|
};
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
wrap_clone!(bitmap::Bitmap);
|
wrap_clone!(Bitmap);
|
||||||
wrap_free!(bitmap::Bitmap);
|
wrap_free!(Bitmap);
|
||||||
|
|
||||||
wrap_functions!(bitmap;
|
wrap_functions!(bitmap;
|
||||||
|
|
||||||
|
@ -105,8 +105,7 @@ wrap_functions!(bitmap;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
wrap_methods!(
|
wrap_methods!(Bitmap;
|
||||||
bitmap::Bitmap;
|
|
||||||
|
|
||||||
/// Gets the current value at the specified position.
|
/// Gets the current value at the specified position.
|
||||||
///
|
///
|
||||||
|
|
|
@ -55,11 +55,10 @@ wrap_functions!(bitvec;
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
wrap_clone!(bitvec::DisplayBitVec);
|
wrap_clone!(DisplayBitVec);
|
||||||
wrap_free!(bitvec::DisplayBitVec);
|
wrap_free!(DisplayBitVec);
|
||||||
|
|
||||||
wrap_methods!(
|
wrap_methods!(DisplayBitVec;
|
||||||
bitvec::DisplayBitVec;
|
|
||||||
|
|
||||||
/// Gets the value of a bit.
|
/// Gets the value of a bit.
|
||||||
///
|
///
|
||||||
|
|
|
@ -71,11 +71,10 @@ wrap_functions!(brightnessgrid;
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
wrap_clone!(brightnessgrid::BrightnessGrid);
|
wrap_clone!(BrightnessGrid);
|
||||||
wrap_free!(brightnessgrid::BrightnessGrid);
|
wrap_free!(BrightnessGrid);
|
||||||
|
|
||||||
wrap_methods!(
|
wrap_methods!(BrightnessGrid;
|
||||||
brightnessgrid::BrightnessGrid;
|
|
||||||
|
|
||||||
/// Gets the current value at the specified position.
|
/// Gets the current value at the specified position.
|
||||||
///
|
///
|
||||||
|
|
|
@ -36,6 +36,7 @@ impl ByteSlice {
|
||||||
unsafe { std::slice::from_raw_parts(self.start, self.length) }
|
unsafe { std::slice::from_raw_parts(self.start, self.length) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::mut_from_ref, reason = "This is used to get a pointer from the C side")]
|
||||||
pub(crate) unsafe fn as_slice_mut(&self) -> &mut [u8] {
|
pub(crate) unsafe fn as_slice_mut(&self) -> &mut [u8] {
|
||||||
unsafe { std::slice::from_raw_parts_mut(self.start, self.length) }
|
unsafe { std::slice::from_raw_parts_mut(self.start, self.length) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,11 +58,10 @@ wrap_functions!(chargrid;
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
wrap_clone!(chargrid::CharGrid);
|
wrap_clone!(CharGrid);
|
||||||
wrap_free!(chargrid::CharGrid);
|
wrap_free!(CharGrid);
|
||||||
|
|
||||||
wrap_methods!(
|
wrap_methods!(CharGrid;
|
||||||
chargrid::CharGrid;
|
|
||||||
|
|
||||||
/// Returns the current value at the specified position.
|
/// Returns the current value at the specified position.
|
||||||
///
|
///
|
||||||
|
|
|
@ -50,11 +50,10 @@ wrap_functions!(cp437grid;
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
wrap_clone!(cp437grid::Cp437Grid);
|
wrap_clone!(Cp437Grid);
|
||||||
wrap_free!(cp437grid::Cp437Grid);
|
wrap_free!(Cp437Grid);
|
||||||
|
|
||||||
wrap_methods!(
|
wrap_methods!(Cp437Grid;
|
||||||
cp437grid::Cp437Grid;
|
|
||||||
/// Gets the current value at the specified position.
|
/// Gets the current value at the specified position.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
|
|
@ -1,22 +1,26 @@
|
||||||
macro_rules! wrap_free {
|
macro_rules! wrap_free {
|
||||||
($prefix:ident :: $typ:ty) => {
|
($typ:ident) => {
|
||||||
$crate::macros::wrap_functions!($prefix;
|
::paste::paste! {
|
||||||
#[doc = concat!("Deallocates a [`", stringify!($typ), "`] instance.")]
|
$crate::macros::wrap_functions!([< $typ:lower >];
|
||||||
|
#[doc = "Deallocates a [`" $typ "`] instance."]
|
||||||
fn free(instance: NonNull<$typ>) {
|
fn free(instance: NonNull<$typ>) {
|
||||||
unsafe { $crate::mem::heap_drop(instance) }
|
unsafe { $crate::mem::heap_drop(instance) }
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! wrap_clone {
|
macro_rules! wrap_clone {
|
||||||
($prefix:ident :: $typ:ty) => {
|
($typ:ident) => {
|
||||||
$crate::macros::wrap_functions!($prefix;
|
::paste::paste! {
|
||||||
#[doc = concat!("Clones a [`", stringify!($typ), "`] instance.")]
|
$crate::macros::wrap_functions!([< $typ:lower >];
|
||||||
|
#[doc = "Clones a [`" $typ "`] instance."]
|
||||||
fn clone(instance: NonNull<$typ>) -> NonNull<$typ> {
|
fn clone(instance: NonNull<$typ>) -> NonNull<$typ> {
|
||||||
unsafe { $crate::mem::heap_clone(instance) }
|
unsafe { $crate::mem::heap_clone(instance) }
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +39,7 @@ macro_rules! nonnull_as_mut {
|
||||||
// meta required on purpose, because otherwise the added documentation would suppress warnings
|
// meta required on purpose, because otherwise the added documentation would suppress warnings
|
||||||
macro_rules! wrap_methods {
|
macro_rules! wrap_methods {
|
||||||
(
|
(
|
||||||
$prefix:ident :: $object_type:ty;
|
$object_type:ident;
|
||||||
$(
|
$(
|
||||||
$(#[$meta:meta])+
|
$(#[$meta:meta])+
|
||||||
$ref_or_mut:ident fn $function:ident($($param_name:ident: $param_type:ty),*)
|
$ref_or_mut:ident fn $function:ident($($param_name:ident: $param_type:ty),*)
|
||||||
|
@ -48,10 +52,9 @@ macro_rules! wrap_methods {
|
||||||
)+
|
)+
|
||||||
) => {
|
) => {
|
||||||
paste::paste! {
|
paste::paste! {
|
||||||
$crate::macros::wrap_functions!($prefix;
|
$crate::macros::wrap_functions!([< $object_type:lower >];
|
||||||
$(
|
$(
|
||||||
#[doc = concat!(" Calls method [`servicepoint::", stringify!($object_type),
|
#[doc = " Calls method [`servicepoint::" $object_type "::" $function "`]."]
|
||||||
"::", stringify!($function), "`].")]
|
|
||||||
#[doc = ""]
|
#[doc = ""]
|
||||||
$(#[$meta])*
|
$(#[$meta])*
|
||||||
fn $function(
|
fn $function(
|
||||||
|
@ -82,7 +85,7 @@ macro_rules! wrap_methods {
|
||||||
|
|
||||||
macro_rules! wrap_fields {
|
macro_rules! wrap_fields {
|
||||||
(
|
(
|
||||||
$prefix:ident :: $object_type:ty;
|
$object_type:ident;
|
||||||
$(
|
$(
|
||||||
prop $prop_name:ident : $prop_type:ty {
|
prop $prop_name:ident : $prop_type:ty {
|
||||||
$(
|
$(
|
||||||
|
@ -118,11 +121,10 @@ macro_rules! wrap_fields {
|
||||||
)+
|
)+
|
||||||
) => {
|
) => {
|
||||||
paste::paste! {
|
paste::paste! {
|
||||||
$crate::macros::wrap_functions!($prefix;
|
$crate::macros::wrap_functions!([< $object_type:lower >];
|
||||||
$(
|
$(
|
||||||
$(
|
$(
|
||||||
#[doc = concat!(" Gets the value of field `", stringify!($prop_name),
|
#[doc = " Gets the value of field `" $prop_name "` of the [`servicepoint::" $object_type "`]."]
|
||||||
"` of the [`servicepoint::", stringify!($object_type),"`].")]
|
|
||||||
$($(
|
$($(
|
||||||
#[doc = ""]
|
#[doc = ""]
|
||||||
#[$get_meta]
|
#[$get_meta]
|
||||||
|
@ -230,6 +232,25 @@ macro_rules! wrap_functions {
|
||||||
)+
|
)+
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
(
|
||||||
|
associate $object_type:ident;
|
||||||
|
$(
|
||||||
|
$(#[$meta:meta])+
|
||||||
|
fn $function:ident($($param_name:ident: $param_type:ty),*$(,)?)
|
||||||
|
$(-> $return_type:ty)?
|
||||||
|
$block:block
|
||||||
|
)+
|
||||||
|
) => {
|
||||||
|
::paste::paste! {
|
||||||
|
$crate::macros::wrap_functions!{[< $object_type:lower >];
|
||||||
|
$(
|
||||||
|
$(#[$meta])+
|
||||||
|
fn $function($($param_name: $param_type),*) $(-> $return_type)?
|
||||||
|
$block
|
||||||
|
)+
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) use {
|
pub(crate) use {
|
||||||
|
|
|
@ -68,11 +68,10 @@ wrap_functions!(packet;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
wrap_clone!(packet::Packet);
|
wrap_clone!(Packet);
|
||||||
wrap_free!(packet::Packet);
|
wrap_free!(Packet);
|
||||||
|
|
||||||
wrap_fields!(
|
wrap_fields!(Packet;
|
||||||
packet::Packet;
|
|
||||||
prop header: Header {
|
prop header: Header {
|
||||||
get();
|
get();
|
||||||
mut get();
|
mut get();
|
||||||
|
|
|
@ -10,9 +10,9 @@ use std::{
|
||||||
ptr::NonNull,
|
ptr::NonNull,
|
||||||
};
|
};
|
||||||
|
|
||||||
wrap_free!(udp::UdpSocket);
|
wrap_free!(UdpSocket);
|
||||||
|
|
||||||
wrap_functions!(udp;
|
wrap_functions!(associate UdpSocket;
|
||||||
|
|
||||||
/// Creates a new instance of [UdpSocket].
|
/// Creates a new instance of [UdpSocket].
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in a new issue