fix c api, add usage example
This commit is contained in:
parent
98e8a6d639
commit
4bb505650c
12 changed files with 488 additions and 237 deletions
23
examples/lang_c/CMakeLists.txt
Normal file
23
examples/lang_c/CMakeLists.txt
Normal file
|
@ -0,0 +1,23 @@
|
|||
cmake_minimum_required(VERSION 3.28)
|
||||
project(lang_c C)
|
||||
set(CMAKE_C_STANDARD 17)
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
Corrosion
|
||||
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
|
||||
GIT_TAG v0.5 # Optionally specify a commit hash, version tag or branch here
|
||||
)
|
||||
FetchContent_MakeAvailable(Corrosion)
|
||||
|
||||
# Import targets defined in a package or workspace manifest `Cargo.toml` file
|
||||
corrosion_import_crate(
|
||||
MANIFEST_PATH ../../servicepoint2/Cargo.toml
|
||||
PROFILE release
|
||||
FEATURES c-api
|
||||
ALL_FEATURES)
|
||||
|
||||
add_executable(lang_c main.c)
|
||||
|
||||
target_link_libraries(lang_c PRIVATE servicepoint2)
|
||||
|
25
examples/lang_c/main.c
Normal file
25
examples/lang_c/main.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include <stdio.h>
|
||||
#include "../../servicepoint2/sp2-bindings.h"
|
||||
|
||||
int main(void) {
|
||||
sp2_Connection *connection = sp2_connection_open("localhost:2342");
|
||||
if (connection == NULL)
|
||||
return 1;
|
||||
|
||||
sp2_Command *command = sp2_command_clear();
|
||||
if (command == NULL)
|
||||
return 2;
|
||||
if (!sp2_connection_send(connection, command))
|
||||
return 3;
|
||||
|
||||
sp2_PixelGrid *pixels = sp2_pixel_grid_new(sp2_PIXEL_WIDTH, sp2_PIXEL_HEIGHT);
|
||||
sp2_pixel_grid_fill(pixels, true);
|
||||
command = sp2_command_bitmap_linear_win(0, 0, pixels);
|
||||
if (command == NULL)
|
||||
return 4;
|
||||
if (!sp2_connection_send(connection, command))
|
||||
return 5;
|
||||
|
||||
sp2_connection_dealloc(connection);
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue