Controller demo: Use State in queue
@@ -38,9 +38,9 @@ const APP: () = {
#[init([0; 32])]
mute_buf: [i16; 32],
#[init(None)]
- queue: Option<Queue<bool, U256>>,
- producer: Producer<'static, bool, U256>,
- consumer: Consumer<'static, bool, U256>,
+ queue: Option<Queue<State, U256>>,
+ producer: Producer<'static, State, U256>,
+ consumer: Consumer<'static, State, U256>,
#[init(5_000_000)]
speed: u32,
uarte: Uarte<UARTE0>,
@@ -135,15 +135,15 @@ const APP: () = {
uarte_timer,
producer,
} = ctx.resources;
- let uarte_rx_buf = &mut [0u8; 32][..];
+ let uarte_rx_buf = &mut [0u8; 64][..];
loop {
- match uarte.read_timeout(uarte_rx_buf, uarte_timer, 200_000) {
+ match uarte.read_timeout(uarte_rx_buf, uarte_timer, 100_000) {
Ok(_) => {
if let Ok(msg) = core::str::from_utf8(&uarte_rx_buf[..]) {
rprintln!("{}", msg);
for action in encode(msg) {
for _ in 0..action.duration {
- producer.enqueue(action.state == State::On).ok();
+ producer.enqueue(action.state).ok();
}
}
}
@@ -153,7 +153,7 @@ const APP: () = {
rprintln!("{}", msg);
for action in encode(msg) {
for _ in 0..action.duration {
- producer.enqueue(action.state == State::On).ok();
+ producer.enqueue(action.state).ok();
}
}
}
@@ -166,13 +166,13 @@ const APP: () = {
#[task(resources = [consumer, i2s, signal_buf, mute_buf, gpiote, speed], schedule = [tick])]
fn tick(ctx: tick::Context) {
let i2s = ctx.resources.i2s;
- if let Some(is_on) = ctx.resources.consumer.dequeue() {
- match is_on {
- true => {
+ if let Some(state) = ctx.resources.consumer.dequeue() {
+ match state {
+ State::On => {
i2s.tx_buffer(&ctx.resources.signal_buf[..]).ok();
ctx.resources.gpiote.channel0().clear();
}
- false => {
+ State::Off => {
i2s.tx_buffer(&ctx.resources.mute_buf[..]).ok();
ctx.resources.gpiote.channel0().set();
}
