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, ) -> NonNull { heap_move_nonnull(GlobalBrightnessCommand::from(brightness)) } #[no_mangle] pub unsafe extern "C" fn sp_cmd_brightness_global_into_packet( command: NonNull, ) -> NonNull { 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, ) -> NonNull { unsafe { heap_clone(command) } } #[no_mangle] pub unsafe extern "C" fn sp_cmd_brightness_global_free( command: NonNull, ) { unsafe { heap_drop(command) } } /// Moves the provided bitmap to be contained in the command. #[no_mangle] pub unsafe extern "C" fn sp_cmd_brightness_global_set( mut command: NonNull, brightness: Brightness, ) { unsafe { command.as_mut().brightness = brightness; } } #[no_mangle] pub unsafe extern "C" fn sp_cmd_brightness_global_get( mut command: NonNull, ) -> Brightness { unsafe { command.as_mut().brightness } }