more type name based naming
This commit is contained in:
parent
8f13ba61f0
commit
8116375fd0
27 changed files with 787 additions and 750 deletions
|
@ -3,27 +3,27 @@
|
|||
int main(void) {
|
||||
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)
|
||||
return 1;
|
||||
|
||||
sp_char_grid_set(grid, 0, 0, 'H');
|
||||
sp_char_grid_set(grid, 1, 0, 'e');
|
||||
sp_char_grid_set(grid, 2, 0, 'l');
|
||||
sp_char_grid_set(grid, 3, 0, 'l');
|
||||
sp_char_grid_set(grid, 4, 0, 'o');
|
||||
sp_char_grid_set(grid, 0, 1, 'W');
|
||||
sp_char_grid_set(grid, 1, 1, 'o');
|
||||
sp_char_grid_set(grid, 2, 1, 'r');
|
||||
sp_char_grid_set(grid, 3, 1, 'l');
|
||||
sp_char_grid_set(grid, 4, 1, 'd');
|
||||
sp_chargrid_set(grid, 0, 0, 'H');
|
||||
sp_chargrid_set(grid, 1, 0, 'e');
|
||||
sp_chargrid_set(grid, 2, 0, 'l');
|
||||
sp_chargrid_set(grid, 3, 0, 'l');
|
||||
sp_chargrid_set(grid, 4, 0, 'o');
|
||||
sp_chargrid_set(grid, 0, 1, 'W');
|
||||
sp_chargrid_set(grid, 1, 1, 'o');
|
||||
sp_chargrid_set(grid, 2, 1, 'r');
|
||||
sp_chargrid_set(grid, 3, 1, 'l');
|
||||
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)
|
||||
return 1;
|
||||
sp_udp_send_packet(sock, packet);
|
||||
sp_udpsocket_send_packet(sock, packet);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -5,14 +5,14 @@ void enable_all_pixels(void) {
|
|||
Bitmap *all_on = sp_bitmap_new_max_sized();
|
||||
sp_bitmap_fill(all_on, true);
|
||||
|
||||
BitmapCommand *bitmapCommand = sp_cmd_bitmap_from_bitmap(all_on);
|
||||
Packet *packet = sp_cmd_bitmap_try_into_packet(bitmapCommand);
|
||||
BitmapCommand *bitmapCommand = sp_bitmapcommand_from_bitmap(all_on);
|
||||
Packet *packet = sp_bitmapcommand_try_into_packet(bitmapCommand);
|
||||
if (packet != NULL)
|
||||
sp_udp_send_packet(sock, packet);
|
||||
sp_udpsocket_send_packet(sock, packet);
|
||||
}
|
||||
|
||||
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++) {
|
||||
slice.start[index] = (uint8_t)(index % ((size_t) Brightness_MAX));
|
||||
}
|
||||
|
@ -23,13 +23,13 @@ int main(void) {
|
|||
|
||||
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);
|
||||
|
||||
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)
|
||||
return -2;
|
||||
|
||||
sp_udp_send_packet(sock, packet);
|
||||
sp_udpsocket_send_packet(sock, packet);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -28,12 +28,12 @@ bool log_command(struct Command command) {
|
|||
case COMMAND_TAG_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;
|
||||
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 h = sp_bitmap_height(bitmap);
|
||||
|
||||
|
@ -45,11 +45,11 @@ bool log_command(struct Command command) {
|
|||
BrightnessGridCommand *gridCommand = command.data.brightness_grid;
|
||||
|
||||
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);
|
||||
size_t w = sp_brightness_grid_width(grid);
|
||||
size_t h = sp_brightness_grid_height(grid);
|
||||
BrightnessGrid *grid = sp_brightnessgridcommand_get_grid_mut(gridCommand);
|
||||
size_t w = sp_brightnessgrid_width(grid);
|
||||
size_t h = sp_brightnessgrid_height(grid);
|
||||
|
||||
printf("-> BrightnessGridCommand with params: x=%zu, y=%zu, w=%zu, h=%zu\n",
|
||||
x, y, w, h);
|
||||
|
@ -59,11 +59,11 @@ bool log_command(struct Command command) {
|
|||
CharGridCommand *gridCommand = command.data.char_grid;
|
||||
|
||||
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);
|
||||
size_t w = sp_char_grid_width(grid);
|
||||
size_t h = sp_char_grid_height(grid);
|
||||
CharGrid *grid = sp_chargridcommand_get_grid_mut(gridCommand);
|
||||
size_t w = sp_chargrid_width(grid);
|
||||
size_t h = sp_chargrid_height(grid);
|
||||
|
||||
printf("-> CharGridCommand with params: x=%zu, y=%zu, w=%zu, h=%zu\n",
|
||||
x, y, w, h);
|
||||
|
@ -73,11 +73,11 @@ bool log_command(struct Command command) {
|
|||
Cp437GridCommand *gridCommand = command.data.cp437_grid;
|
||||
|
||||
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);
|
||||
size_t w = sp_cp437_grid_width(grid);
|
||||
size_t h = sp_cp437_grid_height(grid);
|
||||
Cp437Grid *grid = sp_cp437gridcommand_get_grid_mut(gridCommand);
|
||||
size_t w = sp_cp437grid_width(grid);
|
||||
size_t h = sp_cp437grid_height(grid);
|
||||
|
||||
printf("-> Cp437GridCommand with params: x=%zu, y=%zu, w=%zu, h=%zu\n",
|
||||
x, y, w, h);
|
||||
|
@ -86,10 +86,10 @@ bool log_command(struct Command command) {
|
|||
case COMMAND_TAG_BIT_VEC: {
|
||||
BitVecCommand *bitvecCommand = command.data.bit_vec;
|
||||
|
||||
size_t offset = sp_cmd_bitvec_get_offset(bitvecCommand);
|
||||
CompressionCode compression = sp_cmd_bitvec_get_compression(bitvecCommand);
|
||||
size_t offset = sp_bitveccommand_get_offset(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;
|
||||
switch (operation) {
|
||||
case BINARY_OPERATION_AND:
|
||||
|
@ -109,8 +109,8 @@ bool log_command(struct Command command) {
|
|||
break;
|
||||
}
|
||||
|
||||
BitVec *bitvec = sp_cmd_bitvec_get_bitvec_mut(bitvecCommand);
|
||||
size_t len = sp_bitvec_len(bitvec);
|
||||
BitVec *bitvec = sp_bitveccommand_get_bitvec_mut(bitvecCommand);
|
||||
size_t len = sp_displaybitvec_len(bitvec);
|
||||
|
||||
printf("-> BitVecCommand with params: offset=%zu, length=%zu, compression=%hu, operation=%s\n",
|
||||
offset, len, compression, operationText);
|
||||
|
@ -129,7 +129,7 @@ bool log_command(struct Command command) {
|
|||
break;
|
||||
}
|
||||
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);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
static UdpSocket *sock = NULL;
|
||||
|
||||
void sock_free() {
|
||||
sp_udp_free(sock);
|
||||
sp_udpsocket_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);
|
||||
sock = sp_udpsocket_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);
|
||||
|
|
|
@ -13,14 +13,14 @@ int main(void) {
|
|||
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);
|
||||
BitmapCommand *command = sp_bitmapcommand_from_bitmap(sp_bitmap_clone(bitmap));
|
||||
Packet *packet = sp_bitmapcommand_try_into_packet(command);
|
||||
if (packet == NULL) {
|
||||
result = -2;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (!sp_udp_send_packet(sock, packet)) {
|
||||
if (!sp_udpsocket_send_packet(sock, packet)) {
|
||||
result = -3;
|
||||
goto exit;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,6 @@ int main(void) {
|
|||
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);
|
||||
|
||||
sp_udp_send_packet(sock, packet);
|
||||
sp_udpsocket_send_packet(sock, packet);
|
||||
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));
|
||||
BitVecCommand *command = sp_cmd_bitvec_new(bitvec, 0, BINARY_OPERATION_AND, COMPRESSION_CODE_LZMA);
|
||||
Packet *packet = sp_cmd_bitvec_try_into_packet(command);
|
||||
BitVecCommand *command = sp_bitveccommand_new(bitvec, 0, BINARY_OPERATION_AND, COMPRESSION_CODE_LZMA);
|
||||
Packet *packet = sp_bitveccommand_try_into_packet(command);
|
||||
if (packet == NULL) {
|
||||
result = -2;
|
||||
goto exit;
|
||||
}
|
||||
if (!sp_udp_send_packet(sock, packet)) {
|
||||
if (!sp_udpsocket_send_packet(sock, packet)) {
|
||||
result = -3;
|
||||
goto exit;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue