Skip to content

Commit

Permalink
Formatting and LF
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbeechey committed Oct 31, 2024
1 parent 5a8a3ba commit bc84ee6
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 87 deletions.
42 changes: 21 additions & 21 deletions boards/stm32h743zi/src/log.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use crate::tasks::mqtt_send_and_recv::SEND_CHANNEL;
use core::str::FromStr;
use defmt::{debug, error, info, warn};
use heapless::String;
use hyped_core::{log_types::LogLevel, mqtt::MqttMessage, mqtt_topics::MqttTopics};

/// Log a message to the console and send it to the MQTT broker
pub async fn log(level: LogLevel, message: &str) {
match level {
LogLevel::Info => info!("{}", message),
LogLevel::Warn => warn!("{}", message),
LogLevel::Error => error!("{}", message),
LogLevel::Debug => debug!("{}", message),
}
SEND_CHANNEL
.send(MqttMessage {
topic: MqttTopics::to_string(&MqttTopics::Logs),
payload: String::<512>::from_str(message).unwrap(),
})
.await;
}
use crate::tasks::mqtt_send_and_recv::SEND_CHANNEL;
use core::str::FromStr;
use defmt::{debug, error, info, warn};
use heapless::String;
use hyped_core::{log_types::LogLevel, mqtt::MqttMessage, mqtt_topics::MqttTopics};

/// Log a message to the console and send it to the MQTT broker
pub async fn log(level: LogLevel, message: &str) {
match level {
LogLevel::Info => info!("{}", message),
LogLevel::Warn => warn!("{}", message),
LogLevel::Error => error!("{}", message),
LogLevel::Debug => debug!("{}", message),
}
SEND_CHANNEL
.send(MqttMessage {
topic: MqttTopics::to_string(&MqttTopics::Logs),
payload: String::<512>::from_str(message).unwrap(),
})
.await;
}
130 changes: 65 additions & 65 deletions boards/stm32h743zi/src/tasks/test_mqtt_tasks.rs
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
use crate::log::log;
use core::str::FromStr;
use embassy_stm32::gpio::{AnyPin, Input, Pull};
use embassy_time::{Duration, Timer};
use heapless::String;
use hyped_core::{log_types::LogLevel, mqtt::MqttMessage, mqtt_topics::MqttTopics};
use serde::{Deserialize, Serialize};
use typenum::consts::*;

use super::mqtt_send_and_recv::SEND_CHANNEL;

use {defmt_rtt as _, panic_probe as _};

/// Struct to hold the state of the button
#[derive(Debug, Serialize, Deserialize)]
pub struct ButtonMqttMessage {
pub task_id: u8,
pub status: bool,
}

/// Sends the state of the button over MQTT
#[embassy_executor::task]
pub async fn button_task(pin: AnyPin) {
let button = Input::new(pin, Pull::Down);
loop {
SEND_CHANNEL
.send(MqttMessage {
topic: MqttTopics::to_string(&MqttTopics::Debug),
payload: String::<512>::from_str(
serde_json_core::to_string::<U512, ButtonMqttMessage>(&ButtonMqttMessage {
task_id: 0,
status: button.is_high(),
})
.unwrap()
.as_str(),
)
.unwrap(),
})
.await;
Timer::after(Duration::from_millis(100)).await;
}
}

/// Sends a ping MQTT message every five seconds
#[embassy_executor::task]
pub async fn five_seconds_task() {
loop {
log(LogLevel::Info, "Ping from five second loop").await;
SEND_CHANNEL
.send(MqttMessage {
topic: MqttTopics::to_string(&MqttTopics::Debug),
payload: String::<512>::from_str(
serde_json_core::to_string::<U512, ButtonMqttMessage>(&ButtonMqttMessage {
task_id: 2,
status: false,
})
.unwrap()
.as_str(),
)
.unwrap(),
})
.await;
Timer::after(Duration::from_secs(5)).await;
}
}
use crate::log::log;
use core::str::FromStr;
use embassy_stm32::gpio::{AnyPin, Input, Pull};
use embassy_time::{Duration, Timer};
use heapless::String;
use hyped_core::{log_types::LogLevel, mqtt::MqttMessage, mqtt_topics::MqttTopics};
use serde::{Deserialize, Serialize};
use typenum::consts::*;

use super::mqtt_send_and_recv::SEND_CHANNEL;

use {defmt_rtt as _, panic_probe as _};

/// Struct to hold the state of the button
#[derive(Debug, Serialize, Deserialize)]
pub struct ButtonMqttMessage {
pub task_id: u8,
pub status: bool,
}

/// Sends the state of the button over MQTT
#[embassy_executor::task]
pub async fn button_task(pin: AnyPin) {
let button = Input::new(pin, Pull::Down);
loop {
SEND_CHANNEL
.send(MqttMessage {
topic: MqttTopics::to_string(&MqttTopics::Debug),
payload: String::<512>::from_str(
serde_json_core::to_string::<U512, ButtonMqttMessage>(&ButtonMqttMessage {
task_id: 0,
status: button.is_high(),
})
.unwrap()
.as_str(),
)
.unwrap(),
})
.await;
Timer::after(Duration::from_millis(100)).await;
}
}

/// Sends a ping MQTT message every five seconds
#[embassy_executor::task]
pub async fn five_seconds_task() {
loop {
log(LogLevel::Info, "Ping from five second loop").await;
SEND_CHANNEL
.send(MqttMessage {
topic: MqttTopics::to_string(&MqttTopics::Debug),
payload: String::<512>::from_str(
serde_json_core::to_string::<U512, ButtonMqttMessage>(&ButtonMqttMessage {
task_id: 2,
status: false,
})
.unwrap()
.as_str(),
)
.unwrap(),
})
.await;
Timer::after(Duration::from_secs(5)).await;
}
}
2 changes: 1 addition & 1 deletion lib/core/src/mqtt_topics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum MqttTopics {
Velocity,
Acceleration,
Logs,
Debug
Debug,
}

impl MqttTopics {
Expand Down

0 comments on commit bc84ee6

Please sign in to comment.