Skip to content

Commit 4ae1189

Browse files
Merge pull request #46 from FrameworkComputer/als
framework_lib: Read ALS sensor
2 parents e328bb4 + 7c4d0e2 commit 4ae1189

4 files changed

Lines changed: 23 additions & 3 deletions

File tree

framework_lib/src/commandline/clap_std.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ struct ClapCli {
3333
#[arg(long)]
3434
thermal: bool,
3535

36+
/// Print sensor information (ALS, G-Sensor)
37+
#[arg(long)]
38+
sensors: bool,
39+
3640
/// Show information about USB-C PD ports
3741
#[arg(long)]
3842
pdports: bool,
@@ -196,6 +200,7 @@ pub fn parse(args: &[String]) -> Cli {
196200
esrt: args.esrt,
197201
power: args.power,
198202
thermal: args.thermal,
203+
sensors: args.sensors,
199204
pdports: args.pdports,
200205
pd_info: args.pd_info,
201206
dp_hdmi_info: args.dp_hdmi_info,

framework_lib/src/commandline/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ pub struct Cli {
122122
pub esrt: bool,
123123
pub power: bool,
124124
pub thermal: bool,
125+
pub sensors: bool,
125126
pub pdports: bool,
126127
pub privacy: bool,
127128
pub pd_info: bool,
@@ -606,6 +607,8 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
606607
power::get_and_print_power_info(&ec);
607608
} else if args.thermal {
608609
power::print_thermal(&ec);
610+
} else if args.sensors {
611+
power::print_sensors(&ec);
609612
} else if args.pdports {
610613
power::get_and_print_pd_info(&ec);
611614
} else if args.info {
@@ -784,7 +787,8 @@ Options:
784787
--version Show tool version information (Add -vv for more detailed information)
785788
--esrt Display the UEFI ESRT table
786789
--power Show current power status (battery and AC)
787-
--thermal Show current power status (battery and AC)
790+
--thermal Print thermal information (Temperatures and Fan speed)
791+
--sensors Print sensor information (ALS, G-Sensor)
788792
--pdports Show information about USB-C PD ports
789793
--info Show info from SMBIOS (Only on UEFI)
790794
--pd-info Show details about the PD controllers

framework_lib/src/commandline/uefi.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub fn parse(args: &[String]) -> Cli {
6060
esrt: false,
6161
power: false,
6262
thermal: false,
63+
sensors: false,
6364
pdports: false,
6465
pd_info: false,
6566
dp_hdmi_info: false,
@@ -131,6 +132,9 @@ pub fn parse(args: &[String]) -> Cli {
131132
} else if arg == "--thermal" {
132133
cli.thermal = true;
133134
found_an_option = true;
135+
} else if arg == "--sensors" {
136+
cli.sensors = true;
137+
found_an_option = true;
134138
} else if arg == "--pdports" {
135139
cli.pdports = true;
136140
found_an_option = true;

framework_lib/src/power.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ const EC_MEMMAP_BATT_MFGR: u16 = 0x60; // Battery Manufacturer String
5252
const EC_MEMMAP_BATT_MODEL: u16 = 0x68; // Battery Model Number String
5353
const EC_MEMMAP_BATT_SERIAL: u16 = 0x70; // Battery Serial Number String
5454
const EC_MEMMAP_BATT_TYPE: u16 = 0x78; // Battery Type String
55-
const _EC_MEMMAP_ALS: u16 = 0x80; // ALS readings in lux (2 X 16 bits)
56-
// Unused 0x84 - 0x8f
55+
const EC_MEMMAP_ALS: u16 = 0x80; // ALS readings in lux (2 X 16 bits)
56+
// Unused 0x84 - 0x8f
5757
const _EC_MEMMAP_ACC_STATUS: u16 = 0x90; // Accelerometer status (8 bits )
5858
// Unused 0x91
5959
const _EC_MEMMAP_ACC_DATA: u16 = 0x92; // Accelerometers data 0x92 - 0x9f
@@ -191,6 +191,13 @@ pub fn print_memmap_version_info(ec: &CrosEc) {
191191
let _events_ver = ec.read_memory(EC_MEMMAP_EVENTS_VERSION, 2).unwrap();
192192
}
193193

194+
pub fn print_sensors(ec: &CrosEc) {
195+
let als = ec.read_memory(EC_MEMMAP_ALS, 0x04).unwrap();
196+
197+
let als_int = u32::from_le_bytes([als[0], als[1], als[2], als[3]]);
198+
println!("ALS: {:>4} Lux", als_int);
199+
}
200+
194201
pub fn print_thermal(ec: &CrosEc) {
195202
let temps = ec.read_memory(EC_MEMMAP_TEMP_SENSOR, 0x0F).unwrap();
196203
let fans = ec.read_memory(EC_MEMMAP_FAN, 0x08).unwrap();

0 commit comments

Comments
 (0)