Skip to content
Snippets Groups Projects
Commit fd8f8fc6 authored by Stephen D's avatar Stephen D
Browse files

initial commit. untested

parents
No related branches found
No related tags found
No related merge requests found
/target
This diff is collapsed.
[package]
name = "img2gcode"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow = "1.0.97"
image = "0.25.5"
use anyhow::bail;
use image::{GenericImageView, ImageReader};
const TOAST_TIME_SECONDS: u64 = 60;
const CENTER_X: u32 = 100;
const CENTER_Y: u32 = 100;
const BREAD_HEIGHT: f64 = 15.5;
const IDLE_HEIGHT: f64 = BREAD_HEIGHT + 10.0;
const PIXEL_SIZE_MM: f64 = 2.0;
fn main() -> anyhow::Result<()> {
let img = ImageReader::open("/home/stephen/Downloads/qr_tiny.png")?.decode()?;
preamble();
for x in 0..img.width() {
for y in 0..img.height() {
let p = img.get_pixel(x, y);
match p.0 {
[0, 0, 0, 255] => {
// nothing, for now
}
[255, 255, 255, 255] => {
toast(x, y);
}
_ => bail!("Pixel was not entirely black nor entirely white: {:?}", p),
}
}
}
Ok(())
}
fn preamble() {
println!(
r#"
G28 ; home
M109 S220 ; heat hotend to 220C and wait
G90 ; absolute positioning
G0 Z{IDLE_HEIGHT}
G0 X{CENTER_X} Y{CENTER_Y}
"#
);
}
fn toast(x: u32, y: u32) {
println!(
r#"
G0 X{:.2} Y{:.2};
G0 Z{BREAD_HEIGHT};
G4 S{TOAST_TIME_SECONDS} ; wait
G0 Z{IDLE_HEIGHT};
"#,
x as f64 * PIXEL_SIZE_MM,
y as f64 * PIXEL_SIZE_MM
);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment