mirror of
https://github.com/LastExceed/spacermake.git
synced 2025-03-12 06:51:43 +01:00
update display update messages to account for protocol change
This commit is contained in:
parent
608c192805
commit
3c4213265d
@ -8,7 +8,7 @@ use tap::Pipe;
|
||||
use tokio::time::sleep;
|
||||
|
||||
use crate::MACHINE_IDS;
|
||||
use crate::utils::{create_display_update_message, minute_mark};
|
||||
use crate::utils::{create_display_time_string, minute_mark};
|
||||
use crate::{Announcer, State};
|
||||
|
||||
impl State<Announcer> {
|
||||
@ -48,17 +48,24 @@ impl State<Announcer> {
|
||||
}
|
||||
|
||||
async fn update_runtime_display(&self, machine_id: &str, runtime: Duration) {
|
||||
self.client
|
||||
.read()
|
||||
.await
|
||||
.publish(
|
||||
format!("/cmnd/reader/{machine_id}"),
|
||||
QoS::AtMostOnce,
|
||||
false,
|
||||
create_display_update_message(runtime)
|
||||
)
|
||||
.await
|
||||
.expect("failed to publish display update");
|
||||
let client = self.client.read().await;
|
||||
|
||||
let messages = [
|
||||
("title", "Dauer".into()),
|
||||
("info", create_display_time_string(runtime)),
|
||||
];
|
||||
|
||||
for (route, payload) in messages {
|
||||
client
|
||||
.publish(
|
||||
format!("fabreader/{machine_id}/display/{route}"),
|
||||
QoS::AtMostOnce,
|
||||
false,
|
||||
payload
|
||||
)
|
||||
.await
|
||||
.expect("failed to publish display update");
|
||||
}
|
||||
}
|
||||
|
||||
async fn perform_scheduled_shutdowns(&self) {
|
||||
|
@ -34,14 +34,11 @@ pub fn minute_mark(duration: Duration) -> bool {
|
||||
duration.as_secs() % 60 == 0
|
||||
}
|
||||
|
||||
pub fn create_display_update_message(runtime: Duration) -> String {
|
||||
pub fn create_display_time_string(runtime: Duration) -> String {
|
||||
let hours = runtime.as_secs() / 3600;
|
||||
let minutes = runtime.as_secs() / 60 % 60;
|
||||
|
||||
json::object! {
|
||||
Cmd: "message",
|
||||
MssgID: 12,
|
||||
ClrTxt: "Nutzungsdauer",
|
||||
AddnTxt: format!("{hours:.0}:{minutes:0>2.0}")
|
||||
}.to_string()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user