PCFreak Logo (c) Der PCFreak

Archive for September, 2015

Dell XPS 13 Linux – HDD LED (using ShiftLock LED) Kommentare deaktiviert für Dell XPS 13 Linux – HDD LED (using ShiftLock LED)

I recently bought a Dell XPS 13 (Modell 2015) Ultrabook and I run Arch Linux on it. One thing I missed from the beginning was the absence of a drive LED. When I saw, that the XPS 13 has a white LED to signal ShiftLock directly inside the ShiftLock-Key I had an idea. Hey, I run Linux and I have total control, so why not use this ShiftLock-LED as a HardDrive LED?

The following script (running as a service) provides the Drive LED functionality on the Dell XPS 13. (Thanks to P.I. Engineering, Manwe and Stefo for their ideas)

#!/bin/bash
# save this file as pcfreakled without extension
# and make it executable (chmod +x)

#check dependencies
command -v setxkbmap >/dev/null 2>&1 || { echo >&2 "Script requires setxkbmap but it is not installed.Aborting."; exit 1; }
command -v setleds   >/dev/null 2>&1 || { echo >&2 "Script requires setleds but it is not installed.Aborting."; exit 1; }

# console
CONSOLE=/dev/console

# disable caps lock key
# This can also be done within Gnome but here is also a good place
setxkbmap -option ctrl:nocaps  >/dev/null 2>&1

# Check interval seconds
CHECKINTERVAL=0.1

#indicator to use [caps, num, scroll]
INDICATOR=caps

getVmstat() {
#  cat /proc/vmstat|
   egrep "pgpgin|pgpgout" /proc/vmstat 
}
#turn led on
function led_on()
{
    setleds -L +${INDICATOR} < ${CONSOLE} >/dev/null 2>&1
}
#turn led off
function led_off()
{
    setleds -L -${INDICATOR} < ${CONSOLE} >/dev/null 2>&1
}
# initialise variables
NEW=$(getVmstat)
OLD=$(getVmstat)
## 
while [ 1 ] ; do
  sleep $CHECKINTERVAL # slowdown a bit
  # get status 
  NEW=$(getVmstat)
  #compare state
  if [ "$NEW" = "$OLD" ]; then  
    led_off ## no change, led off
  else
    led_on  ## change, led on
  fi
  OLD=$NEW  
done

If your Linux distribution already uses systemd, you can use the following file to implement the above script as a daemon (assuming you placed the script in /usr/lib/systemd/scripts/pcfreakled):

[Unit]
Description=PCFreaks Dell XPS13 DriveLED

[Service]
Type=simple
ExecStart=/usr/lib/systemd/scripts/pcfreakled

[Install]
WantedBy=multi-user.target