Skip to content

Commit 7309551

Browse files
committed
Add --ptp-mode command
Can check and change ptp mode ``` > sudo framework_tool --ptp-mode ptp > sudo framework_tool --ptp-mode mouse > sudo framework_tool --ptp-mode mouse > sudo framework_tool --ptp-mode ptp > sudo framework_tool --ptp-mode ptp Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent ca4415b commit 7309551

6 files changed

Lines changed: 684 additions & 2 deletions

File tree

framework_lib/src/commandline/clap_std.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use clap_num::maybe_hex;
1212
use crate::chromium_ec::commands::SetGpuSerialMagic;
1313
use crate::chromium_ec::CrosEcDriverType;
1414
use crate::commandline::{
15-
Cli, ConsoleArg, FpBrightnessArg, HardwareDeviceType, InputDeckModeArg, LogLevel, RebootEcArg,
16-
TabletModeArg,
15+
Cli, ConsoleArg, FpBrightnessArg, HardwareDeviceType, InputDeckModeArg, LogLevel, PtpModeArg,
16+
RebootEcArg, TabletModeArg,
1717
};
1818

1919
/// Swiss army knife for Framework laptops
@@ -241,6 +241,11 @@ struct ClapCli {
241241
#[arg(long)]
242242
stylus_battery: bool,
243243

244+
/// Get or set precision touchpad mode
245+
#[clap(value_enum)]
246+
#[arg(long)]
247+
ptp_mode: Option<Option<PtpModeArg>>,
248+
244249
/// Get EC console, choose whether recent or to follow the output
245250
#[clap(value_enum)]
246251
#[arg(long)]
@@ -535,6 +540,7 @@ pub fn parse(args: &[String]) -> Cli {
535540
tablet_mode: args.tablet_mode,
536541
touchscreen_enable: args.touchscreen_enable,
537542
stylus_battery: args.stylus_battery,
543+
ptp_mode: args.ptp_mode,
538544
console: args.console,
539545
reboot_ec: args.reboot_ec,
540546
ec_hib_delay: args.ec_hib_delay,

framework_lib/src/commandline/mod.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ use crate::smbios::ConfigDigit0;
6161
use crate::smbios::{get_smbios, is_framework};
6262
#[cfg(feature = "hidapi")]
6363
use crate::touchpad::print_touchpad_fw_ver;
64+
#[cfg(target_os = "linux")]
65+
use crate::touchpad_ptp;
66+
#[cfg(all(feature = "hidapi", windows))]
67+
use crate::touchpad_ptp_win;
6468
#[cfg(feature = "hidapi")]
6569
use crate::touchscreen;
6670
#[cfg(feature = "rusb")]
@@ -132,6 +136,13 @@ pub enum InputDeckModeArg {
132136
Off,
133137
On,
134138
}
139+
140+
#[cfg_attr(not(feature = "uefi"), derive(clap::ValueEnum))]
141+
#[derive(Clone, Copy, Debug, PartialEq)]
142+
pub enum PtpModeArg {
143+
Mouse,
144+
Ptp,
145+
}
135146
impl From<InputDeckModeArg> for DeckStateMode {
136147
fn from(w: InputDeckModeArg) -> DeckStateMode {
137148
match w {
@@ -213,6 +224,7 @@ pub struct Cli {
213224
pub tablet_mode: Option<TabletModeArg>,
214225
pub touchscreen_enable: Option<bool>,
215226
pub stylus_battery: bool,
227+
pub ptp_mode: Option<Option<PtpModeArg>>,
216228
pub console: Option<ConsoleArg>,
217229
pub reboot_ec: Option<RebootEcArg>,
218230
pub ec_hib_delay: Option<Option<u32>>,
@@ -303,6 +315,7 @@ pub fn parse(args: &[String]) -> Cli {
303315
// tablet_mode
304316
// touchscreen_enable
305317
stylus_battery: cli.stylus_battery,
318+
// ptp_mode
306319
console: cli.console,
307320
reboot_ec: cli.reboot_ec,
308321
// ec_hib_delay
@@ -1481,6 +1494,50 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
14811494
print_stylus_battery_level();
14821495
#[cfg(not(feature = "hidapi"))]
14831496
error!("Not build with hidapi feature");
1497+
} else if let Some(ptp_arg) = &args.ptp_mode {
1498+
#[cfg(target_os = "linux")]
1499+
match ptp_arg {
1500+
None => match touchpad_ptp::get_ptp_mode() {
1501+
Some(0) => println!("mouse"),
1502+
Some(3) => println!("ptp"),
1503+
Some(v) => println!("unknown ({})", v),
1504+
None => error!("Failed to read PTP mode"),
1505+
},
1506+
Some(PtpModeArg::Mouse) => {
1507+
if touchpad_ptp::set_ptp_mode(0).is_none() {
1508+
error!("Failed to set PTP mode to mouse");
1509+
}
1510+
}
1511+
Some(PtpModeArg::Ptp) => {
1512+
if touchpad_ptp::set_ptp_mode(3).is_none() {
1513+
error!("Failed to set PTP mode to ptp");
1514+
}
1515+
}
1516+
}
1517+
#[cfg(all(feature = "hidapi", windows))]
1518+
match ptp_arg {
1519+
None => match touchpad_ptp_win::get_ptp_mode() {
1520+
Some(0) => println!("mouse"),
1521+
Some(3) => println!("ptp"),
1522+
Some(v) => println!("unknown ({})", v),
1523+
None => error!("Failed to read PTP mode"),
1524+
},
1525+
Some(PtpModeArg::Mouse) => {
1526+
if touchpad_ptp_win::set_ptp_mode(0).is_none() {
1527+
error!("Failed to set PTP mode to mouse");
1528+
}
1529+
}
1530+
Some(PtpModeArg::Ptp) => {
1531+
if touchpad_ptp_win::set_ptp_mode(3).is_none() {
1532+
error!("Failed to set PTP mode to ptp");
1533+
}
1534+
}
1535+
}
1536+
#[cfg(not(any(target_os = "linux", all(feature = "hidapi", windows))))]
1537+
{
1538+
let _ = ptp_arg;
1539+
error!("PTP mode not supported on this platform");
1540+
}
14841541
} else if let Some(console_arg) = &args.console {
14851542
match console_arg {
14861543
ConsoleArg::Follow => {

framework_lib/src/commandline/uefi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pub fn parse(args: &[String]) -> Cli {
8282
tablet_mode: None,
8383
touchscreen_enable: None,
8484
stylus_battery: false,
85+
ptp_mode: None,
8586
console: None,
8687
reboot_ec: None,
8788
ec_hib_delay: None,

framework_lib/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ pub mod inputmodule;
2323
pub mod nvme;
2424
#[cfg(feature = "hidapi")]
2525
pub mod touchpad;
26+
#[cfg(target_os = "linux")]
27+
pub mod touchpad_ptp;
28+
#[cfg(all(feature = "hidapi", windows))]
29+
pub mod touchpad_ptp_win;
2630
#[cfg(feature = "hidapi")]
2731
pub mod touchscreen;
2832
#[cfg(all(feature = "hidapi", windows))]

0 commit comments

Comments
 (0)