generic wrap
This commit is contained in:
parent
5beea6151a
commit
c65b735f57
16 changed files with 828 additions and 795 deletions
|
@ -1,43 +1,43 @@
|
|||
use crate::{
|
||||
commands::{wrap_command, wrap_origin_accessors},
|
||||
macros::{wrap, wrap_functions},
|
||||
macros::wrap,
|
||||
};
|
||||
use servicepoint::{Bitmap, BitmapCommand, CompressionCode, Origin};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
wrap_command!(Bitmap);
|
||||
|
||||
wrap!(BitmapCommand;
|
||||
prop bitmap: Bitmap { get mut; set move; };
|
||||
prop compression: CompressionCode { get; set; };
|
||||
);
|
||||
|
||||
wrap_origin_accessors!(BitmapCommand);
|
||||
|
||||
wrap_functions!(associate BitmapCommand;
|
||||
/// Sets a window of pixels to the specified values.
|
||||
///
|
||||
/// The passed [Bitmap] gets consumed.
|
||||
///
|
||||
/// Returns: a new [BitmapCommand] instance.
|
||||
fn new(
|
||||
bitmap: move NonNull<Bitmap>,
|
||||
origin_x: val usize,
|
||||
origin_y: val usize,
|
||||
compression: val CompressionCode,
|
||||
) -> move NonNull<BitmapCommand> {
|
||||
BitmapCommand {
|
||||
bitmap,
|
||||
origin: Origin::new(origin_x, origin_y),
|
||||
compression,
|
||||
}
|
||||
};
|
||||
wrap! {
|
||||
BitmapCommand {
|
||||
properties:
|
||||
prop bitmap: Bitmap { get mut; set move; };
|
||||
prop compression: CompressionCode { get; set; };
|
||||
functions:
|
||||
/// Sets a window of pixels to the specified values.
|
||||
///
|
||||
/// The passed [Bitmap] gets consumed.
|
||||
///
|
||||
/// Returns: a new [BitmapCommand] instance.
|
||||
fn new(
|
||||
bitmap: move NonNull<Bitmap>,
|
||||
origin_x: val usize,
|
||||
origin_y: val usize,
|
||||
compression: val CompressionCode,
|
||||
) -> move NonNull<BitmapCommand> {
|
||||
BitmapCommand {
|
||||
bitmap,
|
||||
origin: Origin::new(origin_x, origin_y),
|
||||
compression,
|
||||
}
|
||||
};
|
||||
|
||||
/// Move the provided [Bitmap] into a new [BitmapCommand],
|
||||
/// leaving other fields as their default values.
|
||||
///
|
||||
/// Rust equivalent: `BitmapCommand::from(bitmap)`
|
||||
fn from_bitmap(bitmap: move NonNull<Bitmap>) -> move NonNull<BitmapCommand> {
|
||||
bitmap.into()
|
||||
};
|
||||
);
|
||||
/// Move the provided [Bitmap] into a new [BitmapCommand],
|
||||
/// leaving other fields as their default values.
|
||||
///
|
||||
/// Rust equivalent: `BitmapCommand::from(bitmap)`
|
||||
fn from_bitmap(bitmap: move NonNull<Bitmap>) -> move NonNull<BitmapCommand> {
|
||||
bitmap.into()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
use crate::{
|
||||
commands::wrap_command,
|
||||
macros::{wrap, wrap_functions},
|
||||
};
|
||||
use crate::{commands::wrap_command, macros::wrap};
|
||||
use servicepoint::{
|
||||
BinaryOperation, BitVecCommand, CompressionCode, DisplayBitVec, Offset,
|
||||
};
|
||||
|
@ -9,37 +6,38 @@ use std::ptr::NonNull;
|
|||
|
||||
wrap_command!(BitVec);
|
||||
|
||||
wrap!(BitVecCommand;
|
||||
prop bitvec: DisplayBitVec { get mut; set move; };
|
||||
prop offset: Offset { get; set; };
|
||||
prop operation: BinaryOperation { get; set; };
|
||||
prop compression: CompressionCode { get; set; };
|
||||
);
|
||||
|
||||
wrap_functions!(associate BitVecCommand;
|
||||
/// 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.
|
||||
///
|
||||
/// The [`BinaryOperation`] will be applied on the display comparing old and sent bit.
|
||||
///
|
||||
/// `new_bit = old_bit op sent_bit`
|
||||
///
|
||||
/// For example, [`BinaryOperation::Or`] can be used to turn on some pixels without affecting other pixels.
|
||||
///
|
||||
/// The contained [`DisplayBitVec`] is always uncompressed.
|
||||
fn new(
|
||||
bitvec: move NonNull<DisplayBitVec>,
|
||||
offset: val usize,
|
||||
operation: val BinaryOperation,
|
||||
compression: val CompressionCode,
|
||||
) -> move NonNull<BitVecCommand> {
|
||||
BitVecCommand {
|
||||
bitvec,
|
||||
offset,
|
||||
operation,
|
||||
compression,
|
||||
}
|
||||
};
|
||||
wrap!(
|
||||
BitVecCommand {
|
||||
properties:
|
||||
prop bitvec: DisplayBitVec { get mut; set move; };
|
||||
prop offset: Offset { get; set; };
|
||||
prop operation: BinaryOperation { get; set; };
|
||||
prop compression: CompressionCode { get; set; };
|
||||
functions:
|
||||
/// 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.
|
||||
///
|
||||
/// The [`BinaryOperation`] will be applied on the display comparing old and sent bit.
|
||||
///
|
||||
/// `new_bit = old_bit op sent_bit`
|
||||
///
|
||||
/// For example, [`BinaryOperation::Or`] can be used to turn on some pixels without affecting other pixels.
|
||||
///
|
||||
/// The contained [`DisplayBitVec`] is always uncompressed.
|
||||
fn new(
|
||||
bitvec: move NonNull<DisplayBitVec>,
|
||||
offset: val usize,
|
||||
operation: val BinaryOperation,
|
||||
compression: val CompressionCode,
|
||||
) -> move NonNull<BitVecCommand> {
|
||||
BitVecCommand {
|
||||
bitvec,
|
||||
offset,
|
||||
operation,
|
||||
compression,
|
||||
}
|
||||
};
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1,38 +1,38 @@
|
|||
use crate::{
|
||||
commands::{wrap_command, wrap_origin_accessors},
|
||||
macros::{wrap, wrap_functions},
|
||||
macros::wrap,
|
||||
};
|
||||
use servicepoint::{BrightnessGrid, BrightnessGridCommand, Origin};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
wrap_command!(BrightnessGrid);
|
||||
|
||||
wrap!(BrightnessGridCommand;
|
||||
prop grid: BrightnessGrid { get mut; set move; };
|
||||
);
|
||||
|
||||
wrap_origin_accessors!(BrightnessGridCommand);
|
||||
|
||||
wrap_functions!(associate BrightnessGridCommand;
|
||||
/// 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: move NonNull<BrightnessGrid>,
|
||||
origin_x: val usize,
|
||||
origin_y: val usize
|
||||
) -> move NonNull<BrightnessGridCommand> {
|
||||
BrightnessGridCommand {
|
||||
grid,
|
||||
origin: Origin::new(origin_x, origin_y),
|
||||
}
|
||||
};
|
||||
wrap!(
|
||||
BrightnessGridCommand {
|
||||
properties:
|
||||
prop grid: BrightnessGrid { get mut; set move; };
|
||||
functions:
|
||||
/// 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: move NonNull<BrightnessGrid>,
|
||||
origin_x: val usize,
|
||||
origin_y: val usize
|
||||
) -> move NonNull<BrightnessGridCommand> {
|
||||
BrightnessGridCommand {
|
||||
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: move NonNull<BrightnessGrid>) -> move NonNull<BrightnessGridCommand> {
|
||||
grid.into()
|
||||
};
|
||||
/// Moves the provided [BrightnessGrid] into a new [BrightnessGridCommand],
|
||||
/// leaving other fields as their default values.
|
||||
fn from_grid(grid: move NonNull<BrightnessGrid>) -> move NonNull<BrightnessGridCommand> {
|
||||
grid.into()
|
||||
};
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{commands::wrap_command, macros::wrap_functions};
|
||||
use crate::commands::wrap_command;
|
||||
use servicepoint::{ClearCommand, FadeOutCommand, HardResetCommand};
|
||||
|
||||
macro_rules! wrap_cc_only {
|
||||
|
@ -6,14 +6,17 @@ macro_rules! wrap_cc_only {
|
|||
::paste::paste!{
|
||||
wrap_command!($command);
|
||||
|
||||
wrap_functions!(associate [< $command Command >];
|
||||
$(#[$meta])*
|
||||
///
|
||||
#[doc = " Returns: a new [`" [< $command Command >] "`] instance."]
|
||||
fn new() -> move ::core::ptr::NonNull<[< $command Command >]> {
|
||||
[< $command Command >]
|
||||
};
|
||||
);
|
||||
$crate::macros::wrap!{
|
||||
[< $command Command >] {
|
||||
functions:
|
||||
$(#[$meta])*
|
||||
///
|
||||
#[doc = " Returns: a new [`" [< $command Command >] "`] instance."]
|
||||
fn new() -> move ::core::ptr::NonNull<[< $command Command >]> {
|
||||
[< $command Command >]
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,38 +1,38 @@
|
|||
use crate::{
|
||||
commands::{wrap_command, wrap_origin_accessors},
|
||||
macros::{wrap, wrap_functions},
|
||||
macros::wrap,
|
||||
};
|
||||
use servicepoint::{CharGrid, CharGridCommand, Origin};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
wrap_command!(CharGrid);
|
||||
|
||||
wrap!(CharGridCommand;
|
||||
prop grid: CharGrid { get mut; set move; };
|
||||
);
|
||||
|
||||
wrap_origin_accessors!(CharGridCommand);
|
||||
|
||||
wrap_functions!(associate CharGridCommand;
|
||||
/// Show UTF-8 encoded text on the screen.
|
||||
///
|
||||
/// The passed [CharGrid] gets consumed.
|
||||
///
|
||||
/// Returns: a new [CharGridCommand] instance.
|
||||
fn new(
|
||||
grid: move NonNull<CharGrid>,
|
||||
origin_x: val usize,
|
||||
origin_y: val usize,
|
||||
) -> move NonNull<CharGridCommand> {
|
||||
CharGridCommand {
|
||||
grid,
|
||||
origin: Origin::new(origin_x, origin_y),
|
||||
}
|
||||
};
|
||||
wrap!(
|
||||
CharGridCommand {
|
||||
properties:
|
||||
prop grid: CharGrid { get mut; set move; };
|
||||
functions:
|
||||
/// Show UTF-8 encoded text on the screen.
|
||||
///
|
||||
/// The passed [CharGrid] gets consumed.
|
||||
///
|
||||
/// Returns: a new [CharGridCommand] instance.
|
||||
fn new(
|
||||
grid: move NonNull<CharGrid>,
|
||||
origin_x: val usize,
|
||||
origin_y: val usize,
|
||||
) -> move NonNull<CharGridCommand> {
|
||||
CharGridCommand {
|
||||
grid,
|
||||
origin: Origin::new(origin_x, origin_y),
|
||||
}
|
||||
};
|
||||
|
||||
/// Moves the provided [CharGrid] into a new [CharGridCommand],
|
||||
/// leaving other fields as their default values.
|
||||
fn from_grid(grid: move NonNull<CharGrid>) -> move NonNull<CharGridCommand> {
|
||||
grid.into()
|
||||
};
|
||||
/// Moves the provided [CharGrid] into a new [CharGridCommand],
|
||||
/// leaving other fields as their default values.
|
||||
fn from_grid(grid: move NonNull<CharGrid>) -> move NonNull<CharGridCommand> {
|
||||
grid.into()
|
||||
};
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1,38 +1,38 @@
|
|||
use crate::{
|
||||
commands::{wrap_command, wrap_origin_accessors},
|
||||
macros::{wrap, wrap_functions},
|
||||
macros::wrap,
|
||||
};
|
||||
use servicepoint::{Cp437Grid, Cp437GridCommand, Origin};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
wrap_command!(Cp437Grid);
|
||||
|
||||
wrap!(Cp437GridCommand;
|
||||
prop grid: Cp437Grid { get mut; set move; };
|
||||
);
|
||||
|
||||
wrap_origin_accessors!(Cp437GridCommand);
|
||||
|
||||
wrap_functions!(associate Cp437GridCommand;
|
||||
/// 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.
|
||||
fn new(
|
||||
grid: move NonNull<Cp437Grid>,
|
||||
origin_x: val usize,
|
||||
origin_y: val usize,
|
||||
) -> move NonNull<Cp437GridCommand> {
|
||||
Cp437GridCommand {
|
||||
grid,
|
||||
origin: Origin::new(origin_x, origin_y),
|
||||
}
|
||||
};
|
||||
wrap!(
|
||||
Cp437GridCommand {
|
||||
properties:
|
||||
prop grid: Cp437Grid { get mut; set move; };
|
||||
functions:
|
||||
/// 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.
|
||||
fn new(
|
||||
grid: move NonNull<Cp437Grid>,
|
||||
origin_x: val usize,
|
||||
origin_y: val usize,
|
||||
) -> move NonNull<Cp437GridCommand> {
|
||||
Cp437GridCommand {
|
||||
grid,
|
||||
origin: Origin::new(origin_x, origin_y),
|
||||
}
|
||||
};
|
||||
|
||||
/// Moves the provided [Cp437Grid] into a new [Cp437GridCommand],
|
||||
/// leaving other fields as their default values.
|
||||
fn from_grid(grid: move NonNull<Cp437Grid>) -> move NonNull<Cp437GridCommand> {
|
||||
grid.into()
|
||||
};
|
||||
/// Moves the provided [Cp437Grid] into a new [Cp437GridCommand],
|
||||
/// leaving other fields as their default values.
|
||||
fn from_grid(grid: move NonNull<Cp437Grid>) -> move NonNull<Cp437GridCommand> {
|
||||
grid.into()
|
||||
};
|
||||
}
|
||||
);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{
|
||||
macros::{derive_clone, derive_free, wrap, wrap_functions},
|
||||
macros::{derive_clone, derive_free, wrap},
|
||||
mem::{
|
||||
heap_clone, heap_drop, heap_move, heap_move_nonnull, heap_move_ok,
|
||||
heap_remove,
|
||||
|
@ -69,8 +69,6 @@ impl GenericCommand {
|
|||
};
|
||||
}
|
||||
|
||||
derive_clone!(GenericCommand);
|
||||
|
||||
impl Clone for GenericCommand {
|
||||
fn clone(&self) -> Self {
|
||||
unsafe {
|
||||
|
@ -144,8 +142,6 @@ impl Clone for GenericCommand {
|
|||
}
|
||||
}
|
||||
|
||||
derive_free!(GenericCommand);
|
||||
|
||||
impl Drop for GenericCommand {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
|
@ -172,122 +168,126 @@ impl Drop for GenericCommand {
|
|||
}
|
||||
}
|
||||
|
||||
wrap_functions!(associate GenericCommand;
|
||||
/// Tries to turn a [Packet] into a [GenericCommand].
|
||||
///
|
||||
/// The packet is dropped in the process.
|
||||
///
|
||||
/// Returns: pointer to new [GenericCommand] instance or NULL if parsing failed.
|
||||
fn try_from_packet(packet: move NonNull<Packet>) -> move NonNull<GenericCommand> {
|
||||
servicepoint::TypedCommand::try_from(packet)
|
||||
.map(|value| match value {
|
||||
TypedCommand::Clear(clear) => GenericCommand {
|
||||
tag: CommandTag::Clear,
|
||||
data: CommandUnion {
|
||||
clear: heap_move_nonnull(clear),
|
||||
},
|
||||
},
|
||||
TypedCommand::CharGrid(char_grid) => GenericCommand {
|
||||
tag: CommandTag::CharGrid,
|
||||
data: CommandUnion {
|
||||
char_grid: heap_move_nonnull(char_grid),
|
||||
},
|
||||
},
|
||||
TypedCommand::Cp437Grid(cp437_grid) => GenericCommand {
|
||||
tag: CommandTag::Cp437Grid,
|
||||
data: CommandUnion {
|
||||
cp437_grid: heap_move_nonnull(cp437_grid),
|
||||
},
|
||||
},
|
||||
TypedCommand::Bitmap(bitmap) => GenericCommand {
|
||||
tag: CommandTag::Bitmap,
|
||||
data: CommandUnion {
|
||||
bitmap: heap_move_nonnull(bitmap),
|
||||
},
|
||||
},
|
||||
TypedCommand::Brightness(global_brightness) => GenericCommand {
|
||||
tag: CommandTag::GlobalBrightness,
|
||||
data: CommandUnion {
|
||||
global_brightness: heap_move_nonnull(global_brightness),
|
||||
},
|
||||
},
|
||||
TypedCommand::BrightnessGrid(brightness_grid) => GenericCommand {
|
||||
tag: CommandTag::BrightnessGrid,
|
||||
data: CommandUnion {
|
||||
brightness_grid: heap_move_nonnull(brightness_grid),
|
||||
},
|
||||
},
|
||||
TypedCommand::BitVec(bitvec) => GenericCommand {
|
||||
tag: CommandTag::BitVec,
|
||||
data: CommandUnion {
|
||||
bit_vec: heap_move_nonnull(bitvec),
|
||||
},
|
||||
},
|
||||
TypedCommand::HardReset(hard_reset) => GenericCommand {
|
||||
tag: CommandTag::HardReset,
|
||||
data: CommandUnion {
|
||||
hard_reset: heap_move_nonnull(hard_reset),
|
||||
},
|
||||
},
|
||||
TypedCommand::FadeOut(fade_out) => GenericCommand {
|
||||
tag: CommandTag::FadeOut,
|
||||
data: CommandUnion {
|
||||
fade_out: heap_move_nonnull(fade_out),
|
||||
},
|
||||
},
|
||||
#[allow(deprecated)]
|
||||
TypedCommand::BitmapLegacy(bitmap_legacy) => GenericCommand {
|
||||
tag: CommandTag::BitmapLegacy,
|
||||
data: CommandUnion {
|
||||
bitmap_legacy: heap_move_nonnull(bitmap_legacy),
|
||||
},
|
||||
},
|
||||
})
|
||||
.unwrap_or_else(move |_| GenericCommand {
|
||||
tag: CommandTag::Invalid,
|
||||
data: CommandUnion { null: null_mut() },
|
||||
})
|
||||
};
|
||||
);
|
||||
derive_clone!(GenericCommand);
|
||||
derive_free!(GenericCommand);
|
||||
|
||||
wrap! { GenericCommand;
|
||||
/// Tries to turn a [GenericCommand] into a [Packet].
|
||||
/// The [GenericCommand] gets consumed.
|
||||
///
|
||||
/// Returns tag [CommandTag::Invalid] in case of an error.
|
||||
method try_into_packet(move command) -> val *mut Packet {
|
||||
match command.tag {
|
||||
CommandTag::Invalid => null_mut(),
|
||||
CommandTag::Bitmap => {
|
||||
heap_move_ok(unsafe { heap_remove(command.data.bitmap).try_into() })
|
||||
wrap! {
|
||||
GenericCommand {
|
||||
functions:
|
||||
/// Tries to turn a [Packet] into a [GenericCommand].
|
||||
///
|
||||
/// The packet is dropped in the process.
|
||||
///
|
||||
/// Returns: pointer to new [GenericCommand] instance or NULL if parsing failed.
|
||||
fn try_from_packet(packet: move NonNull<Packet>) -> move NonNull<GenericCommand> {
|
||||
servicepoint::TypedCommand::try_from(packet)
|
||||
.map(|value| match value {
|
||||
TypedCommand::Clear(clear) => GenericCommand {
|
||||
tag: CommandTag::Clear,
|
||||
data: CommandUnion {
|
||||
clear: heap_move_nonnull(clear),
|
||||
},
|
||||
},
|
||||
TypedCommand::CharGrid(char_grid) => GenericCommand {
|
||||
tag: CommandTag::CharGrid,
|
||||
data: CommandUnion {
|
||||
char_grid: heap_move_nonnull(char_grid),
|
||||
},
|
||||
},
|
||||
TypedCommand::Cp437Grid(cp437_grid) => GenericCommand {
|
||||
tag: CommandTag::Cp437Grid,
|
||||
data: CommandUnion {
|
||||
cp437_grid: heap_move_nonnull(cp437_grid),
|
||||
},
|
||||
},
|
||||
TypedCommand::Bitmap(bitmap) => GenericCommand {
|
||||
tag: CommandTag::Bitmap,
|
||||
data: CommandUnion {
|
||||
bitmap: heap_move_nonnull(bitmap),
|
||||
},
|
||||
},
|
||||
TypedCommand::Brightness(global_brightness) => GenericCommand {
|
||||
tag: CommandTag::GlobalBrightness,
|
||||
data: CommandUnion {
|
||||
global_brightness: heap_move_nonnull(global_brightness),
|
||||
},
|
||||
},
|
||||
TypedCommand::BrightnessGrid(brightness_grid) => GenericCommand {
|
||||
tag: CommandTag::BrightnessGrid,
|
||||
data: CommandUnion {
|
||||
brightness_grid: heap_move_nonnull(brightness_grid),
|
||||
},
|
||||
},
|
||||
TypedCommand::BitVec(bitvec) => GenericCommand {
|
||||
tag: CommandTag::BitVec,
|
||||
data: CommandUnion {
|
||||
bit_vec: heap_move_nonnull(bitvec),
|
||||
},
|
||||
},
|
||||
TypedCommand::HardReset(hard_reset) => GenericCommand {
|
||||
tag: CommandTag::HardReset,
|
||||
data: CommandUnion {
|
||||
hard_reset: heap_move_nonnull(hard_reset),
|
||||
},
|
||||
},
|
||||
TypedCommand::FadeOut(fade_out) => GenericCommand {
|
||||
tag: CommandTag::FadeOut,
|
||||
data: CommandUnion {
|
||||
fade_out: heap_move_nonnull(fade_out),
|
||||
},
|
||||
},
|
||||
#[allow(deprecated)]
|
||||
TypedCommand::BitmapLegacy(bitmap_legacy) => GenericCommand {
|
||||
tag: CommandTag::BitmapLegacy,
|
||||
data: CommandUnion {
|
||||
bitmap_legacy: heap_move_nonnull(bitmap_legacy),
|
||||
},
|
||||
},
|
||||
})
|
||||
.unwrap_or_else(move |_| GenericCommand {
|
||||
tag: CommandTag::Invalid,
|
||||
data: CommandUnion { null: null_mut() },
|
||||
})
|
||||
};
|
||||
methods:
|
||||
/// Tries to turn a [GenericCommand] into a [Packet].
|
||||
/// The [GenericCommand] gets consumed.
|
||||
///
|
||||
/// Returns tag [CommandTag::Invalid] in case of an error.
|
||||
fn try_into_packet(move command) -> val *mut Packet {
|
||||
match command.tag {
|
||||
CommandTag::Invalid => null_mut(),
|
||||
CommandTag::Bitmap => {
|
||||
heap_move_ok(unsafe { heap_remove(command.data.bitmap).try_into() })
|
||||
}
|
||||
CommandTag::BitVec => {
|
||||
heap_move_ok(unsafe { heap_remove(command.data.bit_vec).try_into() })
|
||||
}
|
||||
CommandTag::BrightnessGrid => heap_move_ok(unsafe {
|
||||
heap_remove(command.data.brightness_grid).try_into()
|
||||
}),
|
||||
CommandTag::CharGrid => heap_move_ok(unsafe {
|
||||
heap_remove(command.data.char_grid).try_into()
|
||||
}),
|
||||
CommandTag::Cp437Grid => heap_move_ok(unsafe {
|
||||
heap_remove(command.data.cp437_grid).try_into()
|
||||
}),
|
||||
CommandTag::GlobalBrightness => heap_move(unsafe {
|
||||
heap_remove(command.data.global_brightness).into()
|
||||
}),
|
||||
CommandTag::Clear => {
|
||||
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::BitVec => {
|
||||
heap_move_ok(unsafe { heap_remove(command.data.bit_vec).try_into() })
|
||||
}
|
||||
CommandTag::BrightnessGrid => heap_move_ok(unsafe {
|
||||
heap_remove(command.data.brightness_grid).try_into()
|
||||
}),
|
||||
CommandTag::CharGrid => heap_move_ok(unsafe {
|
||||
heap_remove(command.data.char_grid).try_into()
|
||||
}),
|
||||
CommandTag::Cp437Grid => heap_move_ok(unsafe {
|
||||
heap_remove(command.data.cp437_grid).try_into()
|
||||
}),
|
||||
CommandTag::GlobalBrightness => heap_move(unsafe {
|
||||
heap_remove(command.data.global_brightness).into()
|
||||
}),
|
||||
CommandTag::Clear => {
|
||||
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() })
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
use crate::{
|
||||
commands::wrap_command,
|
||||
macros::{wrap, wrap_functions},
|
||||
};
|
||||
use crate::{commands::wrap_command, macros::wrap};
|
||||
use servicepoint::{Brightness, GlobalBrightnessCommand};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
wrap_functions!(associate GlobalBrightnessCommand;
|
||||
/// Set the brightness of all tiles to the same value.
|
||||
///
|
||||
/// Returns: a new [GlobalBrightnessCommand] instance.
|
||||
fn new(brightness: val Brightness) -> move NonNull<GlobalBrightnessCommand> {
|
||||
GlobalBrightnessCommand::from(brightness)
|
||||
};
|
||||
);
|
||||
|
||||
wrap_command!(GlobalBrightness);
|
||||
|
||||
wrap!(GlobalBrightnessCommand;
|
||||
prop brightness: Brightness { get; set; };
|
||||
wrap!(
|
||||
GlobalBrightnessCommand {
|
||||
properties:
|
||||
prop brightness: Brightness { get; set; };
|
||||
functions:
|
||||
/// Set the brightness of all tiles to the same value.
|
||||
///
|
||||
/// Returns: a new [GlobalBrightnessCommand] instance.
|
||||
fn new(brightness: val Brightness) -> move NonNull<GlobalBrightnessCommand> {
|
||||
GlobalBrightnessCommand::from(brightness)
|
||||
};
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue