mirror of
https://github.com/actuallymentor/battery.git
synced 2026-02-03 14:03:24 +00:00
Use js4jiang5's approach to detect supported smc keys instead of detect_smc_capabilities() func
This commit is contained in:
53
battery.sh
53
battery.sh
@@ -22,12 +22,6 @@ maintain_percentage_tracker_file=$configfolder/maintain.percentage
|
|||||||
maintain_voltage_tracker_file=$configfolder/maintain.voltage
|
maintain_voltage_tracker_file=$configfolder/maintain.voltage
|
||||||
daemon_path=$HOME/Library/LaunchAgents/battery.plist
|
daemon_path=$HOME/Library/LaunchAgents/battery.plist
|
||||||
calibrate_pidfile=$configfolder/calibrate.pid
|
calibrate_pidfile=$configfolder/calibrate.pid
|
||||||
smc_capabilities_detected=false
|
|
||||||
smc_supports_tahoe=false
|
|
||||||
smc_supports_legacy=false
|
|
||||||
smc_supports_adapter_chie=false
|
|
||||||
smc_supports_adapter_ch0i=false
|
|
||||||
smc_supports_adapter_ch0j=false
|
|
||||||
|
|
||||||
# Voltage limits
|
# Voltage limits
|
||||||
voltage_min="10.5"
|
voltage_min="10.5"
|
||||||
@@ -162,37 +156,6 @@ function valid_voltage() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function detect_smc_capabilities() {
|
|
||||||
if [[ "$smc_capabilities_detected" == "true" ]]; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
smc_capabilities_detected=true
|
|
||||||
smc_supports_tahoe=false
|
|
||||||
smc_supports_legacy=false
|
|
||||||
smc_supports_adapter_chie=false
|
|
||||||
smc_supports_adapter_ch0i=false
|
|
||||||
smc_supports_adapter_ch0j=false
|
|
||||||
|
|
||||||
if sudo -n smc -k CHTE -r &>/dev/null; then
|
|
||||||
smc_supports_tahoe=true
|
|
||||||
fi
|
|
||||||
if sudo -n smc -k CH0B -r &>/dev/null && sudo -n smc -k CH0C -r &>/dev/null; then
|
|
||||||
smc_supports_legacy=true
|
|
||||||
fi
|
|
||||||
if sudo -n smc -k CHIE -r &>/dev/null; then
|
|
||||||
smc_supports_adapter_chie=true
|
|
||||||
fi
|
|
||||||
if sudo -n smc -k CH0I -r &>/dev/null; then
|
|
||||||
smc_supports_adapter_ch0i=true
|
|
||||||
fi
|
|
||||||
if sudo -n smc -k CH0J -r &>/dev/null; then
|
|
||||||
smc_supports_adapter_ch0j=true
|
|
||||||
fi
|
|
||||||
|
|
||||||
log "SMC capabilities: tahoe=$smc_supports_tahoe legacy=$smc_supports_legacy CHIE=$smc_supports_adapter_chie CH0I=$smc_supports_adapter_ch0i CH0J=$smc_supports_adapter_ch0j"
|
|
||||||
}
|
|
||||||
|
|
||||||
function smc_read_hex() {
|
function smc_read_hex() {
|
||||||
key=$1
|
key=$1
|
||||||
line=$(echo $(smc -k $key -r))
|
line=$(echo $(smc -k $key -r))
|
||||||
@@ -213,6 +176,16 @@ function smc_write_hex() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## #########################
|
||||||
|
## Detect supported SMC keys
|
||||||
|
## #########################
|
||||||
|
[[ $(smc -k CHTE -r) =~ "no data" ]] && smc_supports_tahoe=false || smc_supports_tahoe=true;
|
||||||
|
[[ $(smc -k CH0B -r) =~ "no data" ]] && smc_supports_legacy=false || smc_supports_legacy=true;
|
||||||
|
[[ $(smc -k CHIE -r) =~ "no data" ]] && smc_supports_adapter_chie=false || smc_supports_adapter_chie=true;
|
||||||
|
[[ $(smc -k CH0I -r) =~ "no data" ]] && smc_supports_adapter_ch0i=false || smc_supports_adapter_ch0i=true;
|
||||||
|
[[ $(smc -k CH0J -r) =~ "no data" || $(smc -k CH0J -r) =~ "Error" ]] && smc_supports_adapter_ch0j=false || smc_supports_adapter_ch0j=true;
|
||||||
|
log "SMC capabilities: tahoe=$smc_supports_tahoe legacy=$smc_supports_legacy CHIE=$smc_supports_adapter_chie CH0I=$smc_supports_adapter_ch0i CH0J=$smc_supports_adapter_ch0j"
|
||||||
|
|
||||||
## #################
|
## #################
|
||||||
## SMC Manipulation
|
## SMC Manipulation
|
||||||
## #################
|
## #################
|
||||||
@@ -248,7 +221,6 @@ function change_magsafe_led_color() {
|
|||||||
# CH0I seems to be the "disable the adapter" key
|
# CH0I seems to be the "disable the adapter" key
|
||||||
function enable_discharging() {
|
function enable_discharging() {
|
||||||
log "🔽🪫 Enabling battery discharging"
|
log "🔽🪫 Enabling battery discharging"
|
||||||
detect_smc_capabilities
|
|
||||||
if [[ "$smc_supports_adapter_chie" == "true" ]]; then
|
if [[ "$smc_supports_adapter_chie" == "true" ]]; then
|
||||||
smc_write_hex CHIE 08
|
smc_write_hex CHIE 08
|
||||||
elif [[ "$smc_supports_adapter_ch0j" == "true" ]]; then
|
elif [[ "$smc_supports_adapter_ch0j" == "true" ]]; then
|
||||||
@@ -261,7 +233,6 @@ function enable_discharging() {
|
|||||||
|
|
||||||
function disable_discharging() {
|
function disable_discharging() {
|
||||||
log "🔼🪫 Disabling battery discharging"
|
log "🔼🪫 Disabling battery discharging"
|
||||||
detect_smc_capabilities
|
|
||||||
if [[ "$smc_supports_adapter_chie" == "true" ]]; then
|
if [[ "$smc_supports_adapter_chie" == "true" ]]; then
|
||||||
smc_write_hex CHIE 00
|
smc_write_hex CHIE 00
|
||||||
elif [[ "$smc_supports_adapter_ch0j" == "true" ]]; then
|
elif [[ "$smc_supports_adapter_ch0j" == "true" ]]; then
|
||||||
@@ -318,7 +289,6 @@ function disable_discharging() {
|
|||||||
# so I'm using both since with only CH0B I noticed sometimes during sleep it does trigger charging
|
# so I'm using both since with only CH0B I noticed sometimes during sleep it does trigger charging
|
||||||
function enable_charging() {
|
function enable_charging() {
|
||||||
log "🔌🔋 Enabling battery charging"
|
log "🔌🔋 Enabling battery charging"
|
||||||
detect_smc_capabilities
|
|
||||||
if [[ "$smc_supports_tahoe" == "true" ]]; then
|
if [[ "$smc_supports_tahoe" == "true" ]]; then
|
||||||
smc_write_hex CHTE 00000000
|
smc_write_hex CHTE 00000000
|
||||||
elif [[ "$smc_supports_legacy" == "true" ]]; then
|
elif [[ "$smc_supports_legacy" == "true" ]]; then
|
||||||
@@ -332,7 +302,6 @@ function enable_charging() {
|
|||||||
|
|
||||||
function disable_charging() {
|
function disable_charging() {
|
||||||
log "🔌🪫 Disabling battery charging"
|
log "🔌🪫 Disabling battery charging"
|
||||||
detect_smc_capabilities
|
|
||||||
if [[ "$smc_supports_tahoe" == "true" ]]; then
|
if [[ "$smc_supports_tahoe" == "true" ]]; then
|
||||||
smc_write_hex CHTE 01000000
|
smc_write_hex CHTE 01000000
|
||||||
elif [[ "$smc_supports_legacy" == "true" ]]; then
|
elif [[ "$smc_supports_legacy" == "true" ]]; then
|
||||||
@@ -344,7 +313,6 @@ function disable_charging() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function get_smc_charging_status() {
|
function get_smc_charging_status() {
|
||||||
detect_smc_capabilities >/dev/null
|
|
||||||
local status_key="CH0B"
|
local status_key="CH0B"
|
||||||
if [[ "$smc_supports_tahoe" == "true" ]]; then
|
if [[ "$smc_supports_tahoe" == "true" ]]; then
|
||||||
status_key="CHTE"
|
status_key="CHTE"
|
||||||
@@ -368,7 +336,6 @@ function get_smc_charging_status() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function get_smc_discharging_status() {
|
function get_smc_discharging_status() {
|
||||||
detect_smc_capabilities >/dev/null
|
|
||||||
local status_key="CH0I"
|
local status_key="CH0I"
|
||||||
if [[ "$smc_supports_adapter_chie" == "true" ]]; then
|
if [[ "$smc_supports_adapter_chie" == "true" ]]; then
|
||||||
status_key="CHIE"
|
status_key="CHIE"
|
||||||
|
|||||||
Reference in New Issue
Block a user