use embassy_ssd1306_graphics::Graphics;
use embedded_hal_async::i2c::I2c;
#[inline]
pub fn segment<I: I2c>(
gfx: &mut Graphics<'_, I>,
x0: i32, y0: i32,
x1: i32, y1: i32,
on: bool,
) {
embassy_ssd1306_graphics::line(gfx, x0, y0, x1, y1, on);
}
#[inline]
pub fn filled_disk<I: I2c>(
gfx: &mut Graphics<'_, I>,
cx: i32, cy: i32, r: i32,
on: bool,
) {
embassy_ssd1306_graphics::fill_circle(gfx, cx, cy, r, on);
}
#[inline]
pub fn ring<I: I2c>(
gfx: &mut Graphics<'_, I>,
cx: i32, cy: i32, r: i32,
on: bool,
) {
embassy_ssd1306_graphics::circle(gfx, cx, cy, r, on);
}
#[inline]
pub fn filled_rect<I: I2c>(
gfx: &mut Graphics<'_, I>,
x: i32, y: i32, w: i32, h: i32,
on: bool,
) {
for dy in 0..h {
for dx in 0..w {
gfx.pixel(x + dx, y + dy, on);
}
}
}
#[inline]
pub fn polar_end(ox: i32, oy: i32, len: i32, cos_a: f32, sin_a: f32) -> (i32, i32) {
let x = ox + ((len as f32) * cos_a + 0.5) as i32;
let y = oy + ((len as f32) * sin_a + 0.5) as i32;
(x, y)
}
#[inline]
pub fn thick_segment<I: I2c>(
gfx: &mut Graphics<'_, I>,
x0: i32, y0: i32,
x1: i32, y1: i32,
on: bool,
) {
segment(gfx, x0, y0, x1, y1, on);
let dx = (x1 - x0).abs();
let dy = (y1 - y0).abs();
if dx >= dy {
segment(gfx, x0, y0 + 1, x1, y1 + 1, on);
} else {
segment(gfx, x0 + 1, y0, x1 + 1, y1, on);
}
}