add command code constants, send header

This commit is contained in:
Vinzenz Schroeter 2025-04-12 21:47:23 +02:00
parent f193c659b9
commit ce70ecd9e2
12 changed files with 141 additions and 60 deletions

View file

@ -95,6 +95,36 @@ enum BinaryOperation
typedef uint8_t BinaryOperation;
#endif // __cplusplus
/**
* The u16 command codes used for the [Command]s.
*/
enum CommandCode
#ifdef __cplusplus
: uint16_t
#endif // __cplusplus
{
COMMAND_CODE_CLEAR = 2,
COMMAND_CODE_CP437_DATA = 3,
COMMAND_CODE_CHAR_BRIGHTNESS = 5,
COMMAND_CODE_BRIGHTNESS = 7,
COMMAND_CODE_HARD_RESET = 11,
COMMAND_CODE_FADE_OUT = 13,
COMMAND_CODE_BITMAP_LEGACY = 16,
COMMAND_CODE_BITMAP_LINEAR = 18,
COMMAND_CODE_BITMAP_LINEAR_WIN_UNCOMPRESSED = 19,
COMMAND_CODE_BITMAP_LINEAR_AND = 20,
COMMAND_CODE_BITMAP_LINEAR_OR = 21,
COMMAND_CODE_BITMAP_LINEAR_XOR = 22,
COMMAND_CODE_BITMAP_LINEAR_WIN_ZLIB = 23,
COMMAND_CODE_BITMAP_LINEAR_WIN_BZIP2 = 24,
COMMAND_CODE_BITMAP_LINEAR_WIN_LZMA = 25,
COMMAND_CODE_UTF8_DATA = 32,
COMMAND_CODE_BITMAP_LINEAR_WIN_ZSTD = 26,
};
#ifndef __cplusplus
typedef uint16_t CommandCode;
#endif // __cplusplus
/**
* Specifies the kind of compression to use. Availability depends on features.
*
@ -683,7 +713,7 @@ BrightnessGrid *sp_brightness_grid_load(size_t width,
*
* # Examples
* ```C
* UdpConnection connection = sp_connection_open("127.0.0.1:2342");
* UdpConnection connection = sp_udp_open("127.0.0.1:2342");
* if (connection == NULL)
* return 1;
*
@ -692,7 +722,7 @@ BrightnessGrid *sp_brightness_grid_load(size_t width,
* sp_brightness_grid_set(grid, 1, 1, 10);
*
* TypedCommand command = sp_command_char_brightness(grid);
* sp_connection_free(connection);
* sp_udp_free(connection);
* ```
*/
BrightnessGrid */*notnull*/ sp_brightness_grid_new(size_t width, size_t height);
@ -899,7 +929,7 @@ TypedCommand */*notnull*/ sp_command_char_grid(size_t x,
* # Examples
*
* ```C
* sp_connection_send_command(connection, sp_command_clear());
* sp_udp_send_command(connection, sp_command_clear());
* ```
*/
TypedCommand */*notnull*/ sp_command_clear(void);
@ -1122,6 +1152,8 @@ void sp_packet_set_payload(Packet */*notnull*/ packet, ByteSlice data);
*/
Packet *sp_packet_try_load(ByteSlice data);
bool sp_u16_to_command_code(uint16_t code, CommandCode *result);
/**
* Closes and deallocates a [UdpConnection].
*/
@ -1135,9 +1167,9 @@ void sp_udp_free(UdpConnection */*notnull*/ connection);
* # Examples
*
* ```C
* UdpConnection connection = sp_connection_open("172.23.42.29:2342");
* UdpConnection connection = sp_udp_open("172.23.42.29:2342");
* if (connection != NULL)
* sp_connection_send_command(connection, sp_command_clear());
* sp_udp_send_command(connection, sp_command_clear());
* ```
*/
UdpConnection *sp_udp_open(char */*notnull*/ host);
@ -1150,9 +1182,9 @@ UdpConnection *sp_udp_open(char */*notnull*/ host);
* # Examples
*
* ```C
* UdpConnection connection = sp_connection_open_ipv4(172, 23, 42, 29, 2342);
* UdpConnection connection = sp_udp_open_ipv4(172, 23, 42, 29, 2342);
* if (connection != NULL)
* sp_connection_send_command(connection, sp_command_clear());
* sp_udp_send_command(connection, sp_command_clear());
* ```
*/
UdpConnection *sp_udp_open_ipv4(uint8_t ip1,
@ -1171,13 +1203,26 @@ UdpConnection *sp_udp_open_ipv4(uint8_t ip1,
* # Examples
*
* ```C
* sp_connection_send_command(connection, sp_command_clear());
* sp_connection_send_command(connection, sp_command_brightness(5));
* sp_udp_send_command(connection, sp_command_brightness(5));
* ```
*/
bool sp_udp_send_command(UdpConnection */*notnull*/ connection,
TypedCommand */*notnull*/ command);
/**
* Sends a [Header] to the display using the [UdpConnection].
*
* returns: true in case of success
*
* # Examples
*
* ```C
* sp_udp_send_header(connection, sp_command_brightness(5));
* ```
*/
bool sp_udp_send_header(UdpConnection */*notnull*/ udp_connection,
Header header);
/**
* Sends a [Packet] to the display using the [UdpConnection].
*