annotate which parameters are consumed, move constants

This commit is contained in:
Vinzenz Schroeter 2024-10-19 15:31:54 +02:00
parent 57c66d9d31
commit f836220259
19 changed files with 158 additions and 92 deletions

View file

@ -121,6 +121,8 @@ pub unsafe extern "C" fn sp_bitmap_clone(
/// - `bitmap` points to a valid [SPBitmap]
/// - `bitmap` is not used concurrently or after bitmap call
/// - `bitmap` was not passed to another consuming function, e.g. to create a [SPCommand]
///
/// servicepoint_csbindgen_consumes: bitmap
#[no_mangle]
pub unsafe extern "C" fn sp_bitmap_free(bitmap: *mut SPBitmap) {
assert!(!bitmap.is_null());

View file

@ -8,13 +8,6 @@ use std::convert::Into;
use std::intrinsics::transmute;
use std::ptr::NonNull;
/// see [Brightness::MIN]
pub const SP_BRIGHTNESS_MIN: u8 = 0;
/// see [Brightness::MAX]
pub const SP_BRIGHTNESS_MAX: u8 = 11;
/// Count of possible brightness values
pub const SP_BRIGHTNESS_LEVELS: u8 = 12;
/// A grid containing brightness values.
///
/// # Examples
@ -133,6 +126,8 @@ pub unsafe extern "C" fn sp_brightness_grid_clone(
/// - `brightness_grid` points to a valid [SPBrightnessGrid]
/// - `brightness_grid` is not used concurrently or after this call
/// - `brightness_grid` was not passed to another consuming function, e.g. to create a [SPCommand]
///
/// servicepoint_csbindgen_consumes: brightness_grid
#[no_mangle]
pub unsafe extern "C" fn sp_brightness_grid_free(
brightness_grid: *mut SPBrightnessGrid,

View file

@ -50,6 +50,8 @@ impl Clone for SPCommand {
/// - the result is checked for NULL
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_free`.
///
/// servicepoint_csbindgen_consumes: packet
#[no_mangle]
pub unsafe extern "C" fn sp_command_try_from_packet(
packet: *mut SPPacket,
@ -187,6 +189,8 @@ pub unsafe extern "C" fn sp_command_brightness(
/// - `grid` is not used concurrently or after this call
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_free`.
///
/// servicepoint_csbindgen_consumes: grid
#[no_mangle]
pub unsafe extern "C" fn sp_command_char_brightness(
x: usize,
@ -227,6 +231,8 @@ pub unsafe extern "C" fn sp_command_char_brightness(
/// - `compression` matches one of the allowed enum values
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_free`.
///
/// servicepoint_csbindgen_consumes: bit_vec
#[no_mangle]
pub unsafe extern "C" fn sp_command_bitmap_linear(
offset: usize,
@ -268,6 +274,8 @@ pub unsafe extern "C" fn sp_command_bitmap_linear(
/// - `compression` matches one of the allowed enum values
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_free`.
///
/// servicepoint_csbindgen_consumes: bit_vec
#[no_mangle]
pub unsafe extern "C" fn sp_command_bitmap_linear_and(
offset: usize,
@ -309,6 +317,8 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_and(
/// - `compression` matches one of the allowed enum values
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_free`.
///
/// servicepoint_csbindgen_consumes: bit_vec
#[no_mangle]
pub unsafe extern "C" fn sp_command_bitmap_linear_or(
offset: usize,
@ -350,6 +360,8 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_or(
/// - `compression` matches one of the allowed enum values
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_free`.
///
/// servicepoint_csbindgen_consumes: bit_vec
#[no_mangle]
pub unsafe extern "C" fn sp_command_bitmap_linear_xor(
offset: usize,
@ -384,6 +396,8 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_xor(
/// - `grid` is not used concurrently or after this call
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_free`.
///
/// servicepoint_csbindgen_consumes: grid
#[no_mangle]
pub unsafe extern "C" fn sp_command_cp437_data(
x: usize,
@ -419,6 +433,8 @@ pub unsafe extern "C" fn sp_command_cp437_data(
/// - `compression` matches one of the allowed enum values
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_free`.
///
/// servicepoint_csbindgen_consumes: bitmap
#[no_mangle]
pub unsafe extern "C" fn sp_command_bitmap_linear_win(
x: usize,
@ -458,6 +474,8 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_win(
/// - `command` points to a valid [SPCommand]
/// - `command` is not used concurrently or after this call
/// - `command` was not passed to another consuming function, e.g. to create a [SPPacket]
///
/// servicepoint_csbindgen_consumes: command
#[no_mangle]
pub unsafe extern "C" fn sp_command_free(command: *mut SPCommand) {
assert!(!command.is_null());

View file

@ -64,6 +64,8 @@ pub unsafe extern "C" fn sp_connection_open(
/// - `connection` points to a valid instance of [SPConnection]
/// - `packet` points to a valid instance of [SPPacket]
/// - `packet` is not used concurrently or after this call
///
/// servicepoint_csbindgen_consumes: packet
#[no_mangle]
pub unsafe extern "C" fn sp_connection_send_packet(
connection: *const SPConnection,
@ -93,6 +95,8 @@ pub unsafe extern "C" fn sp_connection_send_packet(
/// - `connection` points to a valid instance of [SPConnection]
/// - `command` points to a valid instance of [SPPacket]
/// - `command` is not used concurrently or after this call
///
/// servicepoint_csbindgen_consumes: packet
#[no_mangle]
pub unsafe extern "C" fn sp_connection_send_command(
connection: *const SPConnection,
@ -116,6 +120,8 @@ pub unsafe extern "C" fn sp_connection_send_command(
///
/// - `connection` points to a valid [SPConnection]
/// - `connection` is not used concurrently or after this call
///
/// servicepoint_csbindgen_consumes: connection
#[no_mangle]
pub unsafe extern "C" fn sp_connection_free(connection: *mut SPConnection) {
assert!(!connection.is_null());

View file

@ -1,6 +1,6 @@
//! re-exported constants for use in C
use servicepoint::CompressionCode;
use servicepoint::{CompressionCode};
use std::time::Duration;
/// size of a single tile in one dimension
@ -24,6 +24,13 @@ pub const SP_PIXEL_COUNT: usize = SP_PIXEL_WIDTH * SP_PIXEL_HEIGHT;
/// Actual hardware limit is around 28-29ms/frame. Rounded up for less dropped packets.
pub const SP_FRAME_PACING_MS: u128 = Duration::from_millis(30).as_millis();
/// see [Brightness::MIN]
pub const SP_BRIGHTNESS_MIN: u8 = 0;
/// see [Brightness::MAX]
pub const SP_BRIGHTNESS_MAX: u8 = 11;
/// Count of possible brightness values
pub const SP_BRIGHTNESS_LEVELS: u8 = 12;
/// Specifies the kind of compression to use.
#[repr(u16)]
pub enum SPCompressionCode {

View file

@ -116,6 +116,8 @@ pub unsafe extern "C" fn sp_cp437_grid_clone(
/// - `cp437_grid` points to a valid [SPCp437Grid]
/// - `cp437_grid` is not used concurrently or after cp437_grid call
/// - `cp437_grid` was not passed to another consuming function, e.g. to create a [SPCommand]
///
/// servicepoint_csbindgen_consumes: cp437_grid
#[no_mangle]
pub unsafe extern "C" fn sp_cp437_grid_free(cp437_grid: *mut SPCp437Grid) {
assert!(!cp437_grid.is_null());

View file

@ -26,6 +26,8 @@ pub struct SPPacket(pub(crate) servicepoint::packet::Packet);
/// - [SPCommand] is not used concurrently or after this call
/// - the returned [SPPacket] instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_packet_free`.
///
/// servicepoint_csbindgen_consumes: command
#[no_mangle]
pub unsafe extern "C" fn sp_packet_from_command(
command: *mut SPCommand,
@ -94,7 +96,7 @@ pub unsafe extern "C" fn sp_packet_clone(
///
/// # Panics
///
/// - when `sp_packet_free` is NULL
/// - when `packet` is NULL
///
/// # Safety
///
@ -102,6 +104,8 @@ pub unsafe extern "C" fn sp_packet_clone(
///
/// - `packet` points to a valid [SPPacket]
/// - `packet` is not used concurrently or after this call
///
/// servicepoint_csbindgen_consumes: packet
#[no_mangle]
pub unsafe extern "C" fn sp_packet_free(packet: *mut SPPacket) {
assert!(!packet.is_null());

View file

@ -79,7 +79,7 @@ namespace ServicePoint
/// </summary>
public BitVec Clone()
{
return new BitVec(BitVec.sp_bitvec_clone(Instance));
return new BitVec(BitVec.sp_bitvec_clone(this.Instance));
}
/// <summary>
@ -106,7 +106,7 @@ namespace ServicePoint
/// </summary>
public bool Get(nuint index)
{
return BitVec.sp_bitvec_get(Instance, index);
return BitVec.sp_bitvec_get(this.Instance, index);
}
/// <summary>
@ -132,7 +132,7 @@ namespace ServicePoint
/// </summary>
public void Set(nuint index, bool value)
{
BitVec.sp_bitvec_set(Instance, index, value);
BitVec.sp_bitvec_set(this.Instance, index, value);
}
/// <summary>
@ -156,7 +156,7 @@ namespace ServicePoint
/// </summary>
public void Fill(bool value)
{
BitVec.sp_bitvec_fill(Instance, value);
BitVec.sp_bitvec_fill(this.Instance, value);
}
/// <summary>
@ -178,7 +178,7 @@ namespace ServicePoint
/// </summary>
public nuint Len()
{
return BitVec.sp_bitvec_len(Instance);
return BitVec.sp_bitvec_len(this.Instance);
}
/// <summary>
@ -200,7 +200,7 @@ namespace ServicePoint
/// </summary>
public bool IsEmpty()
{
return BitVec.sp_bitvec_is_empty(Instance);
return BitVec.sp_bitvec_is_empty(this.Instance);
}
/// <summary>
@ -224,10 +224,11 @@ namespace ServicePoint
/// </summary>
public SPByteSlice UnsafeDataRef()
{
return BitVec.sp_bitvec_unsafe_data_ref(Instance);
return BitVec.sp_bitvec_unsafe_data_ref(this.Instance);
}
#region internal machinery
private SPBitVec* _instance;
internal SPBitVec* Instance
{
@ -266,8 +267,11 @@ namespace ServicePoint
~BitVec() => Free();
const string __DllName = "servicepoint_binding_c";
#endregion
#nullable restore
#region native methods
const string __DllName = "servicepoint_binding_c";
[DllImport(__DllName, EntryPoint = "sp_bitvec_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
private static extern SPBitVec* sp_bitvec_new(nuint size);
@ -301,6 +305,7 @@ namespace ServicePoint
private static extern SPByteSlice sp_bitvec_unsafe_data_ref(SPBitVec* bit_vec);
#endregion
}
[StructLayout(LayoutKind.Sequential)]

View file

@ -86,7 +86,7 @@ namespace ServicePoint
/// </summary>
public Bitmap Clone()
{
return new Bitmap(Bitmap.sp_bitmap_clone(Instance));
return new Bitmap(Bitmap.sp_bitmap_clone(this.Instance));
}
/// <summary>
@ -111,7 +111,7 @@ namespace ServicePoint
/// </summary>
public bool Get(nuint x, nuint y)
{
return Bitmap.sp_bitmap_get(Instance, x, y);
return Bitmap.sp_bitmap_get(this.Instance, x, y);
}
/// <summary>
@ -139,7 +139,7 @@ namespace ServicePoint
/// </summary>
public void Set(nuint x, nuint y, bool value)
{
Bitmap.sp_bitmap_set(Instance, x, y, value);
Bitmap.sp_bitmap_set(this.Instance, x, y, value);
}
/// <summary>
@ -163,7 +163,7 @@ namespace ServicePoint
/// </summary>
public void Fill(bool value)
{
Bitmap.sp_bitmap_fill(Instance, value);
Bitmap.sp_bitmap_fill(this.Instance, value);
}
/// <summary>
@ -185,7 +185,7 @@ namespace ServicePoint
/// </summary>
public nuint Width()
{
return Bitmap.sp_bitmap_width(Instance);
return Bitmap.sp_bitmap_width(this.Instance);
}
/// <summary>
@ -207,7 +207,7 @@ namespace ServicePoint
/// </summary>
public nuint Height()
{
return Bitmap.sp_bitmap_height(Instance);
return Bitmap.sp_bitmap_height(this.Instance);
}
/// <summary>
@ -227,10 +227,11 @@ namespace ServicePoint
/// </summary>
public SPByteSlice UnsafeDataRef()
{
return Bitmap.sp_bitmap_unsafe_data_ref(Instance);
return Bitmap.sp_bitmap_unsafe_data_ref(this.Instance);
}
#region internal machinery
private SPBitmap* _instance;
internal SPBitmap* Instance
{
@ -269,8 +270,11 @@ namespace ServicePoint
~Bitmap() => Free();
const string __DllName = "servicepoint_binding_c";
#endregion
#nullable restore
#region native methods
const string __DllName = "servicepoint_binding_c";
[DllImport(__DllName, EntryPoint = "sp_bitmap_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
private static extern SPBitmap* sp_bitmap_new(nuint width, nuint height);
@ -303,6 +307,7 @@ namespace ServicePoint
private static extern SPByteSlice sp_bitmap_unsafe_data_ref(SPBitmap* bitmap);
#endregion
}
[StructLayout(LayoutKind.Sequential)]

View file

@ -10,17 +10,6 @@ using System.Runtime.InteropServices;
namespace ServicePoint
{
public static unsafe partial class BrightnessGridNative
{
const string __DllName = "servicepoint_binding_c";
public const byte SP_BRIGHTNESS_MIN = 0;
public const byte SP_BRIGHTNESS_MAX = 11;
public const byte SP_BRIGHTNESS_LEVELS = 12;
}
public unsafe sealed partial class BrightnessGrid: IDisposable
{
@ -87,7 +76,7 @@ namespace ServicePoint
/// </summary>
public BrightnessGrid Clone()
{
return new BrightnessGrid(BrightnessGrid.sp_brightness_grid_clone(Instance));
return new BrightnessGrid(BrightnessGrid.sp_brightness_grid_clone(this.Instance));
}
/// <summary>
@ -114,7 +103,7 @@ namespace ServicePoint
/// </summary>
public byte Get(nuint x, nuint y)
{
return BrightnessGrid.sp_brightness_grid_get(Instance, x, y);
return BrightnessGrid.sp_brightness_grid_get(this.Instance, x, y);
}
/// <summary>
@ -143,7 +132,7 @@ namespace ServicePoint
/// </summary>
public void Set(nuint x, nuint y, byte value)
{
BrightnessGrid.sp_brightness_grid_set(Instance, x, y, value);
BrightnessGrid.sp_brightness_grid_set(this.Instance, x, y, value);
}
/// <summary>
@ -168,7 +157,7 @@ namespace ServicePoint
/// </summary>
public void Fill(byte value)
{
BrightnessGrid.sp_brightness_grid_fill(Instance, value);
BrightnessGrid.sp_brightness_grid_fill(this.Instance, value);
}
/// <summary>
@ -192,7 +181,7 @@ namespace ServicePoint
/// </summary>
public nuint Width()
{
return BrightnessGrid.sp_brightness_grid_width(Instance);
return BrightnessGrid.sp_brightness_grid_width(this.Instance);
}
/// <summary>
@ -216,7 +205,7 @@ namespace ServicePoint
/// </summary>
public nuint Height()
{
return BrightnessGrid.sp_brightness_grid_height(Instance);
return BrightnessGrid.sp_brightness_grid_height(this.Instance);
}
/// <summary>
@ -242,10 +231,11 @@ namespace ServicePoint
/// </summary>
public SPByteSlice UnsafeDataRef()
{
return BrightnessGrid.sp_brightness_grid_unsafe_data_ref(Instance);
return BrightnessGrid.sp_brightness_grid_unsafe_data_ref(this.Instance);
}
#region internal machinery
private SPBrightnessGrid* _instance;
internal SPBrightnessGrid* Instance
{
@ -284,8 +274,11 @@ namespace ServicePoint
~BrightnessGrid() => Free();
const string __DllName = "servicepoint_binding_c";
#endregion
#nullable restore
#region native methods
const string __DllName = "servicepoint_binding_c";
[DllImport(__DllName, EntryPoint = "sp_brightness_grid_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
private static extern SPBrightnessGrid* sp_brightness_grid_new(nuint width, nuint height);
@ -317,6 +310,7 @@ namespace ServicePoint
private static extern SPByteSlice sp_brightness_grid_unsafe_data_ref(SPBrightnessGrid* brightness_grid);
#endregion
}
[StructLayout(LayoutKind.Sequential)]

View file

@ -34,10 +34,12 @@ namespace ServicePoint
/// - the result is checked for NULL
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_free`.
///
/// servicepoint_csbindgen_consumes: packet
/// </summary>
public static Command? TryFromPacket(Packet packet)
{
var native = Command.sp_command_try_from_packet(packet.Instance);
var native = Command.sp_command_try_from_packet(packet.Into());
return native == null ? null : new Command(native);
}
@ -61,7 +63,7 @@ namespace ServicePoint
/// </summary>
public Command Clone()
{
return new Command(Command.sp_command_clone(Instance));
return new Command(Command.sp_command_clone(this.Instance));
}
/// <summary>
@ -165,10 +167,12 @@ namespace ServicePoint
/// - `grid` is not used concurrently or after this call
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_free`.
///
/// servicepoint_csbindgen_consumes: grid
/// </summary>
public static Command CharBrightness(nuint x, nuint y, BrightnessGrid grid)
{
return new Command(Command.sp_command_char_brightness(x, y, grid.Instance));
return new Command(Command.sp_command_char_brightness(x, y, grid.Into()));
}
/// <summary>
@ -197,10 +201,12 @@ namespace ServicePoint
/// - `compression` matches one of the allowed enum values
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_free`.
///
/// servicepoint_csbindgen_consumes: bit_vec
/// </summary>
public static Command BitmapLinear(nuint offset, BitVec bit_vec, CompressionCode compression)
{
return new Command(Command.sp_command_bitmap_linear(offset, bit_vec.Instance, compression));
return new Command(Command.sp_command_bitmap_linear(offset, bit_vec.Into(), compression));
}
/// <summary>
@ -229,10 +235,12 @@ namespace ServicePoint
/// - `compression` matches one of the allowed enum values
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_free`.
///
/// servicepoint_csbindgen_consumes: bit_vec
/// </summary>
public static Command BitmapLinearAnd(nuint offset, BitVec bit_vec, CompressionCode compression)
{
return new Command(Command.sp_command_bitmap_linear_and(offset, bit_vec.Instance, compression));
return new Command(Command.sp_command_bitmap_linear_and(offset, bit_vec.Into(), compression));
}
/// <summary>
@ -261,10 +269,12 @@ namespace ServicePoint
/// - `compression` matches one of the allowed enum values
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_free`.
///
/// servicepoint_csbindgen_consumes: bit_vec
/// </summary>
public static Command BitmapLinearOr(nuint offset, BitVec bit_vec, CompressionCode compression)
{
return new Command(Command.sp_command_bitmap_linear_or(offset, bit_vec.Instance, compression));
return new Command(Command.sp_command_bitmap_linear_or(offset, bit_vec.Into(), compression));
}
/// <summary>
@ -293,10 +303,12 @@ namespace ServicePoint
/// - `compression` matches one of the allowed enum values
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_free`.
///
/// servicepoint_csbindgen_consumes: bit_vec
/// </summary>
public static Command BitmapLinearXor(nuint offset, BitVec bit_vec, CompressionCode compression)
{
return new Command(Command.sp_command_bitmap_linear_xor(offset, bit_vec.Instance, compression));
return new Command(Command.sp_command_bitmap_linear_xor(offset, bit_vec.Into(), compression));
}
/// <summary>
@ -318,10 +330,12 @@ namespace ServicePoint
/// - `grid` is not used concurrently or after this call
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_free`.
///
/// servicepoint_csbindgen_consumes: grid
/// </summary>
public static Command Cp437Data(nuint x, nuint y, Cp437Grid grid)
{
return new Command(Command.sp_command_cp437_data(x, y, grid.Instance));
return new Command(Command.sp_command_cp437_data(x, y, grid.Into()));
}
/// <summary>
@ -345,13 +359,16 @@ namespace ServicePoint
/// - `compression` matches one of the allowed enum values
/// - the returned [SPCommand] instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_command_free`.
///
/// servicepoint_csbindgen_consumes: bitmap
/// </summary>
public static Command BitmapLinearWin(nuint x, nuint y, Bitmap bitmap, CompressionCode compression_code)
{
return new Command(Command.sp_command_bitmap_linear_win(x, y, bitmap.Instance, compression_code));
return new Command(Command.sp_command_bitmap_linear_win(x, y, bitmap.Into(), compression_code));
}
#region internal machinery
private SPCommand* _instance;
internal SPCommand* Instance
{
@ -390,8 +407,11 @@ namespace ServicePoint
~Command() => Free();
const string __DllName = "servicepoint_binding_c";
#endregion
#nullable restore
#region native methods
const string __DllName = "servicepoint_binding_c";
[DllImport(__DllName, EntryPoint = "sp_command_try_from_packet", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
private static extern SPCommand* sp_command_try_from_packet(SPPacket* packet);
@ -435,6 +455,7 @@ namespace ServicePoint
private static extern void sp_command_free(SPCommand* command);
#endregion
}
[StructLayout(LayoutKind.Sequential)]

View file

@ -55,10 +55,12 @@ namespace ServicePoint
/// - `connection` points to a valid instance of [SPConnection]
/// - `packet` points to a valid instance of [SPPacket]
/// - `packet` is not used concurrently or after this call
///
/// servicepoint_csbindgen_consumes: packet
/// </summary>
public bool SendPacket(Packet packet)
{
return Connection.sp_connection_send_packet(Instance, packet.Instance);
return Connection.sp_connection_send_packet(this.Instance, packet.Into());
}
/// <summary>
@ -80,13 +82,16 @@ namespace ServicePoint
/// - `connection` points to a valid instance of [SPConnection]
/// - `command` points to a valid instance of [SPPacket]
/// - `command` is not used concurrently or after this call
///
/// servicepoint_csbindgen_consumes: packet
/// </summary>
public bool SendCommand(Command command)
{
return Connection.sp_connection_send_command(Instance, command.Instance);
return Connection.sp_connection_send_command(this.Instance, command.Instance);
}
#region internal machinery
private SPConnection* _instance;
internal SPConnection* Instance
{
@ -125,8 +130,11 @@ namespace ServicePoint
~Connection() => Free();
const string __DllName = "servicepoint_binding_c";
#endregion
#nullable restore
#region native methods
const string __DllName = "servicepoint_binding_c";
[DllImport(__DllName, EntryPoint = "sp_connection_open", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
private static extern SPConnection* sp_connection_open(byte* host);
@ -142,6 +150,7 @@ namespace ServicePoint
private static extern void sp_connection_free(SPConnection* connection);
#endregion
}
[StructLayout(LayoutKind.Sequential)]

View file

@ -19,4 +19,8 @@ public static class Constants
/// pixel count on whole screen
public const nuint PixelCount = PixelWidth * PixelHeight;
public const byte MinBrightness = ConstantsNative.SP_BRIGHTNESS_MIN;
public const byte MaxBrightness = ConstantsNative.SP_BRIGHTNESS_MAX;
public const byte BrightnessLevels = ConstantsNative.SP_BRIGHTNESS_LEVELS;
}

View file

@ -17,6 +17,9 @@ namespace ServicePoint
public const nuint SP_TILE_SIZE = 8;
public const nuint SP_TILE_WIDTH = 56;
public const nuint SP_TILE_HEIGHT = 20;
public const byte SP_BRIGHTNESS_MIN = 0;
public const byte SP_BRIGHTNESS_MAX = 11;
public const byte SP_BRIGHTNESS_LEVELS = 12;

View file

@ -72,7 +72,7 @@ namespace ServicePoint
/// </summary>
public Cp437Grid Clone()
{
return new Cp437Grid(Cp437Grid.sp_cp437_grid_clone(Instance));
return new Cp437Grid(Cp437Grid.sp_cp437_grid_clone(this.Instance));
}
/// <summary>
@ -97,7 +97,7 @@ namespace ServicePoint
/// </summary>
public byte Get(nuint x, nuint y)
{
return Cp437Grid.sp_cp437_grid_get(Instance, x, y);
return Cp437Grid.sp_cp437_grid_get(this.Instance, x, y);
}
/// <summary>
@ -125,7 +125,7 @@ namespace ServicePoint
/// </summary>
public void Set(nuint x, nuint y, byte value)
{
Cp437Grid.sp_cp437_grid_set(Instance, x, y, value);
Cp437Grid.sp_cp437_grid_set(this.Instance, x, y, value);
}
/// <summary>
@ -149,7 +149,7 @@ namespace ServicePoint
/// </summary>
public void Fill(byte value)
{
Cp437Grid.sp_cp437_grid_fill(Instance, value);
Cp437Grid.sp_cp437_grid_fill(this.Instance, value);
}
/// <summary>
@ -171,7 +171,7 @@ namespace ServicePoint
/// </summary>
public nuint Width()
{
return Cp437Grid.sp_cp437_grid_width(Instance);
return Cp437Grid.sp_cp437_grid_width(this.Instance);
}
/// <summary>
@ -193,7 +193,7 @@ namespace ServicePoint
/// </summary>
public nuint Height()
{
return Cp437Grid.sp_cp437_grid_height(Instance);
return Cp437Grid.sp_cp437_grid_height(this.Instance);
}
/// <summary>
@ -215,10 +215,11 @@ namespace ServicePoint
/// </summary>
public SPByteSlice UnsafeDataRef()
{
return Cp437Grid.sp_cp437_grid_unsafe_data_ref(Instance);
return Cp437Grid.sp_cp437_grid_unsafe_data_ref(this.Instance);
}
#region internal machinery
private SPCp437Grid* _instance;
internal SPCp437Grid* Instance
{
@ -257,8 +258,11 @@ namespace ServicePoint
~Cp437Grid() => Free();
const string __DllName = "servicepoint_binding_c";
#endregion
#nullable restore
#region native methods
const string __DllName = "servicepoint_binding_c";
[DllImport(__DllName, EntryPoint = "sp_cp437_grid_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
private static extern SPCp437Grid* sp_cp437_grid_new(nuint width, nuint height);
@ -290,6 +294,7 @@ namespace ServicePoint
private static extern SPByteSlice sp_cp437_grid_unsafe_data_ref(SPCp437Grid* cp437_grid);
#endregion
}
[StructLayout(LayoutKind.Sequential)]

View file

@ -32,10 +32,12 @@ namespace ServicePoint
/// - [SPCommand] is not used concurrently or after this call
/// - the returned [SPPacket] instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_packet_free`.
///
/// servicepoint_csbindgen_consumes: command
/// </summary>
public static Packet FromCommand(Command command)
{
return new Packet(Packet.sp_packet_from_command(command.Instance));
return new Packet(Packet.sp_packet_from_command(command.Into()));
}
/// <summary>
@ -82,10 +84,11 @@ namespace ServicePoint
/// </summary>
public Packet Clone()
{
return new Packet(Packet.sp_packet_clone(Instance));
return new Packet(Packet.sp_packet_clone(this.Instance));
}
#region internal machinery
private SPPacket* _instance;
internal SPPacket* Instance
{
@ -124,8 +127,11 @@ namespace ServicePoint
~Packet() => Free();
const string __DllName = "servicepoint_binding_c";
#endregion
#nullable restore
#region native methods
const string __DllName = "servicepoint_binding_c";
[DllImport(__DllName, EntryPoint = "sp_packet_from_command", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
private static extern SPPacket* sp_packet_from_command(SPCommand* command);
@ -139,6 +145,7 @@ namespace ServicePoint
private static extern void sp_packet_free(SPPacket* packet);
#endregion
}
[StructLayout(LayoutKind.Sequential)]

View file

@ -1,21 +0,0 @@
using System.Diagnostics.CodeAnalysis;
namespace ServicePoint;
public static class ServicePointExtensions
{
public static Packet IntoPacket(this Command command)
{
return Packet.FromCommand(command);
}
public static bool TryIntoCommand(this Packet packet, [MaybeNullWhen(false)] out Command command)
{
return Command.TryFromPacket(packet, out command);
}
public unsafe static Span<byte> AsSpan(this SPByteSlice slice)
{
return new Span<byte>(slice.start, (int)slice.length);
}
}

View file

@ -7,8 +7,8 @@ if (connection == null)
return;
}
connection.Send(Command.Clear().IntoPacket());
connection.Send(Command.Brightness(128).IntoPacket());
connection.Send(Command.Clear());
connection.Send(Command.Brightness(Constants.MaxBrightness));
using var pixels = new Bitmap(Constants.PixelWidth, Constants.PixelHeight);

@ -1 +1 @@
Subproject commit 2dcf44a5c398925249cf96e9bbf724dd551e5b76
Subproject commit de49df92fa878f0c6685d05ee42f36e3b7d9b042