Commit 051ca096 authored by Astro's avatar Astro
Browse files

revise leds api

parent 02d06b8f
Pipeline #1380 passed with stage
in 7 minutes
......@@ -7,24 +7,45 @@ extern {
fn leds_set_hsv(led: u8, h: f32, s: f32, v: f32);
}
pub const LEDS: u8 = 15;
pub struct Leds;
pub fn init() {
unsafe { leds_init(); }
}
impl Leds {
pub fn new() -> Self {
unsafe { leds_init(); }
Leds
}
pub fn update() {
unsafe { leds_update(); }
}
pub fn len(&self) -> usize {
15
}
pub fn led(&self, idx: usize) -> Led {
Led { idx }
}
pub fn set_dim(led: u8,dim: u8) {
unsafe { leds_set_dim(led, dim); }
pub fn iter(&self) -> impl Iterator<Item=Led> {
(0..self.len()).map(|idx| Led { idx })
}
pub fn update(&self) {
unsafe { leds_update(); }
}
}
pub fn set(led: u8,r: u8,g: u8,b: u8) {
unsafe { leds_set(led, r, g, b); }
pub struct Led {
idx: usize,
}
pub fn set_hsv(led: u8, h: f32, s: f32, v: f32) {
unsafe { leds_set_hsv(led, h, s, v); }
impl Led {
pub fn set_dim(&self, dim: u8) {
unsafe { leds_set_dim(self.idx as u8, dim); }
}
pub fn set(&self, r: u8, g: u8, b: u8) {
unsafe { leds_set(self.idx as u8, r, g, b); }
}
pub fn set_hsv(&self, h: f32, s: f32, v: f32) {
unsafe { leds_set_hsv(self.idx as u8, h, s, v); }
}
}
......@@ -2,13 +2,13 @@
#![no_main]
use panic_abort as _;
use card10::{entry, lcd, leds};
use card10::{entry, lcd, leds::Leds};
#[entry]
fn main() -> ! {
card10::init();
leds::init();
let leds = Leds::new();
lcd::set_backlight(1000);
let mut t = 0;
......@@ -24,10 +24,10 @@ fn main() -> ! {
}
lcd::update();
for led in 0..leds::LEDS {
leds::set(led, ((t << 2) & 0xFF) as u8, ((t << 1) & 0xFF) as u8, ((t >> 2) & 0xFF) as u8);
for led in leds.iter() {
led.set(((t << 2) & 0xFF) as u8, ((t << 1) & 0xFF) as u8, ((t >> 2) & 0xFF) as u8);
}
leds::update();
leds.update();
t += 1;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment