Utils: Introduce utils and animation helpers
The next commit implements the LCD and animation support. To enable an easy way to create animations for it, add details in the README regarding the way the SD card is used and how the files need to be formatted. Create the Utils directory and add a Rust project to do the bit flipping and a script that automates all the steps described in the README. Add a README for Utils explaining how to use them.
This commit is contained in:
parent
6c5a670366
commit
e21123538b
8 changed files with 274 additions and 0 deletions
1
Utils/bitmap_helper/.gitignore
vendored
Normal file
1
Utils/bitmap_helper/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
7
Utils/bitmap_helper/Cargo.lock
generated
Normal file
7
Utils/bitmap_helper/Cargo.lock
generated
Normal file
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "bitmap_helper"
|
||||
version = "0.1.0"
|
8
Utils/bitmap_helper/Cargo.toml
Normal file
8
Utils/bitmap_helper/Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "bitmap_helper"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
51
Utils/bitmap_helper/src/main.rs
Normal file
51
Utils/bitmap_helper/src/main.rs
Normal file
|
@ -0,0 +1,51 @@
|
|||
use std::fs::File;
|
||||
use std::fs::write;
|
||||
use std::env;
|
||||
use std::io::Read;
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
for arg in &args[1..] {
|
||||
println!("Processing : {}", arg);
|
||||
if !arg.ends_with(".mono") {
|
||||
eprintln!("{} : unsupported file type.", arg);
|
||||
continue;
|
||||
}
|
||||
let file_r = File::open(arg);
|
||||
if file_r.is_err() {
|
||||
eprintln!("{} : could not open file.", arg);
|
||||
continue;
|
||||
}
|
||||
let mut image_data = vec![];
|
||||
if file_r.unwrap().read_to_end(&mut image_data).is_err() {
|
||||
eprintln!("{} : could not read file.", arg);
|
||||
continue;
|
||||
}
|
||||
|
||||
let out_file = arg.replace(".mono", ".bin");
|
||||
flip_bits(&mut image_data);
|
||||
if write(&out_file, &image_data).is_err() {
|
||||
eprintln!("Failed to write bit flipped bitmap to file : {}", out_file);
|
||||
}
|
||||
println!("Processing successful, flipped bits and wrote to {}", out_file);
|
||||
}
|
||||
}
|
||||
|
||||
/// Flips the bits of each individual byte (except zeroes).
|
||||
/// This would transform 0b11001100 in 0b00110011.
|
||||
fn flip_bits(data: &mut Vec<u8>) {
|
||||
for source_id in 0..data.len() {
|
||||
let mut new_int = 0;
|
||||
for i in 0..8 {
|
||||
if data[source_id] == 0 { break; }
|
||||
new_int |= ((data[source_id] & (1 << 7 - i)) >> 7 - i) << i;
|
||||
}
|
||||
data[source_id] = new_int;
|
||||
}
|
||||
// for i in 0..data.len() {
|
||||
// print!("{:2X}", data[i]);
|
||||
// if i > 0 && i%16 == 0 { println!(); }
|
||||
// }
|
||||
// println!();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue