54 lines
1.7 KiB
Rust
54 lines
1.7 KiB
Rust
use crate::{
|
|
commands::wrap_origin_accessors,
|
|
macros::{wrap_clone, wrap_fields, wrap_free, wrap_functions},
|
|
mem::{heap_move_nonnull, heap_move_ok, heap_remove},
|
|
};
|
|
use servicepoint::{BrightnessGrid, BrightnessGridCommand, Origin, Packet};
|
|
use std::ptr::NonNull;
|
|
|
|
wrap_clone!(sp_cmd_brightness_grid::BrightnessGridCommand);
|
|
wrap_free!(sp_cmd_brightness_grid::BrightnessGridCommand);
|
|
|
|
wrap_fields!(sp_cmd_brightness_grid::BrightnessGridCommand;
|
|
prop grid: BrightnessGrid { mut get(); move set(grid); };
|
|
);
|
|
|
|
wrap_origin_accessors!(sp_cmd_brightness_grid::BrightnessGridCommand);
|
|
|
|
wrap_functions!(sp_cmd_brightness_grid;
|
|
|
|
/// Set the brightness of individual tiles in a rectangular area of the display.
|
|
///
|
|
/// The passed [BrightnessGrid] gets consumed.
|
|
///
|
|
/// Returns: a new [BrightnessGridCommand] instance.
|
|
fn new(
|
|
grid: NonNull<BrightnessGrid>,
|
|
origin_x: usize,
|
|
origin_y: usize,
|
|
) -> NonNull<BrightnessGridCommand> {
|
|
heap_move_nonnull(BrightnessGridCommand {
|
|
grid: unsafe { heap_remove(grid) },
|
|
origin: Origin::new(origin_x, origin_y),
|
|
})
|
|
}
|
|
|
|
/// Moves the provided [BrightnessGrid] into a new [BrightnessGridCommand],
|
|
/// leaving other fields as their default values.
|
|
fn from_grid(
|
|
grid: NonNull<BrightnessGrid>,
|
|
) -> NonNull<BrightnessGridCommand> {
|
|
heap_move_nonnull(unsafe { heap_remove(grid) }.into())
|
|
}
|
|
|
|
/// Tries to turn a [BrightnessGridCommand] into a [Packet].
|
|
///
|
|
/// Returns: NULL or a [Packet] containing the command.
|
|
fn into_packet(
|
|
command: NonNull<BrightnessGridCommand>,
|
|
) -> *mut Packet {
|
|
heap_move_ok(unsafe { heap_remove(command) }.try_into())
|
|
}
|
|
|
|
);
|