WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: acpid scripts for laptop Fn+F2/3/6/7/8 functions  (Read 1316 times)

Offline nick65go

  • Sr. Member
  • ****
  • Posts: 345
acpid scripts for laptop Fn+F2/3/6/7/8 functions
« on: May 18, 2020, 02:15:47 PM »
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: [Select]
#!/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
I tested by running as root:
Code: [Select]
root@box:/home/tc# /usr/local/sbin/acpid -dmy acpid event-config is just a small file /etc/acpi/event/all,
Code: [Select]
tc@box:/etc/acpi/events$ cat all
event=.*
action=/home/tc/.acpi/actions.sh "%e"


Offline nick65go

  • Sr. Member
  • ****
  • Posts: 345
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #1 on: May 18, 2020, 02:55:45 PM »
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: [Select]
Power Button (/dev/input/event0)
Lid Switch (/dev/input/event1)

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

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

tamimg the beast. TBC...
« Last Edit: May 18, 2020, 03:02:17 PM by nick65go »

Offline nick65go

  • Sr. Member
  • ****
  • Posts: 345
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #2 on: May 18, 2020, 03:32:54 PM »
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: [Select]
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'

Ok you need a little flexibility for brightness?
Code: [Select]
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

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%"
« Last Edit: May 18, 2020, 03:36:24 PM by nick65go »

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10239
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #3 on: May 18, 2020, 11:29:29 PM »
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: [Select]
alias suspend='sleep 1 && echo mem | sudo tee /sys/power/state'
Battery alarm like that is a hw/bios function, and you indeed need a software poll setup for other thresholds and notifications.
The only barriers that can stop you are the ones you create yourself.

Offline nick65go

  • Sr. Member
  • ****
  • Posts: 345
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #4 on: May 19, 2020, 01:23:35 AM »
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: [Select]
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

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: [Select]
tc@box:~$ modinfo snd_hda_intel
filename:       /lib/modules/5.4.3-tinycore64/kernel.tclocal/sound/pci/hda/snd-hda-intel.ko.gz

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: [Select]
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

« Last Edit: May 19, 2020, 01:27:35 AM by nick65go »

Offline nick65go

  • Sr. Member
  • ****
  • Posts: 345
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #5 on: May 19, 2020, 03:41:04 AM »
Two more small victories. Like the song says "another one bits the dust".
It was about input devices. My UK keyboard does not let me type € (euros sign) for Alt-gr + 4.
And the touch-pad is clever in Win10 but stupid in linux. It seams the modern "all-inclusive" libinput (in preparation for Wayland?) is good replacement for evdev, but libinput has not all options as old/trusted synaptics.
Code: [Select]
#/etc/X11/xorg.conf.d/20-keyboard.conf
Section "InputClass"
    Identifier "My Keyboard"
    Driver "libinput"
    MatchIsKeyboard "yes"

    Option "XkbLayout" "gb" #not uk!
    Option "XkbVariant" "extd" #not intl
    Option "XkbOptions" "euro sign:4,terminate:ctrl_alt_bksp"
EndSection
An inspection on /var/log/Xog.0.log shows that only synaptic driver takes my options=.., ignored by libinput "master of inputs"
Code: [Select]
#/etc/X11/xorg.conf.d/70-synaptics.conf
Section "InputClass"
    Identifier "My Pad"
    Driver "synaptics"
    MatchIsTouchpad "on"
    MatchDevicePath "/dev/input/event*"

    Option "TapButton1" "1"
    Option "TapButton2" "2"
    Option "TapButton3" "3"

    Option "ClickFinger1" "1"
    Option "ClickFinger2" "2"
    Option "ClickFinger3" "3"

    Option "RTCornerButton" "2"
    Option "RBCornerButton" "3"
    Option "LTCornerButton" "1"
    Option "LBCornerButton" "1"

    Option "VertEdgeScroll" "1"
    Option "HorizEdgeScroll" "1"
    Option "VertTwoFingerScroll" "1"
    Option "HorizTwoFingerScroll" "1"
    Option "CornerCoasting" "1"
    Option "CircularScrolling" "1"
    Option "CoastingSpeed" "2"
    Option "CoastingFriction" "5"
    Option "SoftButtonAreas"  "60% 0 82% 0 40% 59% 82% 0"
EndSection


FYI: all these little things (keyboard, audio, sound) keep users on Win10 (bloat/spy).
« Last Edit: May 19, 2020, 03:46:00 AM by nick65go »

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 12236
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #6 on: May 19, 2020, 03:44:55 AM »
What happens without xf86-input-evdev and xf86-input-synaptics loaded?

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 12236
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #7 on: May 19, 2020, 03:47:34 AM »
in preparation for Wayland?

wayland has been available for some time now in CorePure64 - have you tried the weston compositor?

Offline nick65go

  • Sr. Member
  • ****
  • Posts: 345
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #8 on: May 19, 2020, 03:55:58 AM »
Hi Juanito, as I said, by default I do no load xf86-input-evdev, neither xf86-input-synaptic. xf86-input-libinput just works.but it ignores my options from
Code: [Select]
#/etc/X11/xorg.conf.d/70-synaptics.conf
Section "InputClass"
    Identifier "My Pad"
    Driver "libinput"

So I need to load
xf86-input-synaptic also.
Code: [Select]
#/etc/X11/xorg.conf.d/70-synaptics.conf
Section "InputClass"
    Identifier "My Pad"
    Driver "synaptics"
About wayland, i have no clue, just reading articles about why evdev is replaced, and libinput promoted (maybe for touch screens, etc)
FYI: I am still at base things, like Xorg + FLTK. partial GK1/2/3 as imposed by others like firefox.
« Last Edit: May 19, 2020, 04:00:40 AM by nick65go »

Offline nick65go

  • Sr. Member
  • ****
  • Posts: 345
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #9 on: May 19, 2020, 05:04:01 AM »
just to confirm, again, that libinput ignores my syntax for "options=" from 70-synaptics.conf
I delete /var/log/Xorg.0.log, I modified the (only one on my laptop) 70-synaptics.conf, to have
Code: [Select]
#/etc/X11/xorg.conf.d/70-synaptics.conf
Section "InputClass"
    Identifier "My Pad"
    Driver "libinput"
    MatchIsTouchpad "on"
    MatchDevicePath "/dev/input/event*"
shut-down X server, then startx. inspecting the fresh /var/log/Xorg.0.log i see it missed all my synaptic options (needed for horizontal/vertical edge scrolls, etc)
Code: [Select]
[  1186.556] (II) config/udev: Adding input device SynPS/2 Synaptics TouchPad (/dev/input/event8)
[  1186.556] (**) SynPS/2 Synaptics TouchPad: Applying InputClass "libinput touchpad catchall"
[  1186.556] (**) SynPS/2 Synaptics TouchPad: Applying InputClass "My Pad"
[  1186.556] (II) Using input driver 'libinput' for 'SynPS/2 Synaptics TouchPad'
[  1186.556] (**) SynPS/2 Synaptics TouchPad: always reports core events
[  1186.556] (**) Option "Device" "/dev/input/event8"
[  1186.556] (**) Option "_source" "server/udev"
[  1186.558] (II) event8  - SynPS/2 Synaptics TouchPad: is tagged by udev as: Touchpad
[  1186.561] (II) event8  - SynPS/2 Synaptics TouchPad: device is a touchpad
[  1186.561] (II) event8  - SynPS/2 Synaptics TouchPad: device removed
[  1186.604] (**) Option "config_info" "udev:/sys/devices/platform/i8042/serio1/input/input5/event8"
[  1186.608] (**) Option "AccelerationScheme" "none"
[  1186.608] (**) SynPS/2 Synaptics TouchPad: (accel) selected scheme none/0
[  1186.608] (**) SynPS/2 Synaptics TouchPad: (accel) acceleration factor: 2.000
[  1186.608] (**) SynPS/2 Synaptics TouchPad: (accel) acceleration threshold: 4
[  1186.610] (II) event8  - SynPS/2 Synaptics TouchPad: is tagged by udev as: Touchpad
[  1186.613] (II) event8  - SynPS/2 Synaptics TouchPad: device is a touchpad
[  1186.614] (II) config/udev: Adding input device SynPS/2 Synaptics TouchPad (/dev/input/mouse0)
[  1186.614] (II) No input driver specified, ignoring this device.
[  1186.614] (II) This device may have been added with another device file.
[  1186.615] (II) config/udev: Adding input device PC Speaker (/dev/input/event4)
[  1186.615] (II) No input driver specified, ignoring this device.
PS: in dmesg (from Control Panel) I see also (but i belive it is not critical)
Code: [Select]
psmouse serio1: synaptics: queried max coordinates: x [..5656], y [..4712]
psmouse serio1: synaptics: queried min coordinates: x [1326..], y [1200..]
psmouse serio1: synaptics: Your touchpad (PNP: SYN3202 PNP0f13) says it can support a different bus. If i2c-hid and hid-rmi are not used, you might want to try setting psmouse.synaptics_intertouch to 1 and report this to linux-input@vger.kernel.org.
random: fast init done

full Xorg.0.log is attached as prove.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 12236
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #10 on: May 19, 2020, 05:20:00 AM »
Out of interest, have you tried accessing the settings directly:
Code: [Select]
$ xinput list
...
AlpsPS/2 ALPS GlidePoint                      id=16   [slave  pointer  (2)]
...
..so the touchpad is device id=16

Code: [Select]
$ xinput list-props 16
Device 'AlpsPS/2 ALPS GlidePoint':
        Device Enabled (161):   1
        Coordinate Transformation Matrix (163): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
        libinput Tapping Enabled (314): 0
        libinput Tapping Enabled Default (315): 0
        libinput Tapping Drag Enabled (316):    1
        libinput Tapping Drag Enabled Default (317):    1
        libinput Tapping Drag Lock Enabled (318):       0
        libinput Tapping Drag Lock Enabled Default (319):       0
        libinput Tapping Button Mapping Enabled (320):  1, 0
        libinput Tapping Button Mapping Default (321):  1, 0
        libinput Natural Scrolling Enabled (296):       0
        libinput Natural Scrolling Enabled Default (297):       0
        libinput Disable While Typing Enabled (322):    1
        libinput Disable While Typing Enabled Default (323):    1
        libinput Scroll Methods Available (298):        1, 1, 0
        libinput Scroll Method Enabled (299):   1, 0, 0
        libinput Scroll Method Enabled Default (300):   1, 0, 0
        libinput Middle Emulation Enabled (303):        1
        libinput Middle Emulation Enabled Default (304):        1
        libinput Accel Speed (305):     0.000000
        libinput Accel Speed Default (306):     0.000000
        libinput Left Handed Enabled (310):     0
        libinput Left Handed Enabled Default (311):     0
        libinput Send Events Modes Available (281):     1, 1
        libinput Send Events Mode Enabled (282):        0, 0
        libinput Send Events Mode Enabled Default (283):        0, 0
        Device Node (284):      "/dev/input/event7"
        Device Product ID (285):        2, 8
        libinput Drag Lock Buttons (312):       <no items>
        libinput Horizontal Scroll Enabled (313):       1
..so device enable is property id=161

Code: [Select]
$ xinput set-prop 16 161 0..disables the touchpad (for example)
« Last Edit: May 19, 2020, 05:28:40 AM by Juanito »

Offline nick65go

  • Sr. Member
  • ****
  • Posts: 345
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #11 on: May 19, 2020, 06:45:41 AM »
Yes, xinput works. This I tried first (reading from Gentoo, Archilinux, Xorg(5) manual),  to understand the equvalences xinput <-> synaptics.

Code: [Select]
$ synclient -l
Parameter settings:
#Synaptics Edge Scrolling (287): 0, 0, 0
    VertEdgeScroll          = 0
    HorizEdgeScroll         = 0
    CornerCoasting          = 0
#Synaptics Two-Finger Scrolling (288):   1, 1
    VertTwoFingerScroll     = 1
    HorizTwoFingerScroll    = 0

Code: [Select]
tc@box:~$ xinput
â   â³ PS/2+USB Mouse                                id=9    [slave  pointer
â   â³ SynPS/2 Synaptics TouchPad                    id=11   [slave  pointer

tc@box:~$ xinput list-props 11
Device 'SynPS/2 Synaptics TouchPad':
        Device Enabled (143):   1
        Coordinate Transformation Matrix (145): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000,                     0.000000, 0.000000, 0.000000, 1.000000
        Synaptics Edge Scrolling (309): 1, 1, 1
        Synaptics Two-Finger Scrolling (310):   1, 1
What I try to achieve is an automatic Xorg configuration. This can be done by loading a small driver (xf86-input-synaptics) and its configuration, OR in /home/tc/X.d using a script about xinput + a list of parameters like above.
« Last Edit: May 19, 2020, 06:50:33 AM by nick65go »

Offline nick65go

  • Sr. Member
  • ****
  • Posts: 345
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #12 on: May 19, 2020, 06:58:40 AM »
Remarks about ALSA. The mydata.tgz (which contains my setings about /etc/modprobe.d/snd_hda-intel.conf) is loaded AFTER the alsa.tcz (and its alsa-module-$kernel.tcz) are loaded from onboot.lst

For me, ALSA without core remastering, can be only in on-demand; because my setting about digital sound before HDMI are useless if alsa.tcz is in onboot.lst
« Last Edit: May 19, 2020, 07:08:51 AM by nick65go »

Offline nick65go

  • Sr. Member
  • ****
  • Posts: 345
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #13 on: May 19, 2020, 07:06:12 AM »
Remarks about firmware*.tcz: Even if I have listed first firmware*.tcz in onboot.lst, dmesg still shows warning messages about them. Because they are found a little later.
Code: [Select]
r8169 0000:02:00.0: Direct firmware load for rtl_nic/rtl8106e-1.fw failed with error -2
rtl8723be 0000:01:00.0: Direct firmware load for rtlwifi/rtl8723befw_36.bin failed with error -2
platform regulatory.0: Direct firmware load for regulatory.db failed with error -2
rtl8723be 0000:01:00.0: Direct firmware load for rtlwifi/rtl8723befw_36.bin failed with error -2
Only remastering the core could suppress them.

Moreover, 3+ processes are running in the background, because firmware triggers like
Code: [Select]
/sbin/udevd --daemonare not stopped later.
« Last Edit: May 19, 2020, 07:18:50 AM by nick65go »

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 12236
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #14 on: May 19, 2020, 07:50:22 AM »
That’s not for certain, the kernel first  looks in the driver for the firmware and then checks elsewhere.

Code: [Select]
iwlwifi 0000:02:00.0: Direct firmware load for iwlwifi-7260-17.ucode failed with error -2
iwlwifi 0000:02:00.0: loaded firmware version 17.459231.0 op_mode iwlmvm
« Last Edit: May 19, 2020, 08:12:02 AM by Juanito »