2024-10-13 18:12:55 +02:00
|
|
|
//! C functions for interacting with [SPCommand]s
|
2024-05-28 22:23:21 +02:00
|
|
|
//!
|
|
|
|
//! prefix `sp_command_`
|
|
|
|
|
2024-05-26 13:15:11 +02:00
|
|
|
use std::ptr::null_mut;
|
|
|
|
|
2024-10-14 22:07:13 +02:00
|
|
|
use servicepoint::{Brightness, Origin};
|
2024-05-26 13:15:11 +02:00
|
|
|
|
2024-09-07 12:23:32 +02:00
|
|
|
use crate::{
|
2024-10-15 21:33:32 +02:00
|
|
|
SPBitVec, SPBitmap, SPBrightnessGrid, SPCompressionCode, SPCp437Grid,
|
|
|
|
SPPacket,
|
2024-09-07 12:23:32 +02:00
|
|
|
};
|
2024-06-03 21:08:26 +02:00
|
|
|
|
2024-08-29 22:02:53 +02:00
|
|
|
/// A low-level display command.
|
|
|
|
///
|
|
|
|
/// This struct and associated functions implement the UDP protocol for the display.
|
|
|
|
///
|
2024-10-13 18:56:29 +02:00
|
|
|
/// To send a [SPCommand], use a [SPConnection].
|
2024-09-05 21:15:53 +02:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```C
|
2024-09-07 14:44:25 +02:00
|
|
|
/// sp_connection_send_command(connection, sp_command_clear());
|
|
|
|
/// sp_connection_send_command(connection, sp_command_brightness(5));
|
2024-09-05 21:15:53 +02:00
|
|
|
/// ```
|
|
|
|
pub struct SPCommand(pub(crate) servicepoint::Command);
|
2024-08-29 20:39:42 +02:00
|
|
|
|
2024-09-05 21:15:53 +02:00
|
|
|
impl Clone for SPCommand {
|
2024-08-29 20:39:42 +02:00
|
|
|
fn clone(&self) -> Self {
|
2024-09-05 21:15:53 +02:00
|
|
|
SPCommand(self.0.clone())
|
2024-08-29 20:39:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-13 18:56:29 +02:00
|
|
|
/// Tries to turn a [SPPacket] into a [SPCommand].
|
2024-09-07 14:44:25 +02:00
|
|
|
///
|
|
|
|
/// The packet is deallocated in the process.
|
2024-05-26 13:15:11 +02:00
|
|
|
///
|
2024-10-13 18:56:29 +02:00
|
|
|
/// Returns: pointer to new [SPCommand] instance or NULL if parsing failed.
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// - when `packet` is NULL
|
2024-05-28 21:25:59 +02:00
|
|
|
///
|
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// The caller has to make sure that:
|
|
|
|
///
|
2024-10-13 18:56:29 +02:00
|
|
|
/// - [SPPacket] points to a valid instance of [SPPacket]
|
|
|
|
/// - [SPPacket] is not used concurrently or after this call
|
2024-05-28 21:25:59 +02:00
|
|
|
/// - the result is checked for NULL
|
2024-10-13 18:12:55 +02:00
|
|
|
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
|
2024-09-07 14:11:15 +02:00
|
|
|
/// by explicitly calling `sp_command_free`.
|
2024-05-26 13:15:11 +02:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn sp_command_try_from_packet(
|
2024-09-05 21:15:53 +02:00
|
|
|
packet: *mut SPPacket,
|
|
|
|
) -> *mut SPCommand {
|
2024-05-26 13:15:11 +02:00
|
|
|
let packet = *Box::from_raw(packet);
|
2024-09-05 21:15:53 +02:00
|
|
|
match servicepoint::Command::try_from(packet.0) {
|
2024-05-26 13:15:11 +02:00
|
|
|
Err(_) => null_mut(),
|
2024-09-05 21:15:53 +02:00
|
|
|
Ok(command) => Box::into_raw(Box::new(SPCommand(command))),
|
2024-05-26 13:15:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-13 18:12:55 +02:00
|
|
|
/// Clones a [SPCommand] instance.
|
2024-05-28 21:25:59 +02:00
|
|
|
///
|
2024-10-13 18:56:29 +02:00
|
|
|
/// returns: new [SPCommand] instance. Will never return NULL.
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// - when `command` is NULL
|
|
|
|
///
|
2024-05-28 21:25:59 +02:00
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// The caller has to make sure that:
|
|
|
|
///
|
2024-10-13 18:12:55 +02:00
|
|
|
/// - `command` points to a valid instance of [SPCommand]
|
2024-09-07 15:06:11 +02:00
|
|
|
/// - `command` is not written to concurrently
|
2024-10-13 18:12:55 +02:00
|
|
|
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
|
2024-09-07 14:11:15 +02:00
|
|
|
/// by explicitly calling `sp_command_free`.
|
2024-05-26 13:15:11 +02:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn sp_command_clone(
|
2024-09-07 15:06:11 +02:00
|
|
|
command: *const SPCommand,
|
2024-09-05 21:15:53 +02:00
|
|
|
) -> *mut SPCommand {
|
2024-10-13 18:56:29 +02:00
|
|
|
assert!(!command.is_null());
|
|
|
|
let result = Box::into_raw(Box::new((*command).clone()));
|
|
|
|
assert!(!result.is_null());
|
|
|
|
result
|
2024-05-26 13:15:11 +02:00
|
|
|
}
|
|
|
|
|
2024-09-07 14:44:25 +02:00
|
|
|
/// Set all pixels to the off state.
|
|
|
|
///
|
|
|
|
/// Does not affect brightness.
|
2024-05-28 21:25:59 +02:00
|
|
|
///
|
2024-10-13 18:56:29 +02:00
|
|
|
/// Returns: a new [Command::Clear] instance. Will never return NULL.
|
2024-09-06 20:10:14 +02:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```C
|
2024-09-07 14:44:25 +02:00
|
|
|
/// sp_connection_send_command(connection, sp_command_clear());
|
2024-09-06 20:10:14 +02:00
|
|
|
/// ```
|
|
|
|
///
|
2024-05-28 21:25:59 +02:00
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// The caller has to make sure that:
|
|
|
|
///
|
2024-10-13 18:12:55 +02:00
|
|
|
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
|
2024-09-07 14:11:15 +02:00
|
|
|
/// by explicitly calling `sp_command_free`.
|
2024-05-26 13:15:11 +02:00
|
|
|
#[no_mangle]
|
2024-09-05 21:15:53 +02:00
|
|
|
pub unsafe extern "C" fn sp_command_clear() -> *mut SPCommand {
|
2024-10-15 21:33:32 +02:00
|
|
|
let result =
|
|
|
|
Box::into_raw(Box::new(SPCommand(servicepoint::Command::Clear)));
|
2024-10-13 18:56:29 +02:00
|
|
|
assert!(!result.is_null());
|
|
|
|
result
|
2024-05-26 13:15:11 +02:00
|
|
|
}
|
|
|
|
|
2024-09-06 20:10:14 +02:00
|
|
|
/// Kills the udp daemon on the display, which usually results in a restart.
|
2024-09-07 14:44:25 +02:00
|
|
|
///
|
2024-09-06 20:10:14 +02:00
|
|
|
/// Please do not send this in your normal program flow.
|
|
|
|
///
|
2024-10-13 18:56:29 +02:00
|
|
|
/// Returns: a new [Command::HardReset] instance. Will never return NULL.
|
2024-09-07 14:44:25 +02:00
|
|
|
///
|
2024-05-28 21:25:59 +02:00
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// The caller has to make sure that:
|
|
|
|
///
|
2024-10-13 18:12:55 +02:00
|
|
|
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
|
2024-09-07 14:11:15 +02:00
|
|
|
/// by explicitly calling `sp_command_free`.
|
2024-05-26 13:15:11 +02:00
|
|
|
#[no_mangle]
|
2024-09-05 21:15:53 +02:00
|
|
|
pub unsafe extern "C" fn sp_command_hard_reset() -> *mut SPCommand {
|
2024-10-15 21:33:32 +02:00
|
|
|
let result =
|
|
|
|
Box::into_raw(Box::new(SPCommand(servicepoint::Command::HardReset)));
|
2024-10-13 18:56:29 +02:00
|
|
|
assert!(!result.is_null());
|
|
|
|
result
|
2024-05-26 13:15:11 +02:00
|
|
|
}
|
|
|
|
|
2024-09-07 14:44:25 +02:00
|
|
|
/// A yet-to-be-tested command.
|
|
|
|
///
|
|
|
|
/// Returns: a new `Command::FadeOut` instance. Will never return NULL.
|
2024-05-28 21:25:59 +02:00
|
|
|
///
|
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// The caller has to make sure that:
|
|
|
|
///
|
2024-10-13 18:12:55 +02:00
|
|
|
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
|
2024-09-07 14:11:15 +02:00
|
|
|
/// by explicitly calling `sp_command_free`.
|
2024-05-26 13:15:11 +02:00
|
|
|
#[no_mangle]
|
2024-09-05 21:15:53 +02:00
|
|
|
pub unsafe extern "C" fn sp_command_fade_out() -> *mut SPCommand {
|
2024-10-15 21:33:32 +02:00
|
|
|
let result =
|
|
|
|
Box::into_raw(Box::new(SPCommand(servicepoint::Command::FadeOut)));
|
2024-10-13 18:56:29 +02:00
|
|
|
assert!(!result.is_null());
|
|
|
|
result
|
2024-05-26 13:15:11 +02:00
|
|
|
}
|
|
|
|
|
2024-09-07 14:44:25 +02:00
|
|
|
/// Set the brightness of all tiles to the same value.
|
|
|
|
///
|
2024-10-13 18:56:29 +02:00
|
|
|
/// Returns: a new [Command::Brightness] instance. Will never return NULL.
|
2024-06-23 13:00:13 +02:00
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// - When the provided brightness value is out of range (0-11).
|
2024-05-28 21:25:59 +02:00
|
|
|
///
|
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// The caller has to make sure that:
|
|
|
|
///
|
2024-10-13 18:12:55 +02:00
|
|
|
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
|
2024-09-07 14:11:15 +02:00
|
|
|
/// by explicitly calling `sp_command_free`.
|
2024-05-26 13:15:11 +02:00
|
|
|
#[no_mangle]
|
2024-08-29 20:39:42 +02:00
|
|
|
pub unsafe extern "C" fn sp_command_brightness(
|
|
|
|
brightness: u8,
|
2024-09-05 21:15:53 +02:00
|
|
|
) -> *mut SPCommand {
|
2024-06-23 13:38:46 +02:00
|
|
|
let brightness =
|
|
|
|
Brightness::try_from(brightness).expect("invalid brightness");
|
2024-10-15 21:33:32 +02:00
|
|
|
let result = Box::into_raw(Box::new(SPCommand(
|
|
|
|
servicepoint::Command::Brightness(brightness),
|
|
|
|
)));
|
2024-10-13 18:56:29 +02:00
|
|
|
assert!(!result.is_null());
|
|
|
|
result
|
2024-05-26 13:15:11 +02:00
|
|
|
}
|
|
|
|
|
2024-09-07 14:44:25 +02:00
|
|
|
/// Set the brightness of individual tiles in a rectangular area of the display.
|
|
|
|
///
|
2024-10-13 18:22:26 +02:00
|
|
|
/// The passed [SPBrightnessGrid] gets consumed.
|
2024-05-28 21:25:59 +02:00
|
|
|
///
|
2024-10-13 18:56:29 +02:00
|
|
|
/// Returns: a new [Command::CharBrightness] instance. Will never return NULL.
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// - when `grid` is NULL
|
2024-09-06 20:10:14 +02:00
|
|
|
///
|
2024-05-28 21:25:59 +02:00
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// The caller has to make sure that:
|
|
|
|
///
|
2024-10-13 18:22:26 +02:00
|
|
|
/// - `grid` points to a valid instance of [SPBrightnessGrid]
|
2024-09-05 21:15:53 +02:00
|
|
|
/// - `grid` is not used concurrently or after this call
|
2024-10-13 18:12:55 +02:00
|
|
|
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
|
2024-09-07 14:11:15 +02:00
|
|
|
/// by explicitly calling `sp_command_free`.
|
2024-05-26 13:15:11 +02:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn sp_command_char_brightness(
|
|
|
|
x: usize,
|
|
|
|
y: usize,
|
2024-09-05 21:15:53 +02:00
|
|
|
grid: *mut SPBrightnessGrid,
|
|
|
|
) -> *mut SPCommand {
|
2024-10-13 18:56:29 +02:00
|
|
|
assert!(!grid.is_null());
|
2024-09-05 21:15:53 +02:00
|
|
|
let byte_grid = *Box::from_raw(grid);
|
2024-10-15 21:33:32 +02:00
|
|
|
let result = Box::into_raw(Box::new(SPCommand(
|
|
|
|
servicepoint::Command::CharBrightness(Origin::new(x, y), byte_grid.0),
|
|
|
|
)));
|
2024-10-13 18:56:29 +02:00
|
|
|
assert!(!result.is_null());
|
|
|
|
result
|
2024-05-26 13:15:11 +02:00
|
|
|
}
|
|
|
|
|
2024-09-06 20:10:14 +02:00
|
|
|
/// Set pixel data starting at the pixel offset on screen.
|
|
|
|
///
|
|
|
|
/// The screen will continuously overwrite more pixel data without regarding the offset, meaning
|
|
|
|
/// once the starting row is full, overwriting will continue on column 0.
|
|
|
|
///
|
2024-10-13 18:12:55 +02:00
|
|
|
/// The contained [SPBitVec] is always uncompressed.
|
2024-09-06 20:10:14 +02:00
|
|
|
///
|
2024-10-13 18:12:55 +02:00
|
|
|
/// The passed [SPBitVec] gets consumed.
|
2024-09-07 14:44:25 +02:00
|
|
|
///
|
2024-10-13 18:56:29 +02:00
|
|
|
/// Returns: a new [Command::BitmapLinear] instance. Will never return NULL.
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// - when `bit_vec` is null
|
|
|
|
/// - when `compression_code` is not a valid value
|
2024-09-07 14:44:25 +02:00
|
|
|
///
|
2024-05-28 21:25:59 +02:00
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// The caller has to make sure that:
|
|
|
|
///
|
2024-10-13 18:12:55 +02:00
|
|
|
/// - `bit_vec` points to a valid instance of [SPBitVec]
|
2024-05-28 21:25:59 +02:00
|
|
|
/// - `bit_vec` is not used concurrently or after this call
|
|
|
|
/// - `compression` matches one of the allowed enum values
|
2024-10-13 18:12:55 +02:00
|
|
|
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
|
2024-09-07 14:11:15 +02:00
|
|
|
/// by explicitly calling `sp_command_free`.
|
2024-05-26 13:15:11 +02:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn sp_command_bitmap_linear(
|
2024-09-07 12:23:32 +02:00
|
|
|
offset: usize,
|
2024-09-05 21:15:53 +02:00
|
|
|
bit_vec: *mut SPBitVec,
|
|
|
|
compression: SPCompressionCode,
|
|
|
|
) -> *mut SPCommand {
|
2024-10-13 18:56:29 +02:00
|
|
|
assert!(!bit_vec.is_null());
|
2024-05-26 13:15:11 +02:00
|
|
|
let bit_vec = *Box::from_raw(bit_vec);
|
2024-10-15 21:33:32 +02:00
|
|
|
let result = Box::into_raw(Box::new(SPCommand(
|
|
|
|
servicepoint::Command::BitmapLinear(
|
|
|
|
offset,
|
|
|
|
bit_vec.into(),
|
|
|
|
compression.try_into().expect("invalid compression code"),
|
|
|
|
),
|
|
|
|
)));
|
2024-10-13 18:56:29 +02:00
|
|
|
assert!(!result.is_null());
|
|
|
|
result
|
2024-05-26 13:15:11 +02:00
|
|
|
}
|
|
|
|
|
2024-09-06 20:10:14 +02:00
|
|
|
/// Set pixel data according to an and-mask starting at the offset.
|
|
|
|
///
|
|
|
|
/// The screen will continuously overwrite more pixel data without regarding the offset, meaning
|
|
|
|
/// once the starting row is full, overwriting will continue on column 0.
|
|
|
|
///
|
2024-10-13 18:12:55 +02:00
|
|
|
/// The contained [SPBitVec] is always uncompressed.
|
2024-09-06 20:10:14 +02:00
|
|
|
///
|
2024-10-13 18:12:55 +02:00
|
|
|
/// The passed [SPBitVec] gets consumed.
|
2024-09-07 14:44:25 +02:00
|
|
|
///
|
2024-10-13 18:56:29 +02:00
|
|
|
/// Returns: a new [Command::BitmapLinearAnd] instance. Will never return NULL.
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// - when `bit_vec` is null
|
|
|
|
/// - when `compression_code` is not a valid value
|
2024-09-07 14:44:25 +02:00
|
|
|
///
|
2024-05-28 21:25:59 +02:00
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// The caller has to make sure that:
|
|
|
|
///
|
2024-10-13 18:12:55 +02:00
|
|
|
/// - `bit_vec` points to a valid instance of [SPBitVec]
|
2024-05-28 21:25:59 +02:00
|
|
|
/// - `bit_vec` is not used concurrently or after this call
|
|
|
|
/// - `compression` matches one of the allowed enum values
|
2024-10-13 18:12:55 +02:00
|
|
|
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
|
2024-09-07 14:11:15 +02:00
|
|
|
/// by explicitly calling `sp_command_free`.
|
2024-05-26 13:15:11 +02:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn sp_command_bitmap_linear_and(
|
2024-09-07 12:23:32 +02:00
|
|
|
offset: usize,
|
2024-09-05 21:15:53 +02:00
|
|
|
bit_vec: *mut SPBitVec,
|
|
|
|
compression: SPCompressionCode,
|
|
|
|
) -> *mut SPCommand {
|
2024-10-13 18:56:29 +02:00
|
|
|
assert!(!bit_vec.is_null());
|
2024-05-26 13:15:11 +02:00
|
|
|
let bit_vec = *Box::from_raw(bit_vec);
|
2024-10-15 21:33:32 +02:00
|
|
|
let result = Box::into_raw(Box::new(SPCommand(
|
|
|
|
servicepoint::Command::BitmapLinearAnd(
|
|
|
|
offset,
|
|
|
|
bit_vec.into(),
|
|
|
|
compression.try_into().expect("invalid compression code"),
|
|
|
|
),
|
|
|
|
)));
|
2024-10-13 18:56:29 +02:00
|
|
|
assert!(!result.is_null());
|
|
|
|
result
|
2024-05-26 13:15:11 +02:00
|
|
|
}
|
|
|
|
|
2024-09-06 20:10:14 +02:00
|
|
|
/// Set pixel data according to an or-mask starting at the offset.
|
|
|
|
///
|
|
|
|
/// The screen will continuously overwrite more pixel data without regarding the offset, meaning
|
|
|
|
/// once the starting row is full, overwriting will continue on column 0.
|
|
|
|
///
|
2024-10-13 18:12:55 +02:00
|
|
|
/// The contained [SPBitVec] is always uncompressed.
|
2024-09-06 20:10:14 +02:00
|
|
|
///
|
2024-10-13 18:12:55 +02:00
|
|
|
/// The passed [SPBitVec] gets consumed.
|
2024-09-07 14:44:25 +02:00
|
|
|
///
|
2024-10-13 18:56:29 +02:00
|
|
|
/// Returns: a new [Command::BitmapLinearOr] instance. Will never return NULL.
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// - when `bit_vec` is null
|
|
|
|
/// - when `compression_code` is not a valid value
|
2024-09-07 14:44:25 +02:00
|
|
|
///
|
2024-05-28 21:25:59 +02:00
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// The caller has to make sure that:
|
|
|
|
///
|
2024-10-13 18:12:55 +02:00
|
|
|
/// - `bit_vec` points to a valid instance of [SPBitVec]
|
2024-05-28 21:25:59 +02:00
|
|
|
/// - `bit_vec` is not used concurrently or after this call
|
|
|
|
/// - `compression` matches one of the allowed enum values
|
2024-10-13 18:12:55 +02:00
|
|
|
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
|
2024-09-07 14:11:15 +02:00
|
|
|
/// by explicitly calling `sp_command_free`.
|
2024-05-26 13:15:11 +02:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn sp_command_bitmap_linear_or(
|
2024-09-07 12:23:32 +02:00
|
|
|
offset: usize,
|
2024-09-05 21:15:53 +02:00
|
|
|
bit_vec: *mut SPBitVec,
|
|
|
|
compression: SPCompressionCode,
|
|
|
|
) -> *mut SPCommand {
|
2024-10-13 18:56:29 +02:00
|
|
|
assert!(!bit_vec.is_null());
|
2024-05-26 13:15:11 +02:00
|
|
|
let bit_vec = *Box::from_raw(bit_vec);
|
2024-10-15 21:33:32 +02:00
|
|
|
let result = Box::into_raw(Box::new(SPCommand(
|
|
|
|
servicepoint::Command::BitmapLinearOr(
|
|
|
|
offset,
|
|
|
|
bit_vec.into(),
|
|
|
|
compression.try_into().expect("invalid compression code"),
|
|
|
|
),
|
|
|
|
)));
|
2024-10-13 18:56:29 +02:00
|
|
|
assert!(!result.is_null());
|
|
|
|
result
|
2024-05-26 13:15:11 +02:00
|
|
|
}
|
|
|
|
|
2024-09-06 20:10:14 +02:00
|
|
|
/// Set pixel data according to a xor-mask starting at the offset.
|
|
|
|
///
|
|
|
|
/// The screen will continuously overwrite more pixel data without regarding the offset, meaning
|
|
|
|
/// once the starting row is full, overwriting will continue on column 0.
|
|
|
|
///
|
2024-10-13 18:12:55 +02:00
|
|
|
/// The contained [SPBitVec] is always uncompressed.
|
2024-09-06 20:10:14 +02:00
|
|
|
///
|
2024-10-13 18:12:55 +02:00
|
|
|
/// The passed [SPBitVec] gets consumed.
|
2024-09-07 14:44:25 +02:00
|
|
|
///
|
2024-10-13 18:56:29 +02:00
|
|
|
/// Returns: a new [Command::BitmapLinearXor] instance. Will never return NULL.
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// - when `bit_vec` is null
|
|
|
|
/// - when `compression_code` is not a valid value
|
2024-09-07 14:44:25 +02:00
|
|
|
///
|
2024-05-28 21:25:59 +02:00
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// The caller has to make sure that:
|
|
|
|
///
|
2024-10-13 18:12:55 +02:00
|
|
|
/// - `bit_vec` points to a valid instance of [SPBitVec]
|
2024-05-28 21:25:59 +02:00
|
|
|
/// - `bit_vec` is not used concurrently or after this call
|
|
|
|
/// - `compression` matches one of the allowed enum values
|
2024-10-13 18:12:55 +02:00
|
|
|
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
|
2024-09-07 14:11:15 +02:00
|
|
|
/// by explicitly calling `sp_command_free`.
|
2024-05-26 13:15:11 +02:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn sp_command_bitmap_linear_xor(
|
2024-09-07 12:23:32 +02:00
|
|
|
offset: usize,
|
2024-09-05 21:15:53 +02:00
|
|
|
bit_vec: *mut SPBitVec,
|
|
|
|
compression: SPCompressionCode,
|
|
|
|
) -> *mut SPCommand {
|
2024-10-13 18:56:29 +02:00
|
|
|
assert!(!bit_vec.is_null());
|
2024-05-26 13:15:11 +02:00
|
|
|
let bit_vec = *Box::from_raw(bit_vec);
|
2024-10-15 21:33:32 +02:00
|
|
|
let result = Box::into_raw(Box::new(SPCommand(
|
|
|
|
servicepoint::Command::BitmapLinearXor(
|
|
|
|
offset,
|
|
|
|
bit_vec.into(),
|
|
|
|
compression.try_into().expect("invalid compression code"),
|
|
|
|
),
|
|
|
|
)));
|
2024-10-13 18:56:29 +02:00
|
|
|
assert!(!result.is_null());
|
|
|
|
result
|
2024-05-26 13:15:11 +02:00
|
|
|
}
|
|
|
|
|
2024-09-06 20:10:14 +02:00
|
|
|
/// Show text on the screen.
|
|
|
|
///
|
2024-10-13 18:56:29 +02:00
|
|
|
/// The passed [SPCp437Grid] gets consumed.
|
2024-09-06 20:10:14 +02:00
|
|
|
///
|
2024-10-13 18:56:29 +02:00
|
|
|
/// Returns: a new [Command::Cp437Data] instance. Will never return NULL.
|
2024-09-07 14:44:25 +02:00
|
|
|
///
|
2024-10-13 18:56:29 +02:00
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// - when `grid` is null
|
2024-09-07 14:35:16 +02:00
|
|
|
///
|
2024-05-28 21:25:59 +02:00
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// The caller has to make sure that:
|
|
|
|
///
|
2024-10-13 18:56:29 +02:00
|
|
|
/// - `grid` points to a valid instance of [SPCp437Grid]
|
2024-09-07 14:11:15 +02:00
|
|
|
/// - `grid` is not used concurrently or after this call
|
2024-10-13 18:12:55 +02:00
|
|
|
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
|
2024-09-07 14:11:15 +02:00
|
|
|
/// by explicitly calling `sp_command_free`.
|
2024-05-26 13:15:11 +02:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn sp_command_cp437_data(
|
|
|
|
x: usize,
|
|
|
|
y: usize,
|
2024-09-07 14:11:15 +02:00
|
|
|
grid: *mut SPCp437Grid,
|
2024-09-05 21:15:53 +02:00
|
|
|
) -> *mut SPCommand {
|
2024-10-13 18:56:29 +02:00
|
|
|
assert!(!grid.is_null());
|
2024-09-07 14:11:15 +02:00
|
|
|
let grid = *Box::from_raw(grid);
|
2024-10-15 21:33:32 +02:00
|
|
|
let result = Box::into_raw(Box::new(SPCommand(
|
|
|
|
servicepoint::Command::Cp437Data(Origin::new(x, y), grid.0),
|
|
|
|
)));
|
2024-10-13 18:56:29 +02:00
|
|
|
assert!(!result.is_null());
|
|
|
|
result
|
2024-05-26 13:15:11 +02:00
|
|
|
}
|
|
|
|
|
2024-09-07 14:35:16 +02:00
|
|
|
/// Sets a window of pixels to the specified values.
|
|
|
|
///
|
2024-10-14 22:42:45 +02:00
|
|
|
/// The passed [SPBitmap] gets consumed.
|
2024-10-13 18:56:29 +02:00
|
|
|
///
|
|
|
|
/// Returns: a new [Command::BitmapLinearWin] instance. Will never return NULL.
|
|
|
|
///
|
|
|
|
/// # Panics
|
2024-09-07 14:44:25 +02:00
|
|
|
///
|
2024-10-14 22:42:45 +02:00
|
|
|
/// - when `bitmap` is null
|
2024-10-13 18:56:29 +02:00
|
|
|
/// - when `compression_code` is not a valid value
|
2024-09-06 20:10:14 +02:00
|
|
|
///
|
2024-05-28 21:25:59 +02:00
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// The caller has to make sure that:
|
|
|
|
///
|
2024-10-14 22:42:45 +02:00
|
|
|
/// - `bitmap` points to a valid instance of [SPBitmap]
|
|
|
|
/// - `bitmap` is not used concurrently or after this call
|
2024-05-28 21:25:59 +02:00
|
|
|
/// - `compression` matches one of the allowed enum values
|
2024-10-13 18:12:55 +02:00
|
|
|
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
|
2024-09-07 14:11:15 +02:00
|
|
|
/// by explicitly calling `sp_command_free`.
|
2024-05-26 13:15:11 +02:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn sp_command_bitmap_linear_win(
|
|
|
|
x: usize,
|
|
|
|
y: usize,
|
2024-10-14 22:42:45 +02:00
|
|
|
bitmap: *mut SPBitmap,
|
2024-09-05 21:15:53 +02:00
|
|
|
compression_code: SPCompressionCode,
|
|
|
|
) -> *mut SPCommand {
|
2024-10-14 22:42:45 +02:00
|
|
|
assert!(!bitmap.is_null());
|
|
|
|
let byte_grid = (*Box::from_raw(bitmap)).0;
|
2024-10-15 21:33:32 +02:00
|
|
|
let result = Box::into_raw(Box::new(SPCommand(
|
|
|
|
servicepoint::Command::BitmapLinearWin(
|
|
|
|
Origin::new(x, y),
|
|
|
|
byte_grid,
|
|
|
|
compression_code
|
|
|
|
.try_into()
|
|
|
|
.expect("invalid compression code"),
|
|
|
|
),
|
|
|
|
)));
|
2024-10-13 18:56:29 +02:00
|
|
|
assert!(!result.is_null());
|
|
|
|
result
|
2024-05-26 13:15:11 +02:00
|
|
|
}
|
|
|
|
|
2024-10-13 18:12:55 +02:00
|
|
|
/// Deallocates a [SPCommand].
|
2024-05-28 21:25:59 +02:00
|
|
|
///
|
2024-09-06 20:10:14 +02:00
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```C
|
|
|
|
/// SPCommand c = sp_command_clear();
|
2024-09-07 14:11:15 +02:00
|
|
|
/// sp_command_free(c);
|
2024-09-06 20:10:14 +02:00
|
|
|
/// ```
|
|
|
|
///
|
2024-10-13 18:56:29 +02:00
|
|
|
/// # Panics
|
|
|
|
///
|
|
|
|
/// - when `command` is NULL
|
|
|
|
///
|
2024-05-28 21:25:59 +02:00
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// The caller has to make sure that:
|
|
|
|
///
|
2024-10-13 18:12:55 +02:00
|
|
|
/// - `command` points to a valid [SPCommand]
|
2024-09-07 15:06:11 +02:00
|
|
|
/// - `command` is not used concurrently or after this call
|
2024-10-13 18:56:29 +02:00
|
|
|
/// - `command` was not passed to another consuming function, e.g. to create a [SPPacket]
|
2024-05-26 13:15:11 +02:00
|
|
|
#[no_mangle]
|
2024-09-07 15:06:11 +02:00
|
|
|
pub unsafe extern "C" fn sp_command_free(command: *mut SPCommand) {
|
2024-10-13 18:56:29 +02:00
|
|
|
assert!(!command.is_null());
|
2024-09-07 15:06:11 +02:00
|
|
|
_ = Box::from_raw(command);
|
2024-05-26 13:15:11 +02:00
|
|
|
}
|