Skip to content

Commit

Permalink
Merge pull request #13 from cccb/fonts
Browse files Browse the repository at this point in the history
More CP437, PrimitiveGrid::map, renamings
  • Loading branch information
kaesaecracker authored Oct 16, 2024
2 parents dbbe631 + 28f2720 commit 30d74ff
Show file tree
Hide file tree
Showing 45 changed files with 2,396 additions and 1,557 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = [
]

[workspace.package]
version = "0.9.1"
version = "0.10.0"

[workspace.lints.rust]
missing-docs = "warn"
2 changes: 1 addition & 1 deletion crates/servicepoint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cargo add servicepoint
or
```toml
[dependencies]
servicepoint = "0.9.1"
servicepoint = "0.10.0"
```

## Examples
Expand Down
28 changes: 17 additions & 11 deletions crates/servicepoint/examples/announce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,26 @@ use servicepoint::{CharGrid, Command, Connection, Cp437Grid, Origin};

#[derive(Parser, Debug)]
struct Cli {
#[arg(short, long, default_value = "localhost:2342")]
#[arg(
short,
long,
default_value = "localhost:2342",
help = "Address of the display"
)]
destination: String,
#[arg(short, long, num_args = 1.., value_delimiter = '\n')]
#[arg(short, long, num_args = 1.., value_delimiter = '\n',
help = "Text to send - specify multiple times for multiple lines")]
text: Vec<String>,
#[arg(short, long, default_value_t = true)]
#[arg(
short,
long,
default_value_t = true,
help = "Clear screen before sending text"
)]
clear: bool,
}

/// example: `cargo run -- --text "Hallo,
/// CCCB"`
/// example: `cargo run -- --text "Hallo" --text "CCCB"`
fn main() {
let mut cli = Cli::parse();
if cli.text.is_empty() {
Expand All @@ -31,15 +41,11 @@ fn main() {
.expect("sending clear failed");
}

let text = cli.text.iter().fold(String::new(), move |str, line| {
let is_first = str.is_empty();
str + if is_first { "" } else { "\n" } + line
});

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

connection
.send(Command::Cp437Data(Origin::new(0, 0), cp437_grid))
.send(Command::Cp437Data(Origin::ZERO, cp437_grid))
.expect("sending text failed");
}
11 changes: 6 additions & 5 deletions crates/servicepoint/examples/brightness_tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@ fn main() {
let connection = Connection::open(cli.destination)
.expect("could not connect to display");

let mut pixels = PixelGrid::max_sized();
let mut pixels = Bitmap::max_sized();
pixels.fill(true);

let command = Command::BitmapLinearWin(
Origin::new(0, 0),
Origin::ZERO,
pixels,
CompressionCode::Uncompressed,
);
connection.send(command).expect("send failed");

let max_brightness = usize::from(u8::from(Brightness::MAX));
let max_brightness: u8 = Brightness::MAX.into();
let mut brightnesses = BrightnessGrid::new(TILE_WIDTH, TILE_HEIGHT);
for (index, byte) in brightnesses.data_ref_mut().iter_mut().enumerate() {
*byte = Brightness::try_from((index % max_brightness) as u8).unwrap();
let level = index as u8 % max_brightness;
*byte = Brightness::try_from(level).unwrap();
}

connection
.send(Command::CharBrightness(Origin::new(0, 0), brightnesses))
.send(Command::CharBrightness(Origin::ZERO, brightnesses))
.expect("send failed");
}
10 changes: 5 additions & 5 deletions crates/servicepoint/examples/game_of_life.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() {

loop {
let command = Command::BitmapLinearWin(
Origin::new(0, 0),
Origin::ZERO,
field.clone(),
CompressionCode::Lzma,
);
Expand All @@ -34,7 +34,7 @@ fn main() {
}
}

fn iteration(field: PixelGrid) -> PixelGrid {
fn iteration(field: Bitmap) -> Bitmap {
let mut next = field.clone();
for x in 0..field.width() {
for y in 0..field.height() {
Expand All @@ -51,7 +51,7 @@ fn iteration(field: PixelGrid) -> PixelGrid {
next
}

fn count_neighbors(field: &PixelGrid, x: i32, y: i32) -> i32 {
fn count_neighbors(field: &Bitmap, x: i32, y: i32) -> i32 {
let mut count = 0;
for nx in x - 1..=x + 1 {
for ny in y - 1..=y + 1 {
Expand All @@ -78,8 +78,8 @@ fn count_neighbors(field: &PixelGrid, x: i32, y: i32) -> i32 {
count
}

fn make_random_field(probability: f64) -> PixelGrid {
let mut field = PixelGrid::max_sized();
fn make_random_field(probability: f64) -> Bitmap {
let mut field = Bitmap::max_sized();
let mut rng = rand::thread_rng();
let d = distributions::Bernoulli::new(probability).unwrap();
for x in 0..field.width() {
Expand Down
4 changes: 2 additions & 2 deletions crates/servicepoint/examples/moving_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() {
let connection = Connection::open(Cli::parse().destination)
.expect("could not connect to display");

let mut pixels = PixelGrid::max_sized();
let mut pixels = Bitmap::max_sized();
for x_offset in 0..usize::MAX {
pixels.fill(false);

Expand All @@ -25,7 +25,7 @@ fn main() {
}

let command = Command::BitmapLinearWin(
Origin::new(0, 0),
Origin::ZERO,
pixels.clone(),
CompressionCode::Lzma,
);
Expand Down
4 changes: 2 additions & 2 deletions crates/servicepoint/examples/random_brightness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ fn main() {

// put all pixels in on state
if cli.enable_all {
let mut filled_grid = PixelGrid::max_sized();
let mut filled_grid = Bitmap::max_sized();
filled_grid.fill(true);

let command = BitmapLinearWin(
Origin::new(0, 0),
Origin::ZERO,
filled_grid,
CompressionCode::Lzma,
);
Expand Down
4 changes: 2 additions & 2 deletions crates/servicepoint/examples/websocket.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Example for how to use the WebSocket connection

use servicepoint::{
Command, CompressionCode, Connection, Grid, Origin, PixelGrid,
Bitmap, Command, CompressionCode, Connection, Grid, Origin,
};

fn main() {
Expand All @@ -13,7 +13,7 @@ fn main() {
// use send_mut instead of send
connection.send_mut(Command::Clear).unwrap();

let mut pixels = PixelGrid::max_sized();
let mut pixels = Bitmap::max_sized();
pixels.fill(true);

// use send_mut instead of send
Expand Down
2 changes: 1 addition & 1 deletion crates/servicepoint/examples/wiping_clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() {
let connection = Connection::open(cli.destination)
.expect("could not connect to display");

let mut enabled_pixels = PixelGrid::new(PIXEL_WIDTH, PIXEL_HEIGHT);
let mut enabled_pixels = Bitmap::max_sized();
enabled_pixels.fill(true);

for x_offset in 0..PIXEL_WIDTH {
Expand Down
Loading

0 comments on commit 30d74ff

Please sign in to comment.