aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 46486316f180a93b590104023844b0431ade288d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! mmx150 — battery and connection monitoring for the beyerdynamic MMX 150
//! wireless dongle.

use std::process::ExitCode;

fn main() -> ExitCode {
    let args: Vec<String> = std::env::args().skip(1).collect();
    match args.first().map(String::as_str) {
        Some("status") => cmd_status(),
        Some("daemon") => cmd_daemon(),
        Some("probe") => cmd_probe(),
        _ => {
            eprintln!("usage: mmx150 <status|daemon|probe>");
            ExitCode::FAILURE
        }
    }
}

fn cmd_status() -> ExitCode {
    match mmx150::hid::find_mmx150() {
        Ok(Some(dev)) => {
            println!("dongle: {} ({}:{:04x})", dev.name, dev.vid, dev.pid);
            println!("connection: unknown (protocol reverse-engineering in progress)");
            println!("battery: unknown");
            ExitCode::SUCCESS
        }
        Ok(None) => {
            eprintln!("dongle not found");
            ExitCode::FAILURE
        }
        Err(e) => {
            eprintln!("error: {e}");
            ExitCode::FAILURE
        }
    }
}

fn cmd_daemon() -> ExitCode {
    eprintln!("daemon not implemented yet");
    ExitCode::FAILURE
}

fn cmd_probe() -> ExitCode {
    eprintln!("use `mmx150-probe` binary instead");
    ExitCode::FAILURE
}