Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .cargo/config.toml

This file was deleted.

4 changes: 2 additions & 2 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 @@ -5,7 +5,7 @@ rust-version = "1.80.0"
edition = "2021"

[dependencies]
firefly-rust = { version = "0.9.0", default-features = false }
firefly-rust = { version = "0.9.3", default-features = false }

# https://github.com/johnthagen/min-sized-rust
[profile.release]
Expand Down
3 changes: 3 additions & 0 deletions firefly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ author_id = "sys"
app_id = "input-test"
author_name = "System"
app_name = "Input test"

[files]
font = { url = "https://fonts.fireflyzero.com/fonts/ascii/eg_6x12.fff", path = "eg6x12.fff" }
114 changes: 66 additions & 48 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,55 @@
#![no_std]
#![no_main]
#![expect(static_mut_refs)]
use firefly_rust::*;

pub const WIDTH: usize = 240;
pub const HEIGHT: usize = 160;
const PAD_RADIUS: i32 = 60;
const TOUCH_RADIUS: i32 = 10;

const ME_COLOR: Color = Color::DarkBlue;
const PEER_COLOR: Color = Color::Blue;
const COMBINED_COLOR: Color = Color::LightBlue;
const ME_COLOR: Color = Color::LightGreen;
const PEER_COLOR: Color = Color::Green;
const COMBINED_COLOR: Color = Color::Black;

const S: Point = Point { x: 160, y: 100 };
const E: Point = Point { x: 190, y: 90 };
const W: Point = Point { x: 160, y: 70 };
const N: Point = Point { x: 190, y: 60 };
const S: Point = Point { x: 180, y: 95 };
const E: Point = Point { x: 200, y: 75 };
const W: Point = Point { x: 160, y: 75 };
const N: Point = Point { x: 180, y: 55 };

static mut FONT_BUF: [u8; 871] = [0; 871];
static mut FONT: Option<File<'static>> = None;

#[no_mangle]
extern "C" fn boot() {
unsafe {
let file = load_file("font", &mut FONT_BUF);
FONT = Some(file);
}
}

#[no_mangle]
extern "C" fn render() {
clear_screen(Color::White);
draw_pad_bg();
draw_buttons_bg();
draw_pad();
draw_buttons();
}

fn draw_pad() {
draw_combined_pad();
let me = get_me();
let peers = get_peers();
for peer in peers {
draw_peer_pad(peer, peer == me);
}
draw_combined_pad();
}

fn draw_combined_pad() {
let Some(pad) = read_pad(Peer::COMBINED) else {
return;
};
let style = Style {
fill_color: COMBINED_COLOR,
stroke_color: Color::None,
fill_color: Color::None,
stroke_color: COMBINED_COLOR,
stroke_width: 2,
};
draw_touch(pad, style);
Expand All @@ -52,8 +61,8 @@ fn draw_peer_pad(peer: Peer, is_me: bool) {
};
let color = if is_me { ME_COLOR } else { PEER_COLOR };
let style = Style {
fill_color: Color::None,
stroke_color: color,
fill_color: color,
stroke_color: Color::LightGray,
stroke_width: 2,
};
draw_touch(pad, style);
Expand Down Expand Up @@ -101,64 +110,73 @@ fn draw_buttons() {

fn draw_combined_buttons() {
let buttons = read_buttons(Peer::COMBINED);
draw_button(S, "S", buttons.s);
draw_button(E, "E", buttons.e);
draw_button(W, "W", buttons.w);
draw_button(N, "N", buttons.n);
}

fn draw_button(p: Point, name: &str, pressed: bool) {
let style = Style {
fill_color: COMBINED_COLOR,
stroke_color: Color::None,
fill_color: Color::White,
stroke_color: Color::Black,
stroke_width: 2,
};
if buttons.s {
draw_circle(S, TOUCH_RADIUS * 2, style)
}
if buttons.e {
draw_circle(E, TOUCH_RADIUS * 2, style)
}
if buttons.w {
draw_circle(W, TOUCH_RADIUS * 2, style)
}
if buttons.n {
draw_circle(N, TOUCH_RADIUS * 2, style)
let shadow = Style {
fill_color: Color::Black,
stroke_color: Color::Black,
stroke_width: 2,
};
let shift = Point::new(1, 1);

if pressed {
draw_circle(p, TOUCH_RADIUS * 2, style);
} else {
draw_circle(p, TOUCH_RADIUS * 2, shadow);
draw_circle(p - shift, TOUCH_RADIUS * 2, style);
}
draw_button_name(p - shift, name)
}

fn draw_button_name(p: Point, name: &str) {
let font = unsafe { FONT.as_ref().unwrap() };
let font = font.as_font();
let text_shift = Point::new(8, 12);
draw_text(name, &font, p + text_shift, Color::Black);
}

fn draw_peer_buttons(peer: Peer, is_me: bool) {
let buttons = read_buttons(peer);
let stroke_color = if is_me { ME_COLOR } else { PEER_COLOR };
let fill_color = if is_me { ME_COLOR } else { PEER_COLOR };
let style = Style {
fill_color: Color::None,
stroke_color,
fill_color,
stroke_color: Color::Black,
stroke_width: 2,
};
if buttons.s {
draw_circle(S, TOUCH_RADIUS * 2, style)
draw_circle(S, TOUCH_RADIUS * 2, style);
draw_button_name(S, "S");
}
if buttons.e {
draw_circle(E, TOUCH_RADIUS * 2, style)
draw_circle(E, TOUCH_RADIUS * 2, style);
draw_button_name(E, "E");
}
if buttons.w {
draw_circle(W, TOUCH_RADIUS * 2, style)
draw_circle(W, TOUCH_RADIUS * 2, style);
draw_button_name(W, "W");
}
if buttons.n {
draw_circle(N, TOUCH_RADIUS * 2, style)
draw_circle(N, TOUCH_RADIUS * 2, style);
draw_button_name(N, "N");
}
}

fn draw_pad_bg() {
let style = Style {
fill_color: Color::White,
stroke_color: Color::LightGray,
stroke_color: Color::Black,
stroke_width: 2,
};
draw_circle(Point::new(11, 11), PAD_RADIUS * 2, style);
draw_circle(Point::new(10, 10), PAD_RADIUS * 2, style);
}

fn draw_buttons_bg() {
let style = Style {
fill_color: Color::None,
stroke_color: Color::Gray,
stroke_width: 2,
};
draw_circle(S, TOUCH_RADIUS * 2, style);
draw_circle(E, TOUCH_RADIUS * 2, style);
draw_circle(W, TOUCH_RADIUS * 2, style);
draw_circle(N, TOUCH_RADIUS * 2, style);
}