sp_cmd_brightness_global_get returns value
This commit is contained in:
parent
c9d2479f5e
commit
01b3169020
5 changed files with 161 additions and 29 deletions
|
@ -49,6 +49,7 @@ int main(int argc, char **argv) {
|
|||
bool done = false;
|
||||
while (!done) {
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
printf("\n");
|
||||
|
||||
ssize_t num_bytes = recv(udp_socket, (void *) buffer, sizeof(buffer), 0);
|
||||
if (num_bytes == -1)
|
||||
|
@ -64,7 +65,6 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
struct Header *header = sp_packet_get_header(packet);
|
||||
done = header->command_code == COMMAND_CODE_HARD_RESET;
|
||||
|
||||
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",
|
||||
|
@ -72,9 +72,128 @@ int main(int argc, char **argv) {
|
|||
payload.start, payload.length);
|
||||
|
||||
struct Command command = sp_cmd_generic_try_from_packet(packet);
|
||||
if (command.tag == COMMAND_TAG_INVALID) {
|
||||
printf("received invalid command\n");
|
||||
continue;
|
||||
switch (command.tag) {
|
||||
case COMMAND_TAG_INVALID: {
|
||||
printf("-> this is an invalid command\n");
|
||||
break;
|
||||
}
|
||||
case COMMAND_TAG_HARD_RESET: {
|
||||
printf("-> HardReset command - exiting\n");
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
case COMMAND_TAG_BITMAP: {
|
||||
BitmapCommand *bitmapCommand = command.data.bitmap;
|
||||
|
||||
CompressionCode compression = sp_cmd_bitmap_get_compression(bitmapCommand);
|
||||
|
||||
size_t x, y;
|
||||
sp_cmd_bitmap_get_origin(bitmapCommand, &x, &y);
|
||||
|
||||
Bitmap *bitmap = sp_cmd_bitmap_get(bitmapCommand);
|
||||
size_t w = sp_bitmap_width(bitmap);
|
||||
size_t h = sp_bitmap_height(bitmap);
|
||||
|
||||
printf("-> BitmapCommand with params: x=%zu, y=%zu, w=%zu, h=%zu, compression=%hu\n",
|
||||
x, y, w, h, compression);
|
||||
break;
|
||||
}
|
||||
case COMMAND_TAG_BRIGHTNESS_GRID: {
|
||||
BrightnessGridCommand *gridCommand = command.data.brightness_grid;
|
||||
|
||||
size_t x, y;
|
||||
sp_cmd_brightness_grid_get_origin(gridCommand, &x, &y);
|
||||
|
||||
BrightnessGrid *grid = sp_cmd_brightness_grid_get(gridCommand);
|
||||
size_t w = sp_brightness_grid_width(grid);
|
||||
size_t h = sp_brightness_grid_height(grid);
|
||||
|
||||
printf("-> BrightnessGridCommand with params: x=%zu, y=%zu, w=%zu, h=%zu\n",
|
||||
x, y, w, h);
|
||||
break;
|
||||
}
|
||||
case COMMAND_TAG_CHAR_GRID: {
|
||||
CharGridCommand *gridCommand = command.data.char_grid;
|
||||
|
||||
size_t x, y;
|
||||
sp_cmd_char_grid_get_origin(gridCommand, &x, &y);
|
||||
|
||||
CharGrid *grid = sp_cmd_char_grid_get(gridCommand);
|
||||
size_t w = sp_char_grid_width(grid);
|
||||
size_t h = sp_char_grid_height(grid);
|
||||
|
||||
printf("-> CharGridCommand with params: x=%zu, y=%zu, w=%zu, h=%zu\n",
|
||||
x, y, w, h);
|
||||
break;
|
||||
}
|
||||
case COMMAND_TAG_CP437_GRID: {
|
||||
Cp437GridCommand *gridCommand = command.data.cp437_grid;
|
||||
|
||||
size_t x, y;
|
||||
sp_cmd_cp437_grid_get_origin(gridCommand, &x, &y);
|
||||
|
||||
Cp437Grid *grid = sp_cmd_cp437_grid_get(gridCommand);
|
||||
size_t w = sp_cp437_grid_width(grid);
|
||||
size_t h = sp_cp437_grid_height(grid);
|
||||
|
||||
printf("-> Cp437GridCommand with params: x=%zu, y=%zu, w=%zu, h=%zu\n",
|
||||
x, y, w, h);
|
||||
break;
|
||||
}
|
||||
case COMMAND_TAG_BIT_VEC: {
|
||||
BitVecCommand *bitvecCommand = command.data.bitvec;
|
||||
|
||||
size_t offset = sp_cmd_bitvec_get_offset(bitvecCommand);
|
||||
CompressionCode compression = sp_cmd_bitvec_get_compression(bitvecCommand);
|
||||
|
||||
BinaryOperation operation = sp_cmd_bitvec_get_operation(bitvecCommand);
|
||||
char *operationText;
|
||||
switch (operation) {
|
||||
case BINARY_OPERATION_AND:
|
||||
operationText = "and";
|
||||
break;
|
||||
case BINARY_OPERATION_OR:
|
||||
operationText = "or";
|
||||
break;
|
||||
case BINARY_OPERATION_XOR:
|
||||
operationText = "xor";
|
||||
break;
|
||||
case BINARY_OPERATION_OVERWRITE:
|
||||
operationText ="overwrite";
|
||||
break;
|
||||
default:
|
||||
operationText ="unknown";
|
||||
break;
|
||||
}
|
||||
|
||||
BitVec *bitvec = sp_cmd_bitvec_get(bitvecCommand);
|
||||
size_t len = sp_bitvec_len(bitvec);
|
||||
|
||||
printf("-> BitVecCommand with params: offset=%zu, length=%zu, compression=%hu, operation=%s\n",
|
||||
offset, len, compression, operationText);
|
||||
break;
|
||||
}
|
||||
case COMMAND_TAG_CLEAR: {
|
||||
printf("-> ClearCommand\n");
|
||||
break;
|
||||
}
|
||||
case COMMAND_TAG_BITMAP_LEGACY: {
|
||||
printf("-> BitmapLinearLegacy\n");
|
||||
break;
|
||||
}
|
||||
case COMMAND_TAG_FADE_OUT:{
|
||||
printf("-> FadeOutCommand\n");
|
||||
break;
|
||||
}
|
||||
case COMMAND_TAG_GLOBAL_BRIGHTNESS: {
|
||||
Brightness brightness = sp_cmd_brightness_global_get(command.data.global_brightness);
|
||||
printf("-> GlobalBrightnessCommand with params: brightness=%hu\n", brightness);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
printf("-> unknown command tag %d\n", command.tag);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sp_cmd_generic_free(command);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue