Compare commits
No commits in common. "635fef024437d29b922999fe1d8bd7e6e30524a9" and "022106e2dba704a58f9e6f97b1db7c9ce38005ab" have entirely different histories.
635fef0244
...
022106e2db
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -1,6 +1,6 @@
|
||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
version = 3
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "adler2"
|
name = "adler2"
|
||||||
|
@ -425,9 +425,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "servicepoint"
|
name = "servicepoint"
|
||||||
version = "0.15.0"
|
version = "0.14.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "91a33bff7f9db5008748b23ca0c906c276fe00694390b681f004a55968a42cfe"
|
checksum = "f6bd5cfa49c73aeecb344680ffbf697abf73e0563a441b93b9723ae43867500f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitvec",
|
"bitvec",
|
||||||
"bzip2",
|
"bzip2",
|
||||||
|
@ -441,7 +441,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "servicepoint_binding_uniffi"
|
name = "servicepoint_binding_uniffi"
|
||||||
version = "0.15.0"
|
version = "0.13.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"servicepoint",
|
"servicepoint",
|
||||||
"thiserror 2.0.11",
|
"thiserror 2.0.11",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "servicepoint_binding_uniffi"
|
name = "servicepoint_binding_uniffi"
|
||||||
version = "0.15.0"
|
version = "0.13.1"
|
||||||
publish = false
|
publish = false
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
|
@ -21,7 +21,7 @@ uniffi = { version = "0.28.3" }
|
||||||
thiserror = "2.0"
|
thiserror = "2.0"
|
||||||
|
|
||||||
[dependencies.servicepoint]
|
[dependencies.servicepoint]
|
||||||
version = "0.15.0"
|
version = "0.14.1"
|
||||||
features = ["all_compressions"]
|
features = ["all_compressions"]
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
|
|
|
@ -2,16 +2,16 @@
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1749494155,
|
"lastModified": 1739357830,
|
||||||
"narHash": "sha256-FG4DEYBpROupu758beabUk9lhrblSf5hnv84v1TLqMc=",
|
"narHash": "sha256-9xim3nJJUFbVbJCz48UP4fGRStVW5nv4VdbimbKxJ3I=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "88331c17ba434359491e8d5889cce872464052c2",
|
"rev": "0ff09db9d034a04acd4e8908820ba0b410d7a33a",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"ref": "nixos-25.05",
|
"ref": "nixos-24.11",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
description = "Flake for the servicepoint library.";
|
description = "Flake for the servicepoint library.";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs =
|
||||||
|
|
77
src/bitmap.rs
Normal file
77
src/bitmap.rs
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
use servicepoint::{DataRef, Grid};
|
||||||
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
|
#[derive(uniffi::Object)]
|
||||||
|
pub struct Bitmap {
|
||||||
|
pub(crate) actual: RwLock<servicepoint::Bitmap>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Bitmap {
|
||||||
|
fn internal_new(actual: servicepoint::Bitmap) -> Arc<Self> {
|
||||||
|
Arc::new(Self {
|
||||||
|
actual: RwLock::new(actual),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[uniffi::export]
|
||||||
|
impl Bitmap {
|
||||||
|
#[uniffi::constructor]
|
||||||
|
pub fn new(width: u64, height: u64) -> Arc<Self> {
|
||||||
|
Self::internal_new(servicepoint::Bitmap::new(
|
||||||
|
width as usize,
|
||||||
|
height as usize,
|
||||||
|
).unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[uniffi::constructor]
|
||||||
|
pub fn new_max_sized() -> Arc<Self> {
|
||||||
|
Self::internal_new(servicepoint::Bitmap::max_sized())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[uniffi::constructor]
|
||||||
|
pub fn load(width: u64, height: u64, data: Vec<u8>) -> Arc<Self> {
|
||||||
|
Self::internal_new(servicepoint::Bitmap::load(
|
||||||
|
width as usize,
|
||||||
|
height as usize,
|
||||||
|
&data,
|
||||||
|
).unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[uniffi::constructor]
|
||||||
|
pub fn clone(other: &Arc<Self>) -> Arc<Self> {
|
||||||
|
Self::internal_new(other.actual.read().unwrap().clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set(&self, x: u64, y: u64, value: bool) {
|
||||||
|
self.actual
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.set(x as usize, y as usize, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get(&self, x: u64, y: u64) -> bool {
|
||||||
|
self.actual.read().unwrap().get(x as usize, y as usize)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn fill(&self, value: bool) {
|
||||||
|
self.actual.write().unwrap().fill(value)
|
||||||
|
}
|
||||||
|
pub fn width(&self) -> u64 {
|
||||||
|
self.actual.read().unwrap().width() as u64
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn height(&self) -> u64 {
|
||||||
|
self.actual.read().unwrap().height() as u64
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn equals(&self, other: &Bitmap) -> bool {
|
||||||
|
let a = self.actual.read().unwrap();
|
||||||
|
let b = other.actual.read().unwrap();
|
||||||
|
*a == *b
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn copy_raw(&self) -> Vec<u8> {
|
||||||
|
self.actual.read().unwrap().data_ref().to_vec()
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,22 +1,34 @@
|
||||||
use crate::macros::wrap_uniffi_object;
|
use std::sync::{Arc, RwLock};
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
wrap_uniffi_object!(DisplayBitVec, BitVec);
|
#[derive(uniffi::Object)]
|
||||||
|
pub struct BitVec {
|
||||||
|
pub(crate) actual: RwLock<servicepoint::DisplayBitVec>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BitVec {
|
||||||
|
fn internal_new(actual: servicepoint::DisplayBitVec) -> Arc<Self> {
|
||||||
|
Arc::new(Self {
|
||||||
|
actual: RwLock::new(actual),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[uniffi::export]
|
#[uniffi::export]
|
||||||
impl BitVec {
|
impl BitVec {
|
||||||
#[uniffi::constructor]
|
#[uniffi::constructor]
|
||||||
pub fn new(size: u64) -> Arc<Self> {
|
pub fn new(size: u64) -> Arc<Self> {
|
||||||
Self::internal_new(servicepoint::DisplayBitVec::repeat(
|
Self::internal_new(servicepoint::DisplayBitVec::repeat(false, size as usize))
|
||||||
false,
|
|
||||||
size as usize,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
#[uniffi::constructor]
|
#[uniffi::constructor]
|
||||||
pub fn load(data: Vec<u8>) -> Arc<Self> {
|
pub fn load(data: Vec<u8>) -> Arc<Self> {
|
||||||
Self::internal_new(servicepoint::DisplayBitVec::from_slice(&data))
|
Self::internal_new(servicepoint::DisplayBitVec::from_slice(&data))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[uniffi::constructor]
|
||||||
|
pub fn clone(other: &Arc<Self>) -> Arc<Self> {
|
||||||
|
Self::internal_new(other.actual.read().unwrap().clone())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set(&self, index: u64, value: bool) {
|
pub fn set(&self, index: u64, value: bool) {
|
||||||
self.actual.write().unwrap().set(index as usize, value)
|
self.actual.write().unwrap().set(index as usize, value)
|
||||||
}
|
}
|
|
@ -1,19 +0,0 @@
|
||||||
use crate::UniffiCustomTypeConverter;
|
|
||||||
use servicepoint::Brightness;
|
|
||||||
|
|
||||||
uniffi::custom_type!(Brightness, u8);
|
|
||||||
|
|
||||||
impl UniffiCustomTypeConverter for Brightness {
|
|
||||||
type Builtin = u8;
|
|
||||||
|
|
||||||
fn into_custom(val: Self::Builtin) -> uniffi::Result<Self>
|
|
||||||
where
|
|
||||||
Self: Sized,
|
|
||||||
{
|
|
||||||
Ok(Brightness::saturating_from(val))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn from_custom(obj: Self) -> Self::Builtin {
|
|
||||||
obj.into()
|
|
||||||
}
|
|
||||||
}
|
|
86
src/brightness_grid.rs
Normal file
86
src/brightness_grid.rs
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
use servicepoint::{Brightness, DataRef, Grid};
|
||||||
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
|
#[derive(uniffi::Object)]
|
||||||
|
pub struct BrightnessGrid {
|
||||||
|
pub(crate) actual: RwLock<servicepoint::BrightnessGrid>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BrightnessGrid {
|
||||||
|
fn internal_new(actual: servicepoint::BrightnessGrid) -> Arc<Self> {
|
||||||
|
Arc::new(Self {
|
||||||
|
actual: RwLock::new(actual),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[uniffi::export]
|
||||||
|
impl BrightnessGrid {
|
||||||
|
#[uniffi::constructor]
|
||||||
|
pub fn new(width: u64, height: u64) -> Arc<Self> {
|
||||||
|
Self::internal_new(servicepoint::BrightnessGrid::new(
|
||||||
|
width as usize,
|
||||||
|
height as usize,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[uniffi::constructor]
|
||||||
|
pub fn load(width: u64, height: u64, data: Vec<u8>) -> Arc<Self> {
|
||||||
|
Self::internal_new(servicepoint::BrightnessGrid::saturating_load(
|
||||||
|
width as usize,
|
||||||
|
height as usize,
|
||||||
|
&data,
|
||||||
|
).unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[uniffi::constructor]
|
||||||
|
pub fn clone(other: &Arc<Self>) -> Arc<Self> {
|
||||||
|
Self::internal_new(other.actual.read().unwrap().clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set(&self, x: u64, y: u64, value: u8) {
|
||||||
|
self.actual.write().unwrap().set(
|
||||||
|
x as usize,
|
||||||
|
y as usize,
|
||||||
|
Brightness::saturating_from(value),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get(&self, x: u64, y: u64) -> u8 {
|
||||||
|
self.actual
|
||||||
|
.read()
|
||||||
|
.unwrap()
|
||||||
|
.get(x as usize, y as usize)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn fill(&self, value: u8) {
|
||||||
|
self.actual
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.fill(Brightness::saturating_from(value))
|
||||||
|
}
|
||||||
|
pub fn width(&self) -> u64 {
|
||||||
|
self.actual.read().unwrap().width() as u64
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn height(&self) -> u64 {
|
||||||
|
self.actual.read().unwrap().height() as u64
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn equals(&self, other: &BrightnessGrid) -> bool {
|
||||||
|
let a = self.actual.read().unwrap();
|
||||||
|
let b = other.actual.read().unwrap();
|
||||||
|
*a == *b
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn copy_raw(&self) -> Vec<u8> {
|
||||||
|
self.actual
|
||||||
|
.read()
|
||||||
|
.unwrap()
|
||||||
|
.data_ref()
|
||||||
|
.iter()
|
||||||
|
.map(u8::from)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,12 @@
|
||||||
use crate::{containers::cp437_grid::Cp437Grid, macros::*};
|
use crate::cp437_grid::Cp437Grid;
|
||||||
use servicepoint::{Grid, SetValueSeriesError};
|
use servicepoint::{Grid, SetValueSeriesError};
|
||||||
use std::{convert::Into, sync::Arc};
|
use std::convert::Into;
|
||||||
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
wrap_uniffi_object!(CharGrid);
|
#[derive(uniffi::Object)]
|
||||||
wrap_width_height!(CharGrid);
|
pub struct CharGrid {
|
||||||
|
pub(crate) actual: RwLock<servicepoint::CharGrid>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(uniffi::Error, thiserror::Error, Debug)]
|
#[derive(uniffi::Error, thiserror::Error, Debug)]
|
||||||
pub enum CharGridError {
|
pub enum CharGridError {
|
||||||
|
@ -30,6 +33,11 @@ impl CharGrid {
|
||||||
Self::internal_new(servicepoint::CharGrid::from(&*data))
|
Self::internal_new(servicepoint::CharGrid::from(&*data))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[uniffi::constructor]
|
||||||
|
pub fn clone(other: &Arc<Self>) -> Arc<Self> {
|
||||||
|
Self::internal_new(other.actual.read().unwrap().clone())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set(
|
pub fn set(
|
||||||
&self,
|
&self,
|
||||||
x: u64,
|
x: u64,
|
||||||
|
@ -58,6 +66,14 @@ impl CharGrid {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn width(&self) -> u64 {
|
||||||
|
self.actual.read().unwrap().width() as u64
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn height(&self) -> u64 {
|
||||||
|
self.actual.read().unwrap().height() as u64
|
||||||
|
}
|
||||||
|
|
||||||
pub fn equals(&self, other: &CharGrid) -> bool {
|
pub fn equals(&self, other: &CharGrid) -> bool {
|
||||||
let a = self.actual.read().unwrap();
|
let a = self.actual.read().unwrap();
|
||||||
let b = other.actual.read().unwrap();
|
let b = other.actual.read().unwrap();
|
||||||
|
@ -117,6 +133,12 @@ impl CharGrid {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CharGrid {
|
impl CharGrid {
|
||||||
|
pub(crate) fn internal_new(actual: servicepoint::CharGrid) -> Arc<Self> {
|
||||||
|
Arc::new(Self {
|
||||||
|
actual: RwLock::new(actual),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn str_to_char(value: String) -> Result<char, CharGridError> {
|
fn str_to_char(value: String) -> Result<char, CharGridError> {
|
||||||
if value.len() != 1 {
|
if value.len() != 1 {
|
||||||
return Err(CharGridError::StringNotOneChar { value });
|
return Err(CharGridError::StringNotOneChar { value });
|
|
@ -1,20 +1,23 @@
|
||||||
use crate::{
|
use crate::bitmap::Bitmap;
|
||||||
compression_code::CompressionCode,
|
use crate::bitvec::BitVec;
|
||||||
containers::{
|
use crate::brightness_grid::BrightnessGrid;
|
||||||
bitmap::Bitmap, bitvec::BitVec, brightness_grid::BrightnessGrid,
|
use crate::char_grid::CharGrid;
|
||||||
char_grid::CharGrid, cp437_grid::Cp437Grid,
|
use crate::compression_code::CompressionCode;
|
||||||
},
|
use crate::cp437_grid::Cp437Grid;
|
||||||
errors::ServicePointError,
|
use crate::errors::ServicePointError;
|
||||||
macros::wrap_uniffi_object,
|
use servicepoint::{BitVecCommand, BrightnessGridCommand, CharGridCommand, ClearCommand, Cp437GridCommand, FadeOutCommand, GlobalBrightnessCommand, HardResetCommand, Origin};
|
||||||
};
|
|
||||||
use servicepoint::{
|
|
||||||
BitVecCommand, BrightnessGridCommand, CharGridCommand, ClearCommand,
|
|
||||||
Cp437GridCommand, FadeOutCommand, GlobalBrightnessCommand,
|
|
||||||
HardResetCommand, Origin,
|
|
||||||
};
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
wrap_uniffi_object!(TypedCommand, Command);
|
#[derive(uniffi::Object)]
|
||||||
|
pub struct Command {
|
||||||
|
pub(crate) actual: servicepoint::TypedCommand,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Command {
|
||||||
|
fn internal_new(actual: servicepoint::TypedCommand) -> Arc<Command> {
|
||||||
|
Arc::new(Command { actual })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[uniffi::export]
|
#[uniffi::export]
|
||||||
impl Command {
|
impl Command {
|
||||||
|
@ -27,7 +30,7 @@ impl Command {
|
||||||
pub fn brightness(brightness: u8) -> Result<Arc<Self>, ServicePointError> {
|
pub fn brightness(brightness: u8) -> Result<Arc<Self>, ServicePointError> {
|
||||||
servicepoint::Brightness::try_from(brightness)
|
servicepoint::Brightness::try_from(brightness)
|
||||||
.map_err(move |value| ServicePointError::InvalidBrightness {
|
.map_err(move |value| ServicePointError::InvalidBrightness {
|
||||||
value,
|
value
|
||||||
})
|
})
|
||||||
.map(GlobalBrightnessCommand::from)
|
.map(GlobalBrightnessCommand::from)
|
||||||
.map(servicepoint::TypedCommand::Brightness)
|
.map(servicepoint::TypedCommand::Brightness)
|
||||||
|
@ -56,10 +59,8 @@ impl Command {
|
||||||
let actual = servicepoint::BitmapCommand {
|
let actual = servicepoint::BitmapCommand {
|
||||||
origin,
|
origin,
|
||||||
bitmap,
|
bitmap,
|
||||||
compression: servicepoint::CompressionCode::try_from(
|
compression: servicepoint::CompressionCode::try_from(compression as u16)
|
||||||
compression as u16,
|
.unwrap(),
|
||||||
)
|
|
||||||
.unwrap(),
|
|
||||||
};
|
};
|
||||||
Self::internal_new(actual.into())
|
Self::internal_new(actual.into())
|
||||||
}
|
}
|
||||||
|
@ -72,7 +73,7 @@ impl Command {
|
||||||
) -> Arc<Self> {
|
) -> Arc<Self> {
|
||||||
let origin = Origin::new(offset_x as usize, offset_y as usize);
|
let origin = Origin::new(offset_x as usize, offset_y as usize);
|
||||||
let grid = grid.actual.read().unwrap().clone();
|
let grid = grid.actual.read().unwrap().clone();
|
||||||
let actual = BrightnessGridCommand { origin, grid };
|
let actual = BrightnessGridCommand {origin, grid};
|
||||||
Self::internal_new(actual.into())
|
Self::internal_new(actual.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,18 +88,14 @@ impl Command {
|
||||||
let actual = BitVecCommand {
|
let actual = BitVecCommand {
|
||||||
offset: offset as usize,
|
offset: offset as usize,
|
||||||
bitvec,
|
bitvec,
|
||||||
compression: servicepoint::CompressionCode::try_from(
|
compression: servicepoint::CompressionCode::try_from(compression as u16)
|
||||||
compression as u16,
|
|
||||||
)
|
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
operation: match operation {
|
operation: match operation {
|
||||||
BinaryOperation::Overwrite => {
|
BinaryOperation::Overwrite => servicepoint::BinaryOperation::Overwrite,
|
||||||
servicepoint::BinaryOperation::Overwrite
|
|
||||||
}
|
|
||||||
BinaryOperation::And => servicepoint::BinaryOperation::And,
|
BinaryOperation::And => servicepoint::BinaryOperation::And,
|
||||||
BinaryOperation::Or => servicepoint::BinaryOperation::Or,
|
BinaryOperation::Or => servicepoint::BinaryOperation::Or,
|
||||||
BinaryOperation::Xor => servicepoint::BinaryOperation::Xor,
|
BinaryOperation::Xor => servicepoint::BinaryOperation::Xor,
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
Self::internal_new(actual.into())
|
Self::internal_new(actual.into())
|
||||||
}
|
}
|
||||||
|
@ -111,7 +108,7 @@ impl Command {
|
||||||
) -> Arc<Self> {
|
) -> Arc<Self> {
|
||||||
let origin = Origin::new(offset_x as usize, offset_y as usize);
|
let origin = Origin::new(offset_x as usize, offset_y as usize);
|
||||||
let grid = grid.actual.read().unwrap().clone();
|
let grid = grid.actual.read().unwrap().clone();
|
||||||
let actual = Cp437GridCommand { origin, grid };
|
let actual = Cp437GridCommand {origin, grid};
|
||||||
Self::internal_new(actual.into())
|
Self::internal_new(actual.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,12 +120,17 @@ impl Command {
|
||||||
) -> Arc<Self> {
|
) -> Arc<Self> {
|
||||||
let origin = Origin::new(offset_x as usize, offset_y as usize);
|
let origin = Origin::new(offset_x as usize, offset_y as usize);
|
||||||
let grid = grid.actual.read().unwrap().clone();
|
let grid = grid.actual.read().unwrap().clone();
|
||||||
let actual = CharGridCommand { origin, grid };
|
let actual = CharGridCommand {origin, grid};
|
||||||
Self::internal_new(actual.into())
|
Self::internal_new(actual.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[uniffi::constructor]
|
||||||
|
pub fn clone(other: &Arc<Self>) -> Arc<Self> {
|
||||||
|
Self::internal_new(other.actual.clone())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn equals(&self, other: &Command) -> bool {
|
pub fn equals(&self, other: &Command) -> bool {
|
||||||
*self.actual.read().unwrap() == *other.actual.read().unwrap()
|
self.actual == other.actual
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
macro_rules! command_code_only_command {
|
|
||||||
($command_struct:ident) => {
|
|
||||||
#[derive(uniffi::Object)]
|
|
||||||
pub struct $command_struct;
|
|
||||||
|
|
||||||
#[uniffi::export]
|
|
||||||
impl $command_struct {
|
|
||||||
#[uniffi::constructor]
|
|
||||||
pub fn new() -> Arc<Self> {
|
|
||||||
const _: () =
|
|
||||||
assert!(size_of::<servicepoint::$command_struct>() == 0);
|
|
||||||
Arc::new($command_struct)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
command_code_only_command!(ClearCommand);
|
|
||||||
command_code_only_command!(HardResetCommand);
|
|
||||||
command_code_only_command!(BitmapLegacyCommand);
|
|
||||||
command_code_only_command!(FadeOutCommand);
|
|
|
@ -1,3 +0,0 @@
|
||||||
pub mod command;
|
|
||||||
|
|
||||||
pub mod cc_only;
|
|
|
@ -1,6 +1,12 @@
|
||||||
use crate::{commands::command::Command, errors::ServicePointError};
|
use std::{
|
||||||
|
net::UdpSocket,
|
||||||
|
sync::Arc
|
||||||
|
};
|
||||||
use servicepoint::UdpSocketExt;
|
use servicepoint::UdpSocketExt;
|
||||||
use std::{net::UdpSocket, sync::Arc};
|
use crate::{
|
||||||
|
command::Command,
|
||||||
|
errors::ServicePointError
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(uniffi::Object)]
|
#[derive(uniffi::Object)]
|
||||||
pub struct Connection {
|
pub struct Connection {
|
||||||
|
@ -19,10 +25,10 @@ impl Connection {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send(&self, command: Arc<Command>) -> Result<(), ServicePointError> {
|
pub fn send(&self, command: Arc<Command>) -> Result<(), ServicePointError> {
|
||||||
self.actual
|
self.actual.send_command(command.actual.clone()).ok_or_else(|| {
|
||||||
.send_command(command.actual.read().unwrap().clone())
|
ServicePointError::IoError {
|
||||||
.ok_or_else(|| ServicePointError::IoError {
|
|
||||||
error: "send failed".to_string(),
|
error: "send failed".to_string(),
|
||||||
})
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
use crate::macros::*;
|
|
||||||
use servicepoint::Grid;
|
|
||||||
use std::{ops::Deref, sync::Arc};
|
|
||||||
|
|
||||||
wrap_uniffi_object!(Bitmap);
|
|
||||||
wrap_width_height!(Bitmap);
|
|
||||||
wrap_get_set_fill_2d!(Bitmap, bool);
|
|
||||||
|
|
||||||
#[uniffi::export]
|
|
||||||
impl Bitmap {
|
|
||||||
#[uniffi::constructor]
|
|
||||||
pub fn new(width: u64, height: u64) -> Arc<Self> {
|
|
||||||
Self::internal_new(
|
|
||||||
servicepoint::Bitmap::new(width as usize, height as usize).unwrap(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[uniffi::constructor]
|
|
||||||
pub fn new_max_sized() -> Arc<Self> {
|
|
||||||
Self::internal_new(servicepoint::Bitmap::max_sized())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[uniffi::constructor]
|
|
||||||
pub fn load(width: u64, height: u64, data: Vec<u8>) -> Arc<Self> {
|
|
||||||
Self::internal_new(
|
|
||||||
servicepoint::Bitmap::load(width as usize, height as usize, &data)
|
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn equals(&self, other: &Bitmap) -> bool {
|
|
||||||
let a = self.actual.read().unwrap();
|
|
||||||
let b = other.actual.read().unwrap();
|
|
||||||
*a == *b
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn copy_raw(&self) -> Vec<u8> {
|
|
||||||
self.actual.read().unwrap().deref().into()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
use crate::macros::*;
|
|
||||||
use servicepoint::{Brightness, Grid};
|
|
||||||
use std::{ops::Deref, sync::Arc};
|
|
||||||
|
|
||||||
wrap_uniffi_object!(BrightnessGrid);
|
|
||||||
wrap_width_height!(BrightnessGrid);
|
|
||||||
wrap_get_set_fill_2d!(BrightnessGrid, Brightness);
|
|
||||||
|
|
||||||
#[uniffi::export]
|
|
||||||
impl BrightnessGrid {
|
|
||||||
#[uniffi::constructor]
|
|
||||||
pub fn new(width: u64, height: u64) -> Arc<Self> {
|
|
||||||
Self::internal_new(servicepoint::BrightnessGrid::new(
|
|
||||||
width as usize,
|
|
||||||
height as usize,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[uniffi::constructor]
|
|
||||||
pub fn load(width: u64, height: u64, data: Vec<u8>) -> Arc<Self> {
|
|
||||||
Self::internal_new(
|
|
||||||
servicepoint::BrightnessGrid::saturating_load(
|
|
||||||
width as usize,
|
|
||||||
height as usize,
|
|
||||||
&data,
|
|
||||||
)
|
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn equals(&self, other: &BrightnessGrid) -> bool {
|
|
||||||
let a = self.actual.read().unwrap();
|
|
||||||
let b = other.actual.read().unwrap();
|
|
||||||
*a == *b
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn copy_raw(&self) -> Vec<u8> {
|
|
||||||
self.actual.read().unwrap().deref().into()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
use crate::{containers::char_grid::CharGrid, macros::*};
|
|
||||||
use servicepoint::Grid;
|
|
||||||
use std::{ops::Deref, sync::Arc};
|
|
||||||
|
|
||||||
wrap_uniffi_object!(Cp437Grid);
|
|
||||||
wrap_width_height!(Cp437Grid);
|
|
||||||
wrap_get_set_fill_2d!(Cp437Grid, u8);
|
|
||||||
|
|
||||||
#[uniffi::export]
|
|
||||||
impl Cp437Grid {
|
|
||||||
#[uniffi::constructor]
|
|
||||||
pub fn new(width: u64, height: u64) -> Arc<Self> {
|
|
||||||
Self::internal_new(servicepoint::Cp437Grid::new(
|
|
||||||
width as usize,
|
|
||||||
height as usize,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[uniffi::constructor]
|
|
||||||
pub fn load(width: u64, height: u64, data: Vec<u8>) -> Arc<Self> {
|
|
||||||
Self::internal_new(
|
|
||||||
servicepoint::Cp437Grid::load(
|
|
||||||
width as usize,
|
|
||||||
height as usize,
|
|
||||||
&data,
|
|
||||||
)
|
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn equals(&self, other: &Cp437Grid) -> bool {
|
|
||||||
let a = self.actual.read().unwrap();
|
|
||||||
let b = other.actual.read().unwrap();
|
|
||||||
*a == *b
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn copy_raw(&self) -> Vec<u8> {
|
|
||||||
self.actual.read().unwrap().deref().into()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_utf8(&self) -> Arc<CharGrid> {
|
|
||||||
CharGrid::internal_new(servicepoint::CharGrid::from(
|
|
||||||
&*self.actual.read().unwrap(),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
pub mod bitmap;
|
|
||||||
pub mod bitvec;
|
|
||||||
pub mod brightness_grid;
|
|
||||||
pub mod char_grid;
|
|
||||||
pub mod cp437_grid;
|
|
79
src/cp437_grid.rs
Normal file
79
src/cp437_grid.rs
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
use crate::char_grid::CharGrid;
|
||||||
|
use servicepoint::{DataRef, Grid};
|
||||||
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
|
#[derive(uniffi::Object)]
|
||||||
|
pub struct Cp437Grid {
|
||||||
|
pub(crate) actual: RwLock<servicepoint::Cp437Grid>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Cp437Grid {
|
||||||
|
pub(crate) fn internal_new(actual: servicepoint::Cp437Grid) -> Arc<Self> {
|
||||||
|
Arc::new(Self {
|
||||||
|
actual: RwLock::new(actual),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[uniffi::export]
|
||||||
|
impl Cp437Grid {
|
||||||
|
#[uniffi::constructor]
|
||||||
|
pub fn new(width: u64, height: u64) -> Arc<Self> {
|
||||||
|
Self::internal_new(servicepoint::Cp437Grid::new(
|
||||||
|
width as usize,
|
||||||
|
height as usize,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[uniffi::constructor]
|
||||||
|
pub fn load(width: u64, height: u64, data: Vec<u8>) -> Arc<Self> {
|
||||||
|
Self::internal_new(servicepoint::Cp437Grid::load(
|
||||||
|
width as usize,
|
||||||
|
height as usize,
|
||||||
|
&data,
|
||||||
|
).unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[uniffi::constructor]
|
||||||
|
pub fn clone(other: &Arc<Self>) -> Arc<Self> {
|
||||||
|
Self::internal_new(other.actual.read().unwrap().clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set(&self, x: u64, y: u64, value: u8) {
|
||||||
|
self.actual
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.set(x as usize, y as usize, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get(&self, x: u64, y: u64) -> u8 {
|
||||||
|
self.actual.read().unwrap().get(x as usize, y as usize)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn fill(&self, value: u8) {
|
||||||
|
self.actual.write().unwrap().fill(value)
|
||||||
|
}
|
||||||
|
pub fn width(&self) -> u64 {
|
||||||
|
self.actual.read().unwrap().width() as u64
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn height(&self) -> u64 {
|
||||||
|
self.actual.read().unwrap().height() as u64
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn equals(&self, other: &Cp437Grid) -> bool {
|
||||||
|
let a = self.actual.read().unwrap();
|
||||||
|
let b = other.actual.read().unwrap();
|
||||||
|
*a == *b
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn copy_raw(&self) -> Vec<u8> {
|
||||||
|
self.actual.read().unwrap().data_ref().to_vec()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_utf8(&self) -> Arc<CharGrid> {
|
||||||
|
CharGrid::internal_new(servicepoint::CharGrid::from(
|
||||||
|
&*self.actual.read().unwrap(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
10
src/lib.rs
10
src/lib.rs
|
@ -1,10 +1,12 @@
|
||||||
uniffi::setup_scaffolding!();
|
uniffi::setup_scaffolding!();
|
||||||
|
|
||||||
mod brightness;
|
mod bitmap;
|
||||||
mod commands;
|
mod bitvec;
|
||||||
|
mod brightness_grid;
|
||||||
|
mod char_grid;
|
||||||
|
mod command;
|
||||||
mod compression_code;
|
mod compression_code;
|
||||||
mod connection;
|
mod connection;
|
||||||
mod constants;
|
mod constants;
|
||||||
mod containers;
|
mod cp437_grid;
|
||||||
mod errors;
|
mod errors;
|
||||||
mod macros;
|
|
||||||
|
|
|
@ -1,72 +0,0 @@
|
||||||
macro_rules! wrap_uniffi_object {
|
|
||||||
($orig_t:ident, $new_t:ident) => {
|
|
||||||
#[derive(uniffi::Object)]
|
|
||||||
pub struct $new_t {
|
|
||||||
pub(crate) actual: std::sync::RwLock<servicepoint::$orig_t>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl $new_t {
|
|
||||||
pub(crate) fn internal_new(
|
|
||||||
actual: servicepoint::$orig_t,
|
|
||||||
) -> Arc<Self> {
|
|
||||||
Arc::new(Self {
|
|
||||||
actual: std::sync::RwLock::new(actual),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[uniffi::export]
|
|
||||||
impl $new_t {
|
|
||||||
#[uniffi::constructor]
|
|
||||||
pub fn clone(other: &Arc<Self>) -> Arc<Self> {
|
|
||||||
Self::internal_new(other.actual.read().unwrap().clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
($t:ident) => {
|
|
||||||
wrap_uniffi_object!($t, $t);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) use wrap_uniffi_object;
|
|
||||||
|
|
||||||
macro_rules! wrap_width_height {
|
|
||||||
($t:ident) => {
|
|
||||||
#[uniffi::export]
|
|
||||||
impl $t {
|
|
||||||
pub fn width(&self) -> u64 {
|
|
||||||
self.actual.read().unwrap().width() as u64
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn height(&self) -> u64 {
|
|
||||||
self.actual.read().unwrap().height() as u64
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) use wrap_width_height;
|
|
||||||
|
|
||||||
macro_rules! wrap_get_set_fill_2d {
|
|
||||||
($t:ident, $contained:ident) => {
|
|
||||||
#[uniffi::export]
|
|
||||||
impl $t {
|
|
||||||
pub fn set(&self, x: u64, y: u64, value: $contained) {
|
|
||||||
self.actual
|
|
||||||
.write()
|
|
||||||
.unwrap()
|
|
||||||
.set(x as usize, y as usize, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get(&self, x: u64, y: u64) -> $contained {
|
|
||||||
self.actual.read().unwrap().get(x as usize, y as usize)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn fill(&self, value: $contained) {
|
|
||||||
self.actual.write().unwrap().fill(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) use wrap_get_set_fill_2d;
|
|
Loading…
Reference in a new issue