rename/merge functions to match rust side more
This commit is contained in:
		
							parent
							
								
									f6e35f1259
								
							
						
					
					
						commit
						a41ca0feeb
					
				
					 7 changed files with 165 additions and 280 deletions
				
			
		| 
						 | 
				
			
			@ -42,7 +42,7 @@ pub unsafe extern "C" fn sp_bitmap_new(
 | 
			
		|||
///
 | 
			
		||||
/// returns: [Bitmap] initialized to all pixels off.
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_bitmap_new_screen_sized() -> NonNull<Bitmap> {
 | 
			
		||||
pub unsafe extern "C" fn sp_bitmap_new_max_sized() -> NonNull<Bitmap> {
 | 
			
		||||
    let result = Box::new(Bitmap::max_sized());
 | 
			
		||||
    NonNull::from(Box::leak(result))
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										117
									
								
								src/command.rs
									
										
									
									
									
								
							
							
						
						
									
										117
									
								
								src/command.rs
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -104,106 +104,15 @@ pub unsafe extern "C" fn sp_command_char_brightness(
 | 
			
		|||
/// 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 contained [SPBitVec] is always uncompressed.
 | 
			
		||||
/// The [`BinaryOperation`] will be applied on the display comparing old and sent bit.
 | 
			
		||||
///
 | 
			
		||||
/// The passed [SPBitVec] gets consumed.
 | 
			
		||||
/// `new_bit = old_bit op sent_bit`
 | 
			
		||||
///
 | 
			
		||||
/// Returns: a new [servicepoint::Command::BitmapLinear] instance.
 | 
			
		||||
/// For example, [`BinaryOperation::Or`] can be used to turn on some pixels without affecting other pixels.
 | 
			
		||||
///
 | 
			
		||||
/// The contained [`BitVecU8Msb0`] is always uncompressed.
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_command_bitmap_linear(
 | 
			
		||||
    offset: usize,
 | 
			
		||||
    bit_vec: NonNull<SPBitVec>,
 | 
			
		||||
    compression: CompressionCode,
 | 
			
		||||
) -> *mut TypedCommand {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        sp_command_bitmap_linear_internal(
 | 
			
		||||
            offset,
 | 
			
		||||
            bit_vec,
 | 
			
		||||
            compression,
 | 
			
		||||
            BinaryOperation::Overwrite,
 | 
			
		||||
        )
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// 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.
 | 
			
		||||
///
 | 
			
		||||
/// The contained [SPBitVec] is always uncompressed.
 | 
			
		||||
///
 | 
			
		||||
/// The passed [SPBitVec] gets consumed.
 | 
			
		||||
///
 | 
			
		||||
/// Returns: a new [servicepoint::Command::BitmapLinearAnd] instance.
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_command_bitmap_linear_and(
 | 
			
		||||
    offset: usize,
 | 
			
		||||
    bit_vec: NonNull<SPBitVec>,
 | 
			
		||||
    compression: CompressionCode,
 | 
			
		||||
) -> *mut TypedCommand {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        sp_command_bitmap_linear_internal(
 | 
			
		||||
            offset,
 | 
			
		||||
            bit_vec,
 | 
			
		||||
            compression,
 | 
			
		||||
            BinaryOperation::Xor,
 | 
			
		||||
        )
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// 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.
 | 
			
		||||
///
 | 
			
		||||
/// The contained [SPBitVec] is always uncompressed.
 | 
			
		||||
///
 | 
			
		||||
/// The passed [SPBitVec] gets consumed.
 | 
			
		||||
///
 | 
			
		||||
/// Returns: a new [servicepoint::Command::BitmapLinearOr] instance.
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_command_bitmap_linear_or(
 | 
			
		||||
    offset: usize,
 | 
			
		||||
    bit_vec: NonNull<SPBitVec>,
 | 
			
		||||
    compression: CompressionCode,
 | 
			
		||||
) -> *mut TypedCommand {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        sp_command_bitmap_linear_internal(
 | 
			
		||||
            offset,
 | 
			
		||||
            bit_vec,
 | 
			
		||||
            compression,
 | 
			
		||||
            BinaryOperation::Or,
 | 
			
		||||
        )
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// 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.
 | 
			
		||||
///
 | 
			
		||||
/// The contained [SPBitVec] is always uncompressed.
 | 
			
		||||
///
 | 
			
		||||
/// The passed [SPBitVec] gets consumed.
 | 
			
		||||
///
 | 
			
		||||
/// Returns: a new [servicepoint::Command::BitmapLinearXor] instance.
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_command_bitmap_linear_xor(
 | 
			
		||||
    offset: usize,
 | 
			
		||||
    bit_vec: NonNull<SPBitVec>,
 | 
			
		||||
    compression: CompressionCode,
 | 
			
		||||
) -> *mut TypedCommand {
 | 
			
		||||
    unsafe {
 | 
			
		||||
        sp_command_bitmap_linear_internal(
 | 
			
		||||
            offset,
 | 
			
		||||
            bit_vec,
 | 
			
		||||
            compression,
 | 
			
		||||
            BinaryOperation::Xor,
 | 
			
		||||
        )
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
unsafe fn sp_command_bitmap_linear_internal(
 | 
			
		||||
pub unsafe extern "C" fn sp_command_bitvec(
 | 
			
		||||
    offset: usize,
 | 
			
		||||
    bit_vec: NonNull<SPBitVec>,
 | 
			
		||||
    compression: CompressionCode,
 | 
			
		||||
| 
						 | 
				
			
			@ -220,7 +129,7 @@ unsafe fn sp_command_bitmap_linear_internal(
 | 
			
		|||
        bitvec: bit_vec.0,
 | 
			
		||||
        compression,
 | 
			
		||||
    }
 | 
			
		||||
    .into();
 | 
			
		||||
        .into();
 | 
			
		||||
    Box::leak(Box::new(command))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -228,9 +137,9 @@ unsafe fn sp_command_bitmap_linear_internal(
 | 
			
		|||
///
 | 
			
		||||
/// The passed [Cp437Grid] gets consumed.
 | 
			
		||||
///
 | 
			
		||||
/// Returns: a new [servicepoint::Command::Cp437Data] instance.
 | 
			
		||||
/// Returns: a new [servicepoint::Cp437GridCommand] instance.
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_command_cp437_data(
 | 
			
		||||
pub unsafe extern "C" fn sp_command_cp437_grid(
 | 
			
		||||
    x: usize,
 | 
			
		||||
    y: usize,
 | 
			
		||||
    grid: NonNull<Cp437Grid>,
 | 
			
		||||
| 
						 | 
				
			
			@ -250,9 +159,9 @@ pub unsafe extern "C" fn sp_command_cp437_data(
 | 
			
		|||
///
 | 
			
		||||
/// The passed [CharGrid] gets consumed.
 | 
			
		||||
///
 | 
			
		||||
/// Returns: a new [servicepoint::Command::Utf8Data] instance.
 | 
			
		||||
/// Returns: a new [servicepoint::CharGridCommand] instance.
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_command_utf8_data(
 | 
			
		||||
pub unsafe extern "C" fn sp_command_char_grid(
 | 
			
		||||
    x: usize,
 | 
			
		||||
    y: usize,
 | 
			
		||||
    grid: NonNull<CharGrid>,
 | 
			
		||||
| 
						 | 
				
			
			@ -272,9 +181,9 @@ pub unsafe extern "C" fn sp_command_utf8_data(
 | 
			
		|||
///
 | 
			
		||||
/// The passed [Bitmap] gets consumed.
 | 
			
		||||
///
 | 
			
		||||
/// Returns: a new [servicepoint::Command::BitmapLinearWin] instance.
 | 
			
		||||
/// Returns: a new [servicepoint::BitmapCommand] instance.
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_command_bitmap_linear_win(
 | 
			
		||||
pub unsafe extern "C" fn sp_command_bitmap(
 | 
			
		||||
    x: usize,
 | 
			
		||||
    y: usize,
 | 
			
		||||
    bitmap: NonNull<Bitmap>,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,7 +15,7 @@ use std::ptr::NonNull;
 | 
			
		|||
///     sp_connection_send_command(connection, sp_command_clear());
 | 
			
		||||
/// ```
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_connection_open(
 | 
			
		||||
pub unsafe extern "C" fn sp_udp_open(
 | 
			
		||||
    host: NonNull<c_char>,
 | 
			
		||||
) -> *mut UdpConnection {
 | 
			
		||||
    let host = unsafe { CStr::from_ptr(host.as_ptr()) }
 | 
			
		||||
| 
						 | 
				
			
			@ -41,7 +41,7 @@ pub unsafe extern "C" fn sp_connection_open(
 | 
			
		|||
///     sp_connection_send_command(connection, sp_command_clear());
 | 
			
		||||
/// ```
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_connection_open_ipv4(
 | 
			
		||||
pub unsafe extern "C" fn sp_udp_open_ipv4(
 | 
			
		||||
    ip1: u8, ip2: u8, ip3: u8, ip4: u8,
 | 
			
		||||
    port: u16,
 | 
			
		||||
) -> *mut UdpConnection {
 | 
			
		||||
| 
						 | 
				
			
			@ -53,29 +53,13 @@ pub unsafe extern "C" fn sp_connection_open_ipv4(
 | 
			
		|||
    Box::into_raw(Box::new(connection))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// /// Creates a new instance of [SPUdpConnection] for testing that does not actually send anything.
 | 
			
		||||
// ///
 | 
			
		||||
// /// returns: a new instance.
 | 
			
		||||
// ///
 | 
			
		||||
// /// # Safety
 | 
			
		||||
// ///
 | 
			
		||||
// /// The caller has to make sure that:
 | 
			
		||||
// ///
 | 
			
		||||
// /// - the returned instance is freed in some way, either by using a consuming function or
 | 
			
		||||
// ///   by explicitly calling `sp_connection_free`.
 | 
			
		||||
// #[no_mangle]
 | 
			
		||||
// pub unsafe extern "C" fn sp_connection_fake() -> NonNull<SPUdpConnection> {
 | 
			
		||||
//     let result = Box::new(SPUdpConnection(servicepoint::Connection::Fake));
 | 
			
		||||
//     NonNull::from(Box::leak(result))
 | 
			
		||||
// }
 | 
			
		||||
 | 
			
		||||
/// Sends a [Packet] to the display using the [UdpConnection].
 | 
			
		||||
///
 | 
			
		||||
/// The passed `packet` gets consumed.
 | 
			
		||||
///
 | 
			
		||||
/// returns: true in case of success
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_connection_send_packet(
 | 
			
		||||
pub unsafe extern "C" fn sp_udp_send_packet(
 | 
			
		||||
    connection: NonNull<UdpConnection>,
 | 
			
		||||
    packet: NonNull<Packet>,
 | 
			
		||||
) -> bool {
 | 
			
		||||
| 
						 | 
				
			
			@ -96,7 +80,7 @@ pub unsafe extern "C" fn sp_connection_send_packet(
 | 
			
		|||
/// sp_connection_send_command(connection, sp_command_brightness(5));
 | 
			
		||||
/// ```
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_connection_send_command(
 | 
			
		||||
pub unsafe extern "C" fn sp_udp_send_command(
 | 
			
		||||
    connection: NonNull<UdpConnection>,
 | 
			
		||||
    command: NonNull<TypedCommand>,
 | 
			
		||||
) -> bool {
 | 
			
		||||
| 
						 | 
				
			
			@ -106,7 +90,7 @@ pub unsafe extern "C" fn sp_connection_send_command(
 | 
			
		|||
 | 
			
		||||
/// Closes and deallocates a [UdpConnection].
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_connection_free(
 | 
			
		||||
pub unsafe extern "C" fn sp_udp_free(
 | 
			
		||||
    connection: NonNull<UdpConnection>,
 | 
			
		||||
) {
 | 
			
		||||
    _ = unsafe { Box::from_raw(connection.as_ptr()) };
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue