formatting changes, mostly resulting from the shorter name
This commit is contained in:
parent
78a4d4dbcf
commit
a08d439366
|
@ -1,7 +1,7 @@
|
||||||
//! Example for how to use the WebSocket connection
|
//! Example for how to use the WebSocket connection
|
||||||
|
|
||||||
use servicepoint::{
|
use servicepoint::{
|
||||||
Command, CompressionCode, Connection, Grid, Origin, Bitmap,
|
Bitmap, Command, CompressionCode, Connection, Grid, Origin,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -197,7 +197,7 @@ impl<'t> Iterator for IterRows<'t> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{DataRef, Grid, Bitmap};
|
use crate::{Bitmap, DataRef, Grid};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn fill() {
|
fn fill() {
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
||||||
command_code::CommandCode,
|
command_code::CommandCode,
|
||||||
compression::into_decompressed,
|
compression::into_decompressed,
|
||||||
packet::{Header, Packet},
|
packet::{Header, Packet},
|
||||||
Brightness, BrightnessGrid, CompressionCode, Cp437Grid, Origin, Bitmap,
|
Bitmap, Brightness, BrightnessGrid, CompressionCode, Cp437Grid, Origin,
|
||||||
Pixels, PrimitiveGrid, SpBitVec, Tiles, TILE_SIZE,
|
Pixels, PrimitiveGrid, SpBitVec, Tiles, TILE_SIZE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -495,8 +495,8 @@ mod tests {
|
||||||
command_code::CommandCode,
|
command_code::CommandCode,
|
||||||
origin::Pixels,
|
origin::Pixels,
|
||||||
packet::{Header, Packet},
|
packet::{Header, Packet},
|
||||||
Brightness, BrightnessGrid, Command, CompressionCode, Origin,
|
Bitmap, Brightness, BrightnessGrid, Command, CompressionCode, Origin,
|
||||||
Bitmap, PrimitiveGrid,
|
PrimitiveGrid,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn round_trip(original: Command) {
|
fn round_trip(original: Command) {
|
||||||
|
@ -903,6 +903,7 @@ mod tests {
|
||||||
Origin::new(1, 0) + Origin::new(3, 2)
|
Origin::new(1, 0) + Origin::new(3, 2)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn packet_into_char_brightness_invalid() {
|
fn packet_into_char_brightness_invalid() {
|
||||||
let grid = BrightnessGrid::new(2, 2);
|
let grid = BrightnessGrid::new(2, 2);
|
||||||
|
|
|
@ -40,6 +40,7 @@ use std::time::Duration;
|
||||||
pub use bitvec;
|
pub use bitvec;
|
||||||
use bitvec::prelude::{BitVec, Msb0};
|
use bitvec::prelude::{BitVec, Msb0};
|
||||||
|
|
||||||
|
pub use crate::bitmap::Bitmap;
|
||||||
pub use crate::brightness::{Brightness, BrightnessGrid};
|
pub use crate::brightness::{Brightness, BrightnessGrid};
|
||||||
pub use crate::command::{Command, Offset};
|
pub use crate::command::{Command, Offset};
|
||||||
pub use crate::compression_code::CompressionCode;
|
pub use crate::compression_code::CompressionCode;
|
||||||
|
@ -48,11 +49,11 @@ pub use crate::cp437::{CharGrid, Cp437Grid};
|
||||||
pub use crate::data_ref::DataRef;
|
pub use crate::data_ref::DataRef;
|
||||||
pub use crate::grid::Grid;
|
pub use crate::grid::Grid;
|
||||||
pub use crate::origin::{Origin, Pixels, Tiles};
|
pub use crate::origin::{Origin, Pixels, Tiles};
|
||||||
pub use crate::bitmap::Bitmap;
|
|
||||||
pub use crate::primitive_grid::PrimitiveGrid;
|
pub use crate::primitive_grid::PrimitiveGrid;
|
||||||
|
|
||||||
type SpBitVec = BitVec<u8, Msb0>;
|
type SpBitVec = BitVec<u8, Msb0>;
|
||||||
|
|
||||||
|
mod bitmap;
|
||||||
mod brightness;
|
mod brightness;
|
||||||
mod command;
|
mod command;
|
||||||
mod command_code;
|
mod command_code;
|
||||||
|
@ -64,7 +65,6 @@ mod data_ref;
|
||||||
mod grid;
|
mod grid;
|
||||||
mod origin;
|
mod origin;
|
||||||
pub mod packet;
|
pub mod packet;
|
||||||
mod bitmap;
|
|
||||||
mod primitive_grid;
|
mod primitive_grid;
|
||||||
|
|
||||||
/// size of a single tile in one dimension
|
/// size of a single tile in one dimension
|
||||||
|
|
|
@ -27,8 +27,8 @@ use std::mem::size_of;
|
||||||
|
|
||||||
use crate::compression::into_compressed;
|
use crate::compression::into_compressed;
|
||||||
use crate::{
|
use crate::{
|
||||||
command_code::CommandCode, Command, CompressionCode, Grid, Offset, Origin,
|
command_code::CommandCode, Bitmap, Command, CompressionCode, Grid, Offset,
|
||||||
Bitmap, Pixels, Tiles, TILE_SIZE,
|
Origin, Pixels, Tiles, TILE_SIZE,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A raw header.
|
/// A raw header.
|
||||||
|
|
|
@ -210,10 +210,7 @@ pub unsafe extern "C" fn sp_bitmap_set(
|
||||||
/// - `bitmap` points to a valid [SPBitmap]
|
/// - `bitmap` points to a valid [SPBitmap]
|
||||||
/// - `bitmap` is not written to or read from concurrently
|
/// - `bitmap` is not written to or read from concurrently
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn sp_bitmap_fill(
|
pub unsafe extern "C" fn sp_bitmap_fill(bitmap: *mut SPBitmap, value: bool) {
|
||||||
bitmap: *mut SPBitmap,
|
|
||||||
value: bool,
|
|
||||||
) {
|
|
||||||
assert!(!bitmap.is_null());
|
assert!(!bitmap.is_null());
|
||||||
(*bitmap).0.fill(value);
|
(*bitmap).0.fill(value);
|
||||||
}
|
}
|
||||||
|
@ -234,9 +231,7 @@ pub unsafe extern "C" fn sp_bitmap_fill(
|
||||||
///
|
///
|
||||||
/// - `bitmap` points to a valid [SPBitmap]
|
/// - `bitmap` points to a valid [SPBitmap]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn sp_bitmap_width(
|
pub unsafe extern "C" fn sp_bitmap_width(bitmap: *const SPBitmap) -> usize {
|
||||||
bitmap: *const SPBitmap,
|
|
||||||
) -> usize {
|
|
||||||
assert!(!bitmap.is_null());
|
assert!(!bitmap.is_null());
|
||||||
(*bitmap).0.width()
|
(*bitmap).0.width()
|
||||||
}
|
}
|
||||||
|
@ -257,9 +252,7 @@ pub unsafe extern "C" fn sp_bitmap_width(
|
||||||
///
|
///
|
||||||
/// - `bitmap` points to a valid [SPBitmap]
|
/// - `bitmap` points to a valid [SPBitmap]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn sp_bitmap_height(
|
pub unsafe extern "C" fn sp_bitmap_height(bitmap: *const SPBitmap) -> usize {
|
||||||
bitmap: *const SPBitmap,
|
|
||||||
) -> usize {
|
|
||||||
assert!(!bitmap.is_null());
|
assert!(!bitmap.is_null());
|
||||||
(*bitmap).0.height()
|
(*bitmap).0.height()
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,8 @@ use std::ptr::null_mut;
|
||||||
use servicepoint::{Brightness, Origin};
|
use servicepoint::{Brightness, Origin};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
SPBitVec, SPBrightnessGrid, SPCompressionCode, SPCp437Grid, SPPacket,
|
SPBitVec, SPBitmap, SPBrightnessGrid, SPCompressionCode, SPCp437Grid,
|
||||||
SPBitmap,
|
SPPacket,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A low-level display command.
|
/// A low-level display command.
|
||||||
|
@ -107,7 +107,8 @@ pub unsafe extern "C" fn sp_command_clone(
|
||||||
/// by explicitly calling `sp_command_free`.
|
/// by explicitly calling `sp_command_free`.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn sp_command_clear() -> *mut SPCommand {
|
pub unsafe extern "C" fn sp_command_clear() -> *mut SPCommand {
|
||||||
let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::Clear)));
|
let result =
|
||||||
|
Box::into_raw(Box::new(SPCommand(servicepoint::Command::Clear)));
|
||||||
assert!(!result.is_null());
|
assert!(!result.is_null());
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
@ -126,7 +127,8 @@ pub unsafe extern "C" fn sp_command_clear() -> *mut SPCommand {
|
||||||
/// by explicitly calling `sp_command_free`.
|
/// by explicitly calling `sp_command_free`.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn sp_command_hard_reset() -> *mut SPCommand {
|
pub unsafe extern "C" fn sp_command_hard_reset() -> *mut SPCommand {
|
||||||
let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::HardReset)));
|
let result =
|
||||||
|
Box::into_raw(Box::new(SPCommand(servicepoint::Command::HardReset)));
|
||||||
assert!(!result.is_null());
|
assert!(!result.is_null());
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
@ -143,7 +145,8 @@ pub unsafe extern "C" fn sp_command_hard_reset() -> *mut SPCommand {
|
||||||
/// by explicitly calling `sp_command_free`.
|
/// by explicitly calling `sp_command_free`.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn sp_command_fade_out() -> *mut SPCommand {
|
pub unsafe extern "C" fn sp_command_fade_out() -> *mut SPCommand {
|
||||||
let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::FadeOut)));
|
let result =
|
||||||
|
Box::into_raw(Box::new(SPCommand(servicepoint::Command::FadeOut)));
|
||||||
assert!(!result.is_null());
|
assert!(!result.is_null());
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
@ -168,9 +171,9 @@ pub unsafe extern "C" fn sp_command_brightness(
|
||||||
) -> *mut SPCommand {
|
) -> *mut SPCommand {
|
||||||
let brightness =
|
let brightness =
|
||||||
Brightness::try_from(brightness).expect("invalid brightness");
|
Brightness::try_from(brightness).expect("invalid brightness");
|
||||||
let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::Brightness(
|
let result = Box::into_raw(Box::new(SPCommand(
|
||||||
brightness,
|
servicepoint::Command::Brightness(brightness),
|
||||||
))));
|
)));
|
||||||
assert!(!result.is_null());
|
assert!(!result.is_null());
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
@ -201,10 +204,9 @@ pub unsafe extern "C" fn sp_command_char_brightness(
|
||||||
) -> *mut SPCommand {
|
) -> *mut SPCommand {
|
||||||
assert!(!grid.is_null());
|
assert!(!grid.is_null());
|
||||||
let byte_grid = *Box::from_raw(grid);
|
let byte_grid = *Box::from_raw(grid);
|
||||||
let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::CharBrightness(
|
let result = Box::into_raw(Box::new(SPCommand(
|
||||||
Origin::new(x, y),
|
servicepoint::Command::CharBrightness(Origin::new(x, y), byte_grid.0),
|
||||||
byte_grid.0,
|
)));
|
||||||
))));
|
|
||||||
assert!(!result.is_null());
|
assert!(!result.is_null());
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
@ -242,11 +244,13 @@ pub unsafe extern "C" fn sp_command_bitmap_linear(
|
||||||
) -> *mut SPCommand {
|
) -> *mut SPCommand {
|
||||||
assert!(!bit_vec.is_null());
|
assert!(!bit_vec.is_null());
|
||||||
let bit_vec = *Box::from_raw(bit_vec);
|
let bit_vec = *Box::from_raw(bit_vec);
|
||||||
let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::BitmapLinear(
|
let result = Box::into_raw(Box::new(SPCommand(
|
||||||
|
servicepoint::Command::BitmapLinear(
|
||||||
offset,
|
offset,
|
||||||
bit_vec.into(),
|
bit_vec.into(),
|
||||||
compression.try_into().expect("invalid compression code"),
|
compression.try_into().expect("invalid compression code"),
|
||||||
))));
|
),
|
||||||
|
)));
|
||||||
assert!(!result.is_null());
|
assert!(!result.is_null());
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
@ -284,11 +288,13 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_and(
|
||||||
) -> *mut SPCommand {
|
) -> *mut SPCommand {
|
||||||
assert!(!bit_vec.is_null());
|
assert!(!bit_vec.is_null());
|
||||||
let bit_vec = *Box::from_raw(bit_vec);
|
let bit_vec = *Box::from_raw(bit_vec);
|
||||||
let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::BitmapLinearAnd(
|
let result = Box::into_raw(Box::new(SPCommand(
|
||||||
|
servicepoint::Command::BitmapLinearAnd(
|
||||||
offset,
|
offset,
|
||||||
bit_vec.into(),
|
bit_vec.into(),
|
||||||
compression.try_into().expect("invalid compression code"),
|
compression.try_into().expect("invalid compression code"),
|
||||||
))));
|
),
|
||||||
|
)));
|
||||||
assert!(!result.is_null());
|
assert!(!result.is_null());
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
@ -326,11 +332,13 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_or(
|
||||||
) -> *mut SPCommand {
|
) -> *mut SPCommand {
|
||||||
assert!(!bit_vec.is_null());
|
assert!(!bit_vec.is_null());
|
||||||
let bit_vec = *Box::from_raw(bit_vec);
|
let bit_vec = *Box::from_raw(bit_vec);
|
||||||
let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::BitmapLinearOr(
|
let result = Box::into_raw(Box::new(SPCommand(
|
||||||
|
servicepoint::Command::BitmapLinearOr(
|
||||||
offset,
|
offset,
|
||||||
bit_vec.into(),
|
bit_vec.into(),
|
||||||
compression.try_into().expect("invalid compression code"),
|
compression.try_into().expect("invalid compression code"),
|
||||||
))));
|
),
|
||||||
|
)));
|
||||||
assert!(!result.is_null());
|
assert!(!result.is_null());
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
@ -368,11 +376,13 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_xor(
|
||||||
) -> *mut SPCommand {
|
) -> *mut SPCommand {
|
||||||
assert!(!bit_vec.is_null());
|
assert!(!bit_vec.is_null());
|
||||||
let bit_vec = *Box::from_raw(bit_vec);
|
let bit_vec = *Box::from_raw(bit_vec);
|
||||||
let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::BitmapLinearXor(
|
let result = Box::into_raw(Box::new(SPCommand(
|
||||||
|
servicepoint::Command::BitmapLinearXor(
|
||||||
offset,
|
offset,
|
||||||
bit_vec.into(),
|
bit_vec.into(),
|
||||||
compression.try_into().expect("invalid compression code"),
|
compression.try_into().expect("invalid compression code"),
|
||||||
))));
|
),
|
||||||
|
)));
|
||||||
assert!(!result.is_null());
|
assert!(!result.is_null());
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
@ -403,10 +413,9 @@ pub unsafe extern "C" fn sp_command_cp437_data(
|
||||||
) -> *mut SPCommand {
|
) -> *mut SPCommand {
|
||||||
assert!(!grid.is_null());
|
assert!(!grid.is_null());
|
||||||
let grid = *Box::from_raw(grid);
|
let grid = *Box::from_raw(grid);
|
||||||
let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::Cp437Data(
|
let result = Box::into_raw(Box::new(SPCommand(
|
||||||
Origin::new(x, y),
|
servicepoint::Command::Cp437Data(Origin::new(x, y), grid.0),
|
||||||
grid.0,
|
)));
|
||||||
))));
|
|
||||||
assert!(!result.is_null());
|
assert!(!result.is_null());
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
@ -440,13 +449,15 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_win(
|
||||||
) -> *mut SPCommand {
|
) -> *mut SPCommand {
|
||||||
assert!(!bitmap.is_null());
|
assert!(!bitmap.is_null());
|
||||||
let byte_grid = (*Box::from_raw(bitmap)).0;
|
let byte_grid = (*Box::from_raw(bitmap)).0;
|
||||||
let result = Box::into_raw(Box::new(SPCommand(servicepoint::Command::BitmapLinearWin(
|
let result = Box::into_raw(Box::new(SPCommand(
|
||||||
|
servicepoint::Command::BitmapLinearWin(
|
||||||
Origin::new(x, y),
|
Origin::new(x, y),
|
||||||
byte_grid,
|
byte_grid,
|
||||||
compression_code
|
compression_code
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("invalid compression code"),
|
.expect("invalid compression code"),
|
||||||
))));
|
),
|
||||||
|
)));
|
||||||
assert!(!result.is_null());
|
assert!(!result.is_null());
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,9 @@ pub unsafe extern "C" fn sp_cp437_grid_new(
|
||||||
width: usize,
|
width: usize,
|
||||||
height: usize,
|
height: usize,
|
||||||
) -> *mut SPCp437Grid {
|
) -> *mut SPCp437Grid {
|
||||||
let result = Box::into_raw(Box::new(SPCp437Grid(servicepoint::Cp437Grid::new(
|
let result = Box::into_raw(Box::new(SPCp437Grid(
|
||||||
width, height,
|
servicepoint::Cp437Grid::new(width, height),
|
||||||
))));
|
)));
|
||||||
assert!(!result.is_null());
|
assert!(!result.is_null());
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
@ -73,9 +73,9 @@ pub unsafe extern "C" fn sp_cp437_grid_load(
|
||||||
) -> *mut SPCp437Grid {
|
) -> *mut SPCp437Grid {
|
||||||
assert!(data.is_null());
|
assert!(data.is_null());
|
||||||
let data = std::slice::from_raw_parts(data, data_length);
|
let data = std::slice::from_raw_parts(data, data_length);
|
||||||
let result = Box::into_raw(Box::new(SPCp437Grid(servicepoint::Cp437Grid::load(
|
let result = Box::into_raw(Box::new(SPCp437Grid(
|
||||||
width, height, data,
|
servicepoint::Cp437Grid::load(width, height, data),
|
||||||
))));
|
)));
|
||||||
assert!(!result.is_null());
|
assert!(!result.is_null());
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
pub use crate::bit_vec::*;
|
pub use crate::bit_vec::*;
|
||||||
|
pub use crate::bitmap::*;
|
||||||
pub use crate::brightness_grid::*;
|
pub use crate::brightness_grid::*;
|
||||||
pub use crate::byte_slice::*;
|
pub use crate::byte_slice::*;
|
||||||
pub use crate::command::*;
|
pub use crate::command::*;
|
||||||
|
@ -33,9 +34,9 @@ pub use crate::connection::*;
|
||||||
pub use crate::constants::*;
|
pub use crate::constants::*;
|
||||||
pub use crate::cp437_grid::*;
|
pub use crate::cp437_grid::*;
|
||||||
pub use crate::packet::*;
|
pub use crate::packet::*;
|
||||||
pub use crate::bitmap::*;
|
|
||||||
|
|
||||||
mod bit_vec;
|
mod bit_vec;
|
||||||
|
mod bitmap;
|
||||||
mod brightness_grid;
|
mod brightness_grid;
|
||||||
mod byte_slice;
|
mod byte_slice;
|
||||||
mod command;
|
mod command;
|
||||||
|
@ -43,4 +44,3 @@ mod connection;
|
||||||
mod constants;
|
mod constants;
|
||||||
mod cp437_grid;
|
mod cp437_grid;
|
||||||
mod packet;
|
mod packet;
|
||||||
mod bitmap;
|
|
||||||
|
|
Loading…
Reference in a new issue