mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2024-09-24 12:30:17 +00:00
b99f217b25
- removed 'in their value' from text - elaborate a bit more on the type level diff between `[b'H', b'i']` and `b"Hi"` - note that not being fully 802.15.4 compliant is not an issue for the workshop exercises - use `b'A'` syntax in hints now that it has been covered early on - use large enough capacity in hints - for consistency, set channel first thing in all hints
33 lines
819 B
Rust
33 lines
819 B
Rust
#![deny(unused_must_use)]
|
|
#![no_main]
|
|
#![no_std]
|
|
|
|
use core::str;
|
|
|
|
use cortex_m_rt::entry;
|
|
use heapless::{consts, Vec};
|
|
use panic_log as _; // the panicking behavior
|
|
|
|
#[entry]
|
|
fn main() -> ! {
|
|
dk::init().unwrap();
|
|
|
|
// a buffer with capacity for 2 bytes
|
|
let mut buffer = Vec::<u8, consts::U2>::new();
|
|
// ^^ capacity; this is a type not a value
|
|
|
|
// do some insertions
|
|
buffer.push(b'H').expect("buffer full");
|
|
buffer.push(b'i').expect("buffer full");
|
|
|
|
// look into the contents so far
|
|
log::info!("{:?}", buffer);
|
|
// or more readable
|
|
// NOTE as long as you only push bytes in the ASCII range (0..=127) the conversion should work
|
|
log::info!(
|
|
"{}",
|
|
str::from_utf8(&buffer).expect("content was not UTF-8")
|
|
);
|
|
|
|
dk::exit()
|
|
}
|