Skip to content

Commit

Permalink
more From for Cp437Grid and BitVec
Browse files Browse the repository at this point in the history
  • Loading branch information
kaesaecracker committed Nov 12, 2024
1 parent eb7496b commit ab16f57
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ version = "0.10.0"
missing-docs = "warn"

[workspace.dependencies]
thiserror = "1.0.69"
thiserror = "1.0.69"
6 changes: 3 additions & 3 deletions crates/servicepoint/examples/announce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ fn main() {
}

let text = cli.text.join("\n");
let grid = CharGrid::from(&*text);
let cp437_grid = Cp437Grid::from(&grid);
let grid = CharGrid::from(text);
let grid = Cp437Grid::from(grid);

connection
.send(Command::Cp437Data(Origin::ZERO, cp437_grid))
.send(Command::Cp437Data(Origin::ZERO, grid))
.expect("sending text failed");
}
6 changes: 1 addition & 5 deletions crates/servicepoint/examples/wiping_clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ fn main() {
enabled_pixels.set(x_offset % PIXEL_WIDTH, y, false);
}

// this works because the pixel grid has max size
let pixel_data: Vec<u8> = enabled_pixels.clone().into();
let bit_vec = BitVec::from_vec(pixel_data);

connection
.send(Command::BitmapLinearAnd(0, bit_vec, CompressionCode::Lzma))
.send(Command::BitmapLinearWin(Origin::ZERO, enabled_pixels.clone(), CompressionCode::Lzma))
.expect("could not send command to display");
thread::sleep(sleep_duration);
}
Expand Down
6 changes: 6 additions & 0 deletions crates/servicepoint/src/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ impl From<Bitmap> for Vec<u8> {
}
}

impl From<Bitmap> for BitVec {
fn from(value: Bitmap) -> Self {
value.bit_vec
}
}

pub struct IterRows<'t> {
bitmap: &'t Bitmap,
row: usize,
Expand Down
12 changes: 12 additions & 0 deletions crates/servicepoint/src/cp437.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ mod feature_cp437 {
}
}

impl From<CharGrid> for Cp437Grid {
fn from(value: CharGrid) -> Self {
Cp437Grid::from(&value)
}
}

impl From<&str> for CharGrid {
fn from(value: &str) -> Self {
let value = value.replace("\r\n", "\n");
Expand All @@ -166,6 +172,12 @@ mod feature_cp437 {
}
}

impl From<String> for CharGrid {
fn from(value: String) -> Self {
CharGrid::from(&value)
}
}

impl From<&CharGrid> for String {
fn from(value: &CharGrid) -> Self {
value
Expand Down

0 comments on commit ab16f57

Please sign in to comment.