aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLibravatar Silas Bartha <[email protected]>2023-11-11 00:03:24 -0500
committerLibravatar Silas Bartha <[email protected]>2023-11-11 00:03:24 -0500
commitd10f633980b642b77aac32f84081f4d8a989fd08 (patch)
treef1ee67173506a89e5f9a59ad38001d79df18dec8 /src
parent347d29d1e1aaec6ec2b21090e52222995020a4da (diff)
basic working client
Diffstat (limited to 'src')
-rw-r--r--src/main.rs156
1 files changed, 154 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index e7a11a9..94abf49 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,155 @@
-fn main() {
- println!("Hello, world!");
+use std::{error::Error, time::Duration};
+
+use clap::{Parser, Subcommand};
+use zbus::Connection;
+
+#[derive(Debug, Parser)]
+#[clap(name = "pomc", version)]
+struct Pomc {
+ #[clap(subcommand)]
+ command: Command,
+}
+
+#[derive(Debug, Subcommand)]
+enum Command {
+ Start,
+ Pause,
+ Stop,
+ Skip,
+ GetIteration,
+ GetRemaining,
+ IsRunning,
+ IsOnBreak,
+}
+
+#[async_std::main]
+async fn main() -> Result<(), Box<dyn Error>> {
+ let args = Pomc::parse();
+ let connection = Connection::session().await?;
+
+ match args.command {
+ Command::Start => start(&connection).await?,
+ Command::Pause => pause(&connection).await?,
+ Command::Stop => stop(&connection).await?,
+ Command::Skip => skip(&connection).await?,
+ Command::GetIteration => get_iteration(&connection).await?,
+ Command::GetRemaining => get_remaining(&connection).await?,
+ Command::IsRunning => is_running(&connection).await?,
+ Command::IsOnBreak => is_on_break(&connection).await?,
+ }
+
+ Ok(())
+}
+
+async fn start(connection: &Connection) -> Result<(), Box<dyn Error>> {
+ connection
+ .call_method(
+ Some("dev.exvacuum.pomd"),
+ "/dev/exvacuum/pomd",
+ Some("dev.exvacuum.pomd"),
+ "Start",
+ &(),
+ )
+ .await?;
+ Ok(())
+}
+
+async fn pause(connection: &Connection) -> Result<(), Box<dyn Error>> {
+ connection
+ .call_method(
+ Some("dev.exvacuum.pomd"),
+ "/dev/exvacuum/pomd",
+ Some("dev.exvacuum.pomd"),
+ "Pause",
+ &(),
+ )
+ .await?;
+ Ok(())
+}
+
+async fn stop(connection: &Connection) -> Result<(), Box<dyn Error>> {
+ connection
+ .call_method(
+ Some("dev.exvacuum.pomd"),
+ "/dev/exvacuum/pomd",
+ Some("dev.exvacuum.pomd"),
+ "Stop",
+ &(),
+ )
+ .await?;
+ Ok(())
+}
+
+async fn skip(connection: &Connection) -> Result<(), Box<dyn Error>> {
+ connection
+ .call_method(
+ Some("dev.exvacuum.pomd"),
+ "/dev/exvacuum/pomd",
+ Some("dev.exvacuum.pomd"),
+ "Skip",
+ &(),
+ )
+ .await?;
+ Ok(())
+}
+
+async fn get_iteration(connection: &Connection) -> Result<(), Box<dyn Error>> {
+ let m = connection
+ .call_method(
+ Some("dev.exvacuum.pomd"),
+ "/dev/exvacuum/pomd",
+ Some("dev.exvacuum.pomd"),
+ "GetIteration",
+ &(),
+ )
+ .await?;
+ let iteration: u8 = m.body().unwrap();
+ println!("{}", iteration + 1);
+ Ok(())
+}
+
+async fn get_remaining(connection: &Connection) -> Result<(), Box<dyn Error>> {
+ let m = connection
+ .call_method(
+ Some("dev.exvacuum.pomd"),
+ "/dev/exvacuum/pomd",
+ Some("dev.exvacuum.pomd"),
+ "GetRemaining",
+ &(),
+ )
+ .await?;
+ let remaining: Duration = m.body().unwrap();
+ let remaining_secs = remaining.as_secs();
+ println!("{:02}:{:02}", remaining_secs / 60, remaining_secs % 60);
+ Ok(())
+}
+
+async fn is_running(connection: &Connection) -> Result<(), Box<dyn Error>> {
+ let m = connection
+ .call_method(
+ Some("dev.exvacuum.pomd"),
+ "/dev/exvacuum/pomd",
+ Some("dev.exvacuum.pomd"),
+ "IsRunning",
+ &(),
+ )
+ .await?;
+ let is_running: bool = m.body().unwrap();
+ println!("{}", is_running as u8);
+ Ok(())
+}
+
+async fn is_on_break(connection: &Connection) -> Result<(), Box<dyn Error>> {
+ let m = connection
+ .call_method(
+ Some("dev.exvacuum.pomd"),
+ "/dev/exvacuum/pomd",
+ Some("dev.exvacuum.pomd"),
+ "IsOnBreak",
+ &(),
+ )
+ .await?;
+ let is_on_break: bool = m.body().unwrap();
+ println!("{}", is_on_break as u8);
+ Ok(())
}