servicepoint-binding-c/src/lib.rs
2025-05-24 13:50:01 +02:00

56 lines
1.7 KiB
Rust

//! C API wrapper for the [servicepoint](https://docs.rs/servicepoint/latest/servicepoint/) crate.
//!
//! # Examples
//!
//! Make sure to check out [this GitHub repo](https://github.com/arfst23/ServicePoint) as well!
//!
//! ```C
//! #include <stdio.h>
//! #include "servicepoint.h"
//!
//! int main(void) {
//! UdpSocket *connection = sp_udp_open("172.23.42.29:2342");
//! if (connection == NULL)
//! return 1;
//!
//! Bitmap *pixels = sp_bitmap_new(SP_PIXEL_WIDTH, SP_PIXEL_HEIGHT);
//! sp_bitmap_fill(pixels, true);
//!
//! TypedCommand *command = sp_command_bitmap_linear_win(0, 0, pixels, Uncompressed);
//! while (sp_udp_send_command(connection, sp_command_clone(command)));
//!
//! sp_command_free(command);
//! sp_udp_free(connection);
//! return 0;
//! }
//! ```
/// Functions related to commands.
pub mod commands;
/// Functions related to [servicepoint::Bitmap], [servicepoint::CharGrid] and friends.
pub mod containers;
pub(crate) mod mem;
/// Functions related to [Packet].
pub mod packet;
/// Functions related to [UdpSocket].
pub mod udp;
/// Actual hardware limit is around 28-29ms/frame. Rounded up for less dropped packets.
pub const SP_FRAME_PACING_MS: u128 = 30;
/// This is a type only used by cbindgen to have a type for pointers.
pub struct UdpSocket;
/// This is a type only used by cbindgen to have a type for pointers.
pub struct DisplayBitVec;
#[cfg(feature = "env_logger")]
mod feature_env_logger {
/// Call this function at the beginning of main to enable rust logging controlled by the
/// `RUST_LOG` environment variable. See [env_logger](https://docs.rs/env_logger/latest/env_logger/).
#[no_mangle]
pub unsafe extern "C" fn init_env_logger() {
env_logger::init();
}
}