General TC > Programming & Scripting - Unofficial

acpid scripts for laptop Fn+F2/3/6/7/8 functions

(1/9) > >>

nick65go:
My modest try to solve annoying problems with my laptop Fn keys.I think my HP laptop has a bug in UEFI firmware. It always was the same problem with BIOS for any PC I bought, because they came with Windows 7/10 preinstalled. And Dell /HP did not care about linux :(
The Fn keys that I need most often are F2/F3 for brightness and F6/F7/F8 for sound volume control.When the laptop starts, the fan is very noisy, because the brightness is very high (near insupportable). Plus the battery will deplete very fast (high power consumption).
So, basic things, but they can keep a user away of TinyCore/Linux if they are few but critical.
After trying in aterm a lot of basic commands for alsamixer, amixer, flit, etc, reading about acpid,here below is my acpid config. hope is usefully for some one.
home/tc/.acpi/actions.sh
--- Code: ---#!/bin/sh
case $1 in
  button/mute*)
    MST=`amixer controls | grep 'Master Playback Switch' | cut -d, -f1`
    if [[ -z `amixer cget $MST | grep "values=on"` ]]
     then
       amixer cset $MST on
     else
      amixer cset $MST off
    fi;;

  button/volumedown*)
    MST2=`amixer controls | grep "Master Playback Volume" | cut -d, -f1`
    VOL=`amixer cget $MST2 | grep ": values=" | cut -d= -f2`
    [[ $VOL -ge 4 ]] && amixer cset $MST2 `expr $VOL - 4` && exit
    MST1=`amixer controls | grep "Master Playback Switch" | cut -d, -f1`
    amixer cset $MST1 off;;

  button/volumeup*)
    MST2=`amixer controls | grep "Master Playback Volume" | cut -d, -f1`
    VOL=`amixer cget $MST2 | grep ": values=" | cut -d= -f2`
    [[ $VOL -le 83 ]]  && amixer cset $MST2 `expr $VOL + 4`
    MST1=`amixer controls | grep "Master Playback Switch" | cut -d, -f1`
    [[ -z `amixer cget $MST1 | grep "values=on"` ]] && amixer cset $MST1 on;;
 
  video/brightnessdown*)
    BG=`cat /sys/class/backlight/radeon_bl0/actual_brightness`
    [[ $BG -ge 9 ]] && echo -n `expr $BG - 8` > /sys/class/backlight/radeon_bl0/brightness;;
  video/brightnessup*)
    BG=`cat /sys/class/backlight/radeon_bl0/actual_brightness`
    [[ $BG -le 247 ]] && echo -n `expr $BG + 8` > /sys/class/backlight/radeon_bl0/brightness;;

  # *)
  #  popup $1;;
esac
--- End code ---
I tested by running as root:
--- Code: ---root@box:/home/tc# /usr/local/sbin/acpid -d
--- End code ---
my acpid event-config is just a small file /etc/acpi/event/all,

--- Code: ---tc@box:/etc/acpi/events$ cat all
event=.*
action=/home/tc/.acpi/actions.sh "%e"
--- End code ---

nick65go:
and the fight against Goliath (laptop!) continue...When the lid is closed, the Diplay is OFF, but other parts are NOT in standby (I hear the fan, the small-left led is still continuum lighting, not flashing as in standby.So basically the LID switch is just for display, not for stand by. When laptop cover is lifted up, the display turn on.
Looking into /var/log/Xorg.0.log I see at least:
--- Code: ---Power Button (/dev/input/event0)
Lid Switch (/dev/input/event1)
--- End code ---

And now the improved/continued list of events for acpid
--- Code: ---  button/power*)
    exitcheck.sh shutdown;;    #<-- thanks tiny core
  button/lid*)
    echo -n "mem" > /sys/power/state;;

  *)
    popup $1 &
    sleep 1
    kill `pidof popup` &;;
esac
--- End code ---

tamimg the beast. TBC...

nick65go:
now there are people who do not give a shit about Fn-F# keys. Right. We can use aterm very easy, if we per-define some aliases:
--- Code: ---tc@box:~$ cat .ashrc
alias suspend='echo mem | sudo tee /sys/power/state'
alias low50='echo 50 | sudo tee /sys/class/backlight/radeon_bl0/brightness'

--- End code ---

Ok you need a little flexibility for brightness?
--- Code: ---tc@box:~/.local/bin$ cat brightness.sh
#!/bin/sh

BG=`cat /sys/class/backlight/radeon_bl0/brightness`
echo "Curent brightnness is" $BG
echo "
1.   Minim ~0% (Are you crazy?)
8.   Hurry Battery is Low!
16.  Economic
32.  GOOD BOY
64.  Medium
128. Very Bright
192. Extremely Bright
255. Max 100% (Are you crazy?)

Type Brightness Number: [1-255]"

read -s answer
echo  $answer | sudo tee /sys/class/backlight/radeon_bl0/brightness
echo "Done! bye"
read junk; exit
--- End code ---

Now another bad habit of the laptop is that the battery runs silent until remain 1%. WTF? then I have maxim 20 seconds to plug the adapter, or bye-bye unsaved work.Time for a cron job? [never tried one] to test every 10-20 minutes the battery capacity? or when is near (lets say) 5% to popup a messge like: "My Lord, plug the F**king power cord, battery is x%"

curaga:
About suspend by command, IIRC in some laptops the enter key press comes so late it causes a wakeup. On those I added a sleep in front,

--- Code: ---alias suspend='sleep 1 && echo mem | sudo tee /sys/power/state'
--- End code ---

Battery alarm like that is a hw/bios function, and you indeed need a software poll setup for other thresholds and notifications.

nick65go:
Thanks curaga for support. I am still thinking about a simple script for crond job, stubborn in using FLTK only as much as possible.

Now the battle with sound and video continue. I hope I won.
ALSA has a bad habit to see HDMI first then Digital sound card. And radeon driver should adjust the clock to low speed to stay quiet for longer.
(I have an AMD A6-6310 APU with AMD Radeon R4 Graphics integrated).
--- Code: ---tc@box:~$ ls -lR /etc/modprobe.d
/etc/modprobe.d:
total 12
-rw-r--r--    1 tc       staff           18 May 19  2019 blacklist.conf
-rw-r--r--    1 tc       staff           50 May 19  2019 radeon.conf
-rw-r--r--    1 tc       staff           33 May 21  2019 snd_hda_intel.conf

tc@box:~$ cat /etc/modprobe.d/blacklist.conf
blacklist pcspkr

tc@box:~$ cat /etc/modprobe.d/radeon.conf
options radeon aspm=1 vce=1 uvd=1 dynclks=Enable dpm=1

tc@box:~$ cat /etc/modprobe.d/snd_hda_intel.conf
options snd_hda_intel index=1,0

--- End code ---

the misleading thing was that i need options snd_hda_intel (not snd-hda-intel) even if modprobe has letters with "minus", not "underscore"

--- Code: ---tc@box:~$ modinfo snd_hda_intel
filename:       /lib/modules/5.4.3-tinycore64/kernel.tclocal/sound/pci/hda/snd-hda-intel.ko.gz
--- End code ---

And finally, for sound testing, aplay is not working by default. because missing few dummy files in /usr/local/etc/alsa/cards (shame-less taken from alsaconfig.tcz)
--- Code: ---tc@box:~$ ls -lR /usr/local/etc/alsa
/usr/local/etc/alsa:
total 8
lrwxrwxrwx    1 root     root            45 May 19 09:32 alsa.conf -> /tmp/tcloop/alsa/usr/local/etc/alsa/alsa.conf
-rw-r--r--    1 tc       staff         6554 May 19  2019 asound.state
drwxr-xr-x    2 root     root            80 May 19 09:32 cards/

/usr/local/etc/alsa/cards:
total 8
-rw-r--r--    1 root     root            71 May 14 00:41 aliases.conf
-rw-r--r--    1 root     root           762 Jan 10 14:46 default.conf
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version