This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conditional Features for razer-cli (#14)
Major changes are: * syntax of `razer-cli` changed, script depending on it requires adjustment * features are introduced and can be selectively activated * 2 modes: `auto` and `manual --pid 0x029f` - in `auto` mode the model is detected automatically and only supported features are activated - in `manual` mode provided pid is used and all features are activated * `razer-cli manual --pid 0x029f info` does not fail on the first error, instead prints the error and continues to dump info * [model number prefix](https://mysupport.razer.com/app/answers/detail/a_id/5481) is used now to detect devices, allowing to differentiate between devices with similar PIDs (e.g. Black and Mercur colors have the same PID, but Mercur doesn't have lid logo). * Supported features can be specified per model * model prefix id is read from Windows registry, for Linux not implemented yet. * cli entries are now dynamically generated based on supported features.
- Loading branch information
Showing
10 changed files
with
501 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use crate::feature; | ||
|
||
// model_number_prefix shall conform to https://mysupport.razer.com/app/answers/detail/a_id/5481 | ||
#[derive(Debug, Clone)] | ||
pub struct Descriptor { | ||
pub model_number_prefix: &'static str, | ||
pub name: &'static str, | ||
pub pid: u16, | ||
pub features: &'static [&'static str], | ||
} | ||
|
||
pub const SUPPORTED: &[Descriptor] = &[ | ||
Descriptor { | ||
model_number_prefix: "RZ09-0483T", | ||
name: "Razer Blade 16” (2023) Black", | ||
pid: 0x029f, | ||
features: &[ | ||
"battery-care", | ||
"fan", | ||
"kbd-backlight", | ||
"lid-logo", | ||
"lights-always-on", | ||
"perf", | ||
], | ||
}, | ||
Descriptor { | ||
model_number_prefix: "RZ09-0482X", | ||
name: "Razer Blade 14” (2023) Mercury", | ||
pid: 0x029d, | ||
features: &[ | ||
"battery-care", | ||
"fan", | ||
"kbd-backlight", | ||
"lights-always-on", | ||
"perf", | ||
], | ||
}, | ||
]; | ||
|
||
const _VALIDATE_FEATURES: () = { | ||
crate::const_for! { device in SUPPORTED => { | ||
feature::validate_features(device.features); | ||
}} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use const_format::{map_ascii_case, Case}; | ||
|
||
pub trait Feature { | ||
fn name(&self) -> &'static str; | ||
} | ||
|
||
macro_rules! feature_list { | ||
($($type:ident,)*) => { | ||
$( | ||
#[derive(Default)] | ||
pub struct $type {} | ||
|
||
impl Feature for $type { | ||
fn name(&self) -> &'static str { | ||
map_ascii_case!(Case::Kebab, stringify!($type)) | ||
} | ||
} | ||
)* | ||
|
||
pub const ALL_FEATURES: &[&'static str] = &[ | ||
$(map_ascii_case!(Case::Kebab, stringify!($type)),)* | ||
]; | ||
|
||
#[macro_export] | ||
macro_rules! iter_features { | ||
($apply:expr) => { | ||
{ | ||
let mut v = Vec::new(); | ||
$( | ||
let entry = $type::default(); | ||
v.push($apply(entry.name(), entry)); | ||
)* | ||
v | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! const_for { | ||
($var:ident in $iter:expr => $block:block) => { | ||
let mut iter = $iter; | ||
while let [$var, tail @ ..] = iter { | ||
iter = tail; | ||
$block | ||
} | ||
}; | ||
} | ||
|
||
const fn contains(array: &[&str], value: &str) -> bool { | ||
const_for! { it in array => { | ||
if const_str::equal!(*it, value) { | ||
return true; | ||
} | ||
}} | ||
false | ||
} | ||
|
||
pub const fn validate_features(features: &[&str]) { | ||
const_for! { f in features => { | ||
assert!(contains(ALL_FEATURES, f), "Feature is not in supported list"); | ||
}} | ||
} | ||
|
||
feature_list![ | ||
BatteryCare, | ||
LidLogo, | ||
LightsAlwaysOn, | ||
KbdBacklight, | ||
Fan, | ||
Perf, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
pub mod command; | ||
pub mod device; | ||
pub mod feature; | ||
pub mod types; | ||
|
||
pub mod descriptor; | ||
mod packet; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.