Difference between revisions of "Tp smapi"

From ArchWiki
Jump to: navigation, search
(Control Battery Charging)
(Features)
Line 9: Line 9:
  
 
===Control Battery Charging===
 
===Control Battery Charging===
[http://www.thinkwiki.org/wiki/Maintenance#Battery_treatment It's bad for most laptop batteries to hold a full charge for long periods of time.]  You should try to keep your battery in the 40-80% charged range, unless you need the battery life for extended periods of time. tp_smapi lets you control the start and stop charging threshold to do just that.  Run these commands to set these to good values:
+
 
 +
[http://www.thinkwiki.org/wiki/Maintenance#Battery_treatment It's bad for most laptop batteries to hold a full charge for long periods of time.]  You should try to keep your battery in the 40-80% charged range, unless you need the battery life for extended periods of time.
 +
 
 +
====General Way====
 +
 
 +
tp_smapi lets you control the start and stop charging threshold to do just that.  Run these commands to set these to good values:
 
  echo 40 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
 
  echo 40 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
 
  echo 80 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh
 
  echo 80 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh
Line 41: Line 46:
 
         ;;
 
         ;;
 
  #... more ACPI stuff
 
  #... more ACPI stuff
 +
 +
====More advanced script====
 +
 +
In case you would like more sophisticated script, which would fasilitate changing the thresholds:
 +
#!/bin/bash
 +
#
 +
# Bash script for setting the battery thresholds on ThinkPads using the tp_smapi interface.
 +
# Written by Ignas Anikevicius (20/03/2010)
 +
 +
#HELP TEXT
 +
if [ "x$1" == "x--help" -o "x$1" == "x-h" ]
 +
then
 +
  echo -e "
 +
  WARNING!!! This script needs to be run as root in order to have effect!!!
 +
 +
  Possible options are:
 +
    set_bat_thresh [BAT_N] [[LOWER] [UPPER]][--reset][-r]
 +
 
 +
    [BAT_N] number of the battery (can be either 0 or 1).
 +
 +
    LOWER - lower threshold.
 +
    UPPER - upper threshold .
 +
    [--reset] or [-r] sets the default thresholds.
 +
 +
  execute to see this text:
 +
    set_bat_thresh [--help][-h]
 +
"
 +
  exit 0
 +
fi
 +
 +
if [ ! -d /sys/devices/platform/smapi ]; then
 +
  echo -e "\nSMAPI interface is NOT installed.\nPlease load the module.\n"
 +
  exit 0; fi
 +
 +
#SETTING THRESHOLD VALUES
 +
if [ "x$2" == "x--reset" -o "x$2" == "x-r" ]
 +
then
 +
  LOWER=96
 +
  UPPER=100
 +
else
 +
  LOWER=$2
 +
  UPPER=$3
 +
fi
 +
 +
#VALUE TESTING
 +
if [ ${LOWER} -ge ${UPPER} ]; then
 +
  echo -e "\n  Please provide proper thresholds!!!  \n"
 +
  exit 0
 +
fi
 +
 +
#BATTERY NUMBER
 +
BAT_N=$1
 +
LOWER_F="/sys/devices/platform/smapi/BAT${BAT_N}/start_charge_thresh"
 +
UPPER_F="/sys/devices/platform/smapi/BAT${BAT_N}/stop_charge_thresh"
 +
 +
#SETTING THE THRESHOLDS
 +
echo ${LOWER} > ${LOWER_F}
 +
echo ${UPPER} > ${UPPER_F}
 +
 +
#ECHOING THE STUFF
 +
echo -e "\nSetting battery thresholds for Battery ${BAT_N}:
 +
  Threshold for charging to start: ${LOWER}
 +
  Threshold for charging to stop: ${UPPER}
 +
"
 +
exit 0;
 +
 +
With this script to set a battery threshold is very simple,
 +
just type (if set_bat_thresh is the name of the script):
 +
set_bat_thresh 0 40 80
  
 
===Protect the Hard Disk from Drops===
 
===Protect the Hard Disk from Drops===

Revision as of 22:59, 19 March 2010

tp_smapi is a set of kernel modules that retrieves information from and conveys commands to the hardware of ThinkPad laptops. This information is presented through the /sys/devices/platform/smapi filesystem. Much like the /proc filesystem, you can read and write information to these files to get information about and send commands to the hardware. tp_smapi is highly recommended if you're using a ThinkPad laptop.

Installation

Install tp_smapi from AUR. After installing, add tp_smapi to your MODULES array. After a reboot, this will activate most of the drivers, represented through the /sys/devices/platform/smapi filesystem.

Features

Here are a couple of useful things you can do using tp_smapi. Please feel free to add your own.

Control Battery Charging

It's bad for most laptop batteries to hold a full charge for long periods of time. You should try to keep your battery in the 40-80% charged range, unless you need the battery life for extended periods of time.

General Way

tp_smapi lets you control the start and stop charging threshold to do just that. Run these commands to set these to good values:

echo 40 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
echo 80 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh

This will cause the battery to begin charging when it falls below 40% charge and stop charging once it exceeds 80% charge. This will extend the lifetime of your battery.

Note that when you remove and re-insert the battery, these thresholds may be reset to their default values. To work around this, create a script to set these values, and make this script run both at startup and when a battery is inserted. More specific instructions follow.

Create a script /usr/sbin/set_battery_thresholds:

#!/bin/bash
# set the battery charging thresholds to extend battery lifespan
echo 40 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
echo 80 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh

NB: if you let the battery discharge below 40%, you will get problems, since it is not charged anymore. A solution consists in setting only the parameter stop_charge_thresh and control manually the lower battery value.

Set it runnable:

[root ~]# chmod 744 /usr/sbin/set_battery_thresholds

Make this script run at startup by editing /etc/rc.local:

#... other rc.local stuff
/usr/sbin/set_battery_thresholds

Make it run when a battery is inserted. This requires that acpid is installed and running. Edit /etc/acpi/handler.sh:

#... other ACPI stuff
battery)
  case "$2" in
    BAT0)
      case "$4" in
        00000000)
        ;;
        00000001)
        /usr/sbin/set_battery_thresholds
        ;;
#... more ACPI stuff

More advanced script

In case you would like more sophisticated script, which would fasilitate changing the thresholds:

#!/bin/bash
#
# Bash script for setting the battery thresholds on ThinkPads using the tp_smapi interface.
# Written by Ignas Anikevicius (20/03/2010)

#HELP TEXT
if [ "x$1" == "x--help" -o "x$1" == "x-h" ]
then
  echo -e "
  WARNING!!! This script needs to be run as root in order to have effect!!!

  Possible options are:
    set_bat_thresh [BAT_N] [[LOWER] [UPPER]][--reset][-r] 
 
    [BAT_N] number of the battery (can be either 0 or 1). 

    LOWER - lower threshold.
    UPPER - upper threshold .
    [--reset] or [-r] sets the default thresholds. 

  execute to see this text:
    set_bat_thresh [--help][-h]
"
  exit 0
fi 

if [ ! -d /sys/devices/platform/smapi ]; then
  echo -e "\nSMAPI interface is NOT installed.\nPlease load the module.\n"
  exit 0; fi

#SETTING THRESHOLD VALUES
if [ "x$2" == "x--reset" -o "x$2" == "x-r" ]
then
  LOWER=96
  UPPER=100
else
  LOWER=$2
  UPPER=$3
fi

#VALUE TESTING
if [ ${LOWER} -ge ${UPPER} ]; then
  echo -e "\n  Please provide proper thresholds!!!  \n"
  exit 0
fi

#BATTERY NUMBER
BAT_N=$1
LOWER_F="/sys/devices/platform/smapi/BAT${BAT_N}/start_charge_thresh"
UPPER_F="/sys/devices/platform/smapi/BAT${BAT_N}/stop_charge_thresh"

#SETTING THE THRESHOLDS
echo ${LOWER} > ${LOWER_F}
echo ${UPPER} > ${UPPER_F} 

#ECHOING THE STUFF
echo -e "\nSetting battery thresholds for Battery ${BAT_N}:
  Threshold for charging to start: ${LOWER} 
  Threshold for charging to stop: ${UPPER} 
"
exit 0;

With this script to set a battery threshold is very simple, just type (if set_bat_thresh is the name of the script):

set_bat_thresh 0 40 80

Protect the Hard Disk from Drops

tp_smapi includes a driver to read the accelerometer in your laptop to detect drops and other events that could cause damage to your hard drive. See the HDAPS page for more information on this useful feature.

See Also

tp_smapi on ThinkWiki