Repository navigation
Expand file tree
/
Copy pathmain.rs
More file actions
70 lines (59 loc) · 1.63 KB
/
Copy pathmain.rs
File metadata and controls
70 lines (59 loc) · 1.63 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#![allow(clippy::needless_range_loop)]
#![allow(clippy::single_match)]
mod b1display;
mod c1minimal;
mod font;
mod inputmodule;
mod ledmatrix;
use clap::{Parser, Subcommand};
use inputmodule::find_serialdevs;
use crate::b1display::B1DisplaySubcommand;
use crate::c1minimal::C1MinimalSubcommand;
use crate::inputmodule::{serial_commands, B1_LCD_PID, LED_MATRIX_PID};
use crate::ledmatrix::LedMatrixSubcommand;
#[derive(Subcommand, Debug)]
enum Commands {
LedMatrix(LedMatrixSubcommand),
B1Display(B1DisplaySubcommand),
C1Minimal(C1MinimalSubcommand),
}
impl Commands {
pub fn to_pid(&self) -> u16 {
match self {
Self::LedMatrix(_) => LED_MATRIX_PID,
Self::B1Display(_) => B1_LCD_PID,
Self::C1Minimal(_) => 0x22,
}
}
}
/// RAW HID and VIA commandline for QMK devices
#[derive(Parser, Debug)]
#[command(version, arg_required_else_help = true)]
pub struct ClapCli {
#[command(subcommand)]
command: Option<Commands>,
/// List connected HID devices
#[arg(short, long)]
list: bool,
/// Verbose outputs to the console
#[arg(short, long)]
verbose: bool,
/// Serial device, like /dev/ttyACM0 or COM0
#[arg(long)]
pub serial_dev: Option<String>,
/// Retry connecting to the device until it works
#[arg(long)]
wait_for_device: bool,
}
fn main() {
let args: Vec<String> = std::env::args().collect();
let args = ClapCli::parse_from(args);
match args.command {
Some(_) => serial_commands(&args),
None => {
if args.list {
find_serialdevs(&args, false);
}
}
}
}