a bunch of docs
This commit is contained in:
parent
626a887480
commit
36f3d84dc8
12 changed files with 215 additions and 70 deletions
|
@ -41,6 +41,9 @@ pub unsafe extern "C" fn sp_cmd_bitmap_into_packet(
|
|||
heap_move_ok(unsafe { heap_remove(command) }.try_into())
|
||||
}
|
||||
|
||||
/// Clones an [BitmapCommand] instance.
|
||||
///
|
||||
/// returns: a new [BitmapCommand] instance.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_bitmap_clone(
|
||||
command: NonNull<BitmapCommand>,
|
||||
|
|
|
@ -41,6 +41,9 @@ pub unsafe extern "C" fn sp_cmd_bitvec_into_packet(
|
|||
heap_move_ok(unsafe { heap_remove(command) }.try_into())
|
||||
}
|
||||
|
||||
/// Clones an [BitVecCommand] instance.
|
||||
///
|
||||
/// returns: a new [BitVecCommand] instance.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_bitvec_clone(
|
||||
command: NonNull<BitVecCommand>,
|
||||
|
@ -48,6 +51,7 @@ pub unsafe extern "C" fn sp_cmd_bitvec_clone(
|
|||
unsafe { heap_clone(command) }
|
||||
}
|
||||
|
||||
/// Deallocates a [BitVecCommand].
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_bitvec_free(command: NonNull<BitVecCommand>) {
|
||||
unsafe { heap_drop(command) }
|
||||
|
|
|
@ -6,6 +6,11 @@ use servicepoint::{
|
|||
};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
/// Set the brightness of individual tiles in a rectangular area of the display.
|
||||
///
|
||||
/// The passed [BrightnessGrid] gets consumed.
|
||||
///
|
||||
/// Returns: a new [BrightnessGridCommand] instance.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_brightness_grid_new(
|
||||
grid: NonNull<BrightnessGrid>,
|
||||
|
@ -18,6 +23,8 @@ pub unsafe extern "C" fn sp_cmd_brightness_grid_new(
|
|||
})
|
||||
}
|
||||
|
||||
/// Moves the provided [BrightnessGrid] into a new [BrightnessGridCommand],
|
||||
/// leaving other fields as their default values.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_brightness_grid_from_grid(
|
||||
grid: NonNull<BrightnessGrid>,
|
||||
|
@ -32,6 +39,9 @@ pub unsafe extern "C" fn sp_cmd_brightness_grid_into_packet(
|
|||
heap_move_ok(unsafe { heap_remove(command) }.try_into())
|
||||
}
|
||||
|
||||
/// Clones an [BrightnessGridCommand] instance.
|
||||
///
|
||||
/// returns: a new [BrightnessGridCommand] instance.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_brightness_grid_clone(
|
||||
command: NonNull<BrightnessGridCommand>,
|
||||
|
@ -39,6 +49,7 @@ pub unsafe extern "C" fn sp_cmd_brightness_grid_clone(
|
|||
unsafe { heap_clone(command) }
|
||||
}
|
||||
|
||||
/// Deallocates a [BitmapCommand].
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_brightness_grid_free(
|
||||
command: NonNull<BitmapCommand>,
|
||||
|
|
|
@ -7,17 +7,12 @@ use std::ptr::NonNull;
|
|||
/// Does not affect brightness.
|
||||
///
|
||||
/// Returns: a new [ClearCommand] instance.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```C
|
||||
/// sp_udp_send_command(connection, sp_cmd_clear());
|
||||
/// ```
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_clear_new() -> NonNull<ClearCommand> {
|
||||
heap_move_nonnull(ClearCommand)
|
||||
}
|
||||
|
||||
/// Deallocates a [ClearCommand].
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_clear_free(command: NonNull<ClearCommand>) {
|
||||
unsafe { heap_drop(command) }
|
||||
|
@ -33,6 +28,7 @@ pub unsafe extern "C" fn sp_cmd_hard_reset_new() -> NonNull<HardResetCommand> {
|
|||
heap_move_nonnull(HardResetCommand)
|
||||
}
|
||||
|
||||
/// Deallocates a [HardResetCommand].
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_hard_reset_free(
|
||||
command: NonNull<ClearCommand>,
|
||||
|
@ -48,6 +44,7 @@ pub unsafe extern "C" fn sp_cmd_fade_out_new() -> NonNull<FadeOutCommand> {
|
|||
heap_move_nonnull(FadeOutCommand)
|
||||
}
|
||||
|
||||
/// Deallocates a [FadeOutCommand].
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_fade_out_free(command: NonNull<ClearCommand>) {
|
||||
unsafe { heap_drop(command) }
|
||||
|
|
|
@ -4,6 +4,11 @@ use crate::mem::{
|
|||
use servicepoint::{BitmapCommand, CharGrid, CharGridCommand, Origin, Packet};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
/// Show UTF-8 encoded text on the screen.
|
||||
///
|
||||
/// The passed [CharGrid] gets consumed.
|
||||
///
|
||||
/// Returns: a new [CharGridCommand] instance.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_char_grid_new(
|
||||
grid: NonNull<CharGrid>,
|
||||
|
@ -16,6 +21,8 @@ pub unsafe extern "C" fn sp_cmd_char_grid_new(
|
|||
})
|
||||
}
|
||||
|
||||
/// Moves the provided [CharGrid] into a new [CharGridCommand],
|
||||
/// leaving other fields as their default values.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_char_grid_from_grid(
|
||||
grid: NonNull<CharGrid>,
|
||||
|
@ -30,6 +37,9 @@ pub unsafe extern "C" fn sp_cmd_char_grid_into_packet(
|
|||
heap_move_ok(unsafe { heap_remove(command) }.try_into())
|
||||
}
|
||||
|
||||
/// Clones an [CharGridCommand] instance.
|
||||
///
|
||||
/// returns: a new [CharGridCommand] instance.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_char_grid_clone(
|
||||
command: NonNull<CharGridCommand>,
|
||||
|
@ -37,6 +47,7 @@ pub unsafe extern "C" fn sp_cmd_char_grid_clone(
|
|||
unsafe { heap_clone(command) }
|
||||
}
|
||||
|
||||
/// Deallocates a [BitmapCommand].
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_char_grid_free(
|
||||
command: NonNull<BitmapCommand>,
|
||||
|
|
|
@ -6,6 +6,11 @@ use servicepoint::{
|
|||
};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
/// Show text on the screen.
|
||||
///
|
||||
/// The text is sent in the form of a 2D grid of [CP-437] encoded characters.
|
||||
///
|
||||
/// The origin is relative to the top-left of the display.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_cp437_grid_new(
|
||||
grid: NonNull<Cp437Grid>,
|
||||
|
@ -18,6 +23,8 @@ pub unsafe extern "C" fn sp_cmd_cp437_grid_new(
|
|||
})
|
||||
}
|
||||
|
||||
/// Moves the provided [Cp437Grid] into a new [Cp437GridCommand],
|
||||
/// leaving other fields as their default values.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_cp437_grid_from_grid(
|
||||
grid: NonNull<Cp437Grid>,
|
||||
|
@ -32,6 +39,9 @@ pub unsafe extern "C" fn sp_cmd_cp437_grid_into_packet(
|
|||
heap_move_ok(unsafe { heap_remove(command) }.try_into())
|
||||
}
|
||||
|
||||
/// Clones an [Cp437GridCommand] instance.
|
||||
///
|
||||
/// returns: a new [Cp437GridCommand] instance.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_cp437_grid_clone(
|
||||
command: NonNull<Cp437GridCommand>,
|
||||
|
@ -39,6 +49,7 @@ pub unsafe extern "C" fn sp_cmd_cp437_grid_clone(
|
|||
unsafe { heap_clone(command) }
|
||||
}
|
||||
|
||||
/// Deallocates a [Cp437GridCommand].
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_cp437_grid_free(
|
||||
command: NonNull<BitmapCommand>,
|
||||
|
@ -59,6 +70,12 @@ pub unsafe extern "C" fn sp_cmd_cp437_grid_set(
|
|||
}
|
||||
}
|
||||
|
||||
/// Show text on the screen.
|
||||
///
|
||||
/// The text is sent in the form of a 2D grid of [CP-437] encoded characters.
|
||||
/// For sending UTF-8 encoded characters, see [servicepoint::CharGridCommand].
|
||||
///
|
||||
/// [CP-437]: https://en.wikipedia.org/wiki/Code_page_437
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_cp437_grid_get(
|
||||
mut command: NonNull<Cp437GridCommand>,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use crate::mem::{
|
||||
heap_clone, heap_drop, heap_move_nonnull, heap_move_ok, heap_remove,
|
||||
heap_clone, heap_drop, heap_move, heap_move_nonnull, heap_move_ok,
|
||||
heap_remove,
|
||||
};
|
||||
use servicepoint::{
|
||||
BitVecCommand, BitmapCommand, BrightnessGridCommand, CharGridCommand,
|
||||
|
@ -229,7 +230,7 @@ pub unsafe extern "C" fn sp_cmd_generic_clone(command: SPCommand) -> SPCommand {
|
|||
pub unsafe extern "C" fn sp_cmd_generic_free(command: SPCommand) {
|
||||
unsafe {
|
||||
match command.tag {
|
||||
CommandTag::Invalid => return,
|
||||
CommandTag::Invalid => (),
|
||||
CommandTag::Bitmap => heap_drop(command.data.bitmap),
|
||||
CommandTag::BitVec => heap_drop(command.data.bitvec),
|
||||
CommandTag::BrightnessGrid => {
|
||||
|
@ -273,20 +274,20 @@ pub unsafe extern "C" fn sp_cmd_generic_into_packet(
|
|||
CommandTag::Cp437Grid => heap_move_ok(unsafe {
|
||||
heap_remove(command.data.cp437_grid).try_into()
|
||||
}),
|
||||
CommandTag::GlobalBrightness => heap_move_ok(unsafe {
|
||||
heap_remove(command.data.global_brightness).try_into()
|
||||
CommandTag::GlobalBrightness => heap_move(unsafe {
|
||||
heap_remove(command.data.global_brightness).into()
|
||||
}),
|
||||
CommandTag::Clear => {
|
||||
heap_move_ok(unsafe { heap_remove(command.data.clear).try_into() })
|
||||
heap_move(unsafe { heap_remove(command.data.clear).into() })
|
||||
}
|
||||
CommandTag::HardReset => {
|
||||
heap_move(unsafe { heap_remove(command.data.hard_reset).into() })
|
||||
}
|
||||
CommandTag::FadeOut => {
|
||||
heap_move(unsafe { heap_remove(command.data.fade_out).into() })
|
||||
}
|
||||
CommandTag::BitmapLegacy => {
|
||||
heap_move(unsafe { heap_remove(command.data.bitmap_legacy).into() })
|
||||
}
|
||||
CommandTag::HardReset => heap_move_ok(unsafe {
|
||||
heap_remove(command.data.hard_reset).try_into()
|
||||
}),
|
||||
CommandTag::FadeOut => heap_move_ok(unsafe {
|
||||
heap_remove(command.data.fade_out).try_into()
|
||||
}),
|
||||
CommandTag::BitmapLegacy => heap_move_ok(unsafe {
|
||||
heap_remove(command.data.bitmap_legacy).try_into()
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
use crate::mem::{
|
||||
heap_clone, heap_drop, heap_move_nonnull, heap_move_ok, heap_remove,
|
||||
};
|
||||
use crate::mem::{heap_clone, heap_drop, heap_move_nonnull, heap_remove};
|
||||
use servicepoint::{
|
||||
BitmapCommand, Brightness, GlobalBrightnessCommand, Packet,
|
||||
};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
/// Set the brightness of all tiles to the same value.
|
||||
///
|
||||
/// Returns: a new [GlobalBrightnessCommand] instance.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_brightness_global_new(
|
||||
brightness: Brightness,
|
||||
|
@ -16,10 +17,13 @@ pub unsafe extern "C" fn sp_cmd_brightness_global_new(
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_brightness_global_into_packet(
|
||||
command: NonNull<GlobalBrightnessCommand>,
|
||||
) -> *mut Packet {
|
||||
heap_move_ok(unsafe { heap_remove(command) }.try_into())
|
||||
) -> NonNull<Packet> {
|
||||
heap_move_nonnull(unsafe { heap_remove(command) }.into())
|
||||
}
|
||||
|
||||
/// Clones an [GlobalBrightnessCommand] instance.
|
||||
///
|
||||
/// returns: a new [GlobalBrightnessCommand] instance.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_cmd_brightness_global_clone(
|
||||
command: NonNull<GlobalBrightnessCommand>,
|
||||
|
|
|
@ -25,10 +25,14 @@
|
|||
//! }
|
||||
//! ```
|
||||
|
||||
/// Functions related to commands.
|
||||
pub mod commands;
|
||||
/// Functions related to [servicepoint::Bitmap], [servicepoint::CharGrid] and friends.
|
||||
pub mod containers;
|
||||
pub mod mem;
|
||||
pub(crate) mod mem;
|
||||
/// Functions related to [Packet].
|
||||
pub mod packet;
|
||||
/// Functions related to [UdpSocket].
|
||||
pub mod udp;
|
||||
|
||||
use std::time::Duration;
|
||||
|
|
|
@ -79,6 +79,8 @@ pub unsafe extern "C" fn sp_packet_serialize_to(
|
|||
}
|
||||
|
||||
/// Clones a [Packet].
|
||||
///
|
||||
/// returns: a new [Packet] instance.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn sp_packet_clone(
|
||||
packet: NonNull<Packet>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue