-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: David Beechey <david@dtbeechey.dev>
- Loading branch information
1 parent
c892334
commit 0f1da38
Showing
10 changed files
with
1,084 additions
and
20 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[workspace] | ||
members = [ | ||
"lib/*", | ||
"config", | ||
] | ||
resolver = "2" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "hyped_core" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
defmt = "0.3" | ||
heapless = { version = "0.8", default-features = false, features = ["serde"] } | ||
rust-mqtt = { version = "0.3.0", default-features = false, features = ["defmt"] } | ||
embedded-io-async = { version = "0.6.1" } | ||
rand_core = "0.6.3" | ||
serde = { version = "1.0", default-features = false, features = ["derive"] } | ||
embassy-net = { version = "0.4.0", default-features = false, features = ["defmt", "tcp", "proto-ipv4", "medium-ip"] } | ||
|
||
[features] | ||
std = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use core::cmp::min; | ||
use core::fmt; | ||
|
||
pub struct FormatString<'a> { | ||
buffer: &'a mut [u8], | ||
used: usize, | ||
} | ||
|
||
impl<'a> FormatString<'a> { | ||
pub fn new(buffer: &'a mut [u8]) -> Self { | ||
FormatString { buffer, used: 0 } | ||
} | ||
|
||
pub fn as_str(self) -> Option<&'a str> { | ||
if self.used <= self.buffer.len() { | ||
use core::str::from_utf8; | ||
Some(from_utf8(&self.buffer[..self.used]).unwrap()) | ||
} else { | ||
None | ||
} | ||
} | ||
} | ||
|
||
impl<'a> fmt::Write for FormatString<'a> { | ||
fn write_str(&mut self, s: &str) -> fmt::Result { | ||
if self.used > self.buffer.len() { | ||
return Err(fmt::Error); | ||
} | ||
let remaining_buf = &mut self.buffer[self.used..]; | ||
let raw_s = s.as_bytes(); | ||
let write_num = min(raw_s.len(), remaining_buf.len()); | ||
remaining_buf[..write_num].copy_from_slice(&raw_s[..write_num]); | ||
self.used += raw_s.len(); | ||
if write_num < raw_s.len() { | ||
Err(fmt::Error) | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
} | ||
|
||
pub fn show<'a>(buffer: &'a mut [u8; 1024], args: fmt::Arguments) -> Result<&'a str, fmt::Error> { | ||
let mut w = FormatString::new(buffer); | ||
fmt::write(&mut w, args)?; | ||
w.as_str().ok_or(fmt::Error) | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! format { | ||
($buffer:expr, $($arg:tt)*) => { | ||
{ | ||
show(&mut $buffer, format_args!($($arg)*)) | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
pub mod format_string; | ||
pub mod log_types; | ||
pub mod mqtt; | ||
pub mod mqtt_topics; | ||
pub mod types; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#[derive(PartialEq, PartialOrd)] | ||
pub enum LogLevel { | ||
Debug = 0, | ||
Info = 1, | ||
Warn = 2, | ||
Error = 3, | ||
} | ||
|
||
pub enum LogTarget { | ||
Console, | ||
Mqtt, | ||
} |
Oops, something went wrong.