WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

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

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #15 on: May 19, 2020, 12:35:36 PM »
If you never use HDMI sound, you could try disabling it with the "radeon.audio=0" bootcode.
The only barriers that can stop you are the ones you create yourself.

Offline nick65go

  • Hero Member
  • *****
  • Posts: 838
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #16 on: May 19, 2020, 12:48:58 PM »
for now my sound configuration is solved.

I can also kill (from mydata.tgz) the 3+ deamons (/sbin/udevd --daemon) which run for nothing in the background (because firmware triggers)
They were only needed for few seconds, until firmware is found and loaded, right?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11618
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #17 on: May 19, 2020, 02:40:38 PM »
Hi nick65go
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
Or you could call:
Code: [Select]
tce-load -i alsafrom  bootsync.sh  which runs after  mydata.tgz  is restored.

Offline nick65go

  • Hero Member
  • *****
  • Posts: 838
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #18 on: May 19, 2020, 04:05:05 PM »
Hi Rich, thank you, it is a good point! I forgot about bootsync.sh.
I  try to avoid to remaster anything. I remastered many times, and then a new TC made it obsoleted (because kernel modules version).

Offline nick65go

  • Hero Member
  • *****
  • Posts: 838
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #19 on: May 19, 2020, 09:40:59 PM »
I was thinking about a solution to trigger an alarm-popup, using tinycore crond daemon, if battery is lower 2%-7%.crond can start/stop from Control-Panel /Services.

Code: [Select]
tc@box:/var/spool/cron/crontabs$ sudo cat tc
# crond timer; */n  =every nth interval; specific intervals with commas (1,2,3,etc)
# M             minute (0 - 59)
#   H           hour (0 - 23)
#     D         day of the month (1 - 31)
#       m       month (1 - 12)
#         w     day of the week (0 - 6)
#           c   command to execute
# * * * * * echo "demo"
*/5 * * * * /home/tc/.acpi/battery.sh

Code: [Select]
tc@box:~/.acpi$ cat battery.sh
#!/bin/sh
# battery.sh alarm for 2% capacity

LOW=`cat /proc/acpi/battery/BAT0/info | grep "design capacity low:" | cut -d: -f2 | tr -d " " | tr -d "mWh"`
#echo $LOW
MAX=`cat /proc/acpi/battery/BAT0/info | grep "design capacity:" | cut -d: -f2 | tr -d " " | tr -d "mWh"`
#echo $MAX
NOW=`cat /proc/acpi/battery/BAT0/state | grep "remaining capacity:" | cut -d: -f2 | tr -d " " | tr -d "mWh"`
#echo $NOW

[[ $NOW -ge $LOW ]] && exit
[ $NOW -gt `expr $MAX / 50` ] && popup "Battery low `expr 100 \* $NOW / $MAX` %%" && exit
popup "Plug NOW the power cable, Battery is less than 2 %%"
I do not know if crond (popping up every 5 minutes) will consume itself the battery.
« Last Edit: May 19, 2020, 09:57:33 PM by nick65go »

Offline nick65go

  • Hero Member
  • *****
  • Posts: 838
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #20 on: May 20, 2020, 09:15:48 AM »
It would be nice if flit.tcz has a nice battery alarm option, like I tried to simulate with crond daemon.Anyway, it works for me now. I had 3 times popup messages about battery 2% - 5%, so it seams that 5 minutes interval has good granularity for not missing the 2%-7% threshold.
Summary (until now) about automation of basic tasks accomplished:
Code: [Select]
tc@box:~/.X.d$ ls -al
-rwxrwxr--    1 tc       staff          136 May 20 14:06 flit+alsa
-rwxrwxr--    1 tc       staff          512 May 20 14:54 myacpi
Code: [Select]
tc@box:~/.X.d$ cat flit\+alsa
[ -e /usr/local/tce.installed/alsa ] || tce-load -i -l alsa.tcz
[ -e /usr/local/tce.installed/flit ] || tce-load -i -l flit.tcz
flit &
Code: [Select]
tc@box:~/.X.d$ cat myacpi
# lower brightness, from default 255 to 32
echo 32 | sudo tee /sys/class/backlight/radeon_bl0/brightness &

#start acpid daemon for F2/3(brightness), F6/7/8(sound), and LID
sudo kill `pidof acpid`
sudo /usr/local/sbin/acpid &

#start crond daemon for battery low 2%
sudo kill `pidof crond`
sudo /usr/local/sbin/crond &

#stop orfans daemons (/sbin/udevd --daemon) for firmware
sudo kill `pidof udevd`

#stop wire-network if we use wifi
[ -e /var/run/udhcpc.eth0.pid ] && sudo kill `cat /var/run/udhcpc.eth0.pid`
So no more multiple/useless acpid, crond, udevd.
Next challenge is to tame the UEFI to boot automatically grub2, instead of the tedious F9 + select UEFI partition + the scrolling for a folder/grub.efi. (for 5-10 seconds faster boot?). Because default is win10 "hard-coded", so maybe to change some efi variables.
« Last Edit: May 20, 2020, 09:24:08 AM by nick65go »

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #21 on: May 20, 2020, 12:41:03 PM »
That is a risky operation on some machines. Changing those EFI vars, on a badly written UEFI BIOS, may cause the machine to become unbootable, and removing the bios battery won't fix it. Do search if your machine has such.
The only barriers that can stop you are the ones you create yourself.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11618
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #22 on: May 20, 2020, 02:08:21 PM »
Hi nick65go
...
Code: [Select]
tc@box:~/.acpi$ cat battery.sh
#!/bin/sh
# battery.sh alarm for 2% capacity

LOW=`cat /proc/acpi/battery/BAT0/info | grep "design capacity low:" | cut -d: -f2 | tr -d " " | tr -d "mWh"`
#echo $LOW
MAX=`cat /proc/acpi/battery/BAT0/info | grep "design capacity:" | cut -d: -f2 | tr -d " " | tr -d "mWh"`
#echo $MAX
NOW=`cat /proc/acpi/battery/BAT0/state | grep "remaining capacity:" | cut -d: -f2 | tr -d " " | tr -d "mWh"`
#echo $NOW

[[ $NOW -ge $LOW ]] && exit
[ $NOW -gt `expr $MAX / 50` ] && popup "Battery low `expr 100 \* $NOW / $MAX` %%" && exit
popup "Plug NOW the power cable, Battery is less than 2 %%"
I do not know if crond (popping up every 5 minutes) will consume itself the battery.

Or you could just launch a script in the background that sleeps 99.9999% of the time and occasionally reads the remaining
battery capacity directly:
Code: [Select]
#!/bin/sh
# Short script to monitor remaining percent of battery power.
# Check  /sys/class/power_supply  to find how your battery is named.
#
#  Usage:
# BatteryMonitor.sh BatteryName &
#
#  Example:
# BatteryMonitor.sh BAT0 &

[ -z "$1" ] && exit

# The percentage that triggers a warning.
WarningLevel=5
# Number of minutes to sleep before checking capacity again.
SleepMinutes=5

PowerPath="/sys/class/power_supply"
BatteryName="$1"
Capacity="$PowerPath/$BatteryName/capacity"
SleepTime=$((60 * $SleepMinutes))

while true
do
sleep "$SleepTime"
RemainingCapacity="`cat $Capacity`"
[ "$RemainingCapacity" -gt "$WarningLevel" ] && continue
popup "Remaining battery capacity is $RemainingCapacity%%"
done

    [EDIT]: The syntax for  SleepTime=  was corrected in the attachment and this post. See reply #35 and #36.  Rich
« Last Edit: May 24, 2020, 11:29:31 PM by Rich »

Offline nick65go

  • Hero Member
  • *****
  • Posts: 838
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #23 on: May 20, 2020, 03:15:38 PM »
@Rich: yes, work appreciated! I will try it. I will search for tricks, like /proc/acpi/ vs. /sys/class/power_supply.It was fun to learn for first time how cron works.

@curaga: you are right. It is a big risk, versus the gain, I am still reading about it. Maybe I will get for the fast and dirty solution, to repalce the Win10 bootloader (/EFI/Microsoft/Boot/bootmgrfw.efi, 1.46 MB) with my customized /EFI/1grub.64-gpt.efi (118.5 KB). Made a copy of the former MS bootloader, just to put it back in emergency.
But I suspect that in the background, when I will start Win10, it will silently replace back its bloated boot loader. MS had this bad habit in the past. OR just refuse to boot from grub chain loading.

PS: I do not know if I have a bug in the FLTK environment, it happened in the past also, with TinyCore other versions: During my writing, in editor, but mostly in firefox, my cursor JUMP from current position to random row/position. So if I do not pay attention, I just overwrite previous words. And then I see I wrote crazy phrases/words.
Also, strange things happen with my mouse. I copy an area in aterm with the mouse, by selecting. Sometimes also by right-click mouse after I already selected.
 I do not know how to paste it with keyboard, so I just go to destination and just push the mouse middle button for paste.And here the paste is double of my clipboard content, second buffer in the middle of the first buffer.ex: abcde fff hhh -> ababcde fff hhhcde fff hhh

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #24 on: May 21, 2020, 02:33:24 AM »
During my writing, in editor, but mostly in firefox, my cursor JUMP from current position to random row/position.

Hi, nick65go!

Probably it is the wrong supposition, but looks like accidential touches to the touchpad during typing. Is it possible? Usually, a person, who's typing text, is rather concentrated on the meaning of the process and only the other person can mark those accidential touches.

Some options for {Copy,Paste} for various environments are {Shift-Del,Shift-Ins}  {Ctrl-Shift-C,Ctrl-Shift-V}

Offline nick65go

  • Hero Member
  • *****
  • Posts: 838
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #25 on: May 21, 2020, 02:16:03 PM »
maybe possible accidental touch of pad, but i am 90% it is not. Maybe my mouse is a little warned/broken, because it happened with few tinycore versions also in the past; myabe i am wrong but i suspected  background script for tinycore forum. Or is a memory leak in fltk -> most of the time it happens copy/paste between aterm and aterm.
Feed-back: testing between "aterm" and "editor"1. in editor selected a word "maria" , and copy it with ctrl+C. paste it in aterm with sfht+ins. OK. (ins=Fn+Prt_sc, crazy keyboard layout)2. in aterm select with the mouse a word "john", it means copy. It another aterm past it with sfht+ins. OK. But in editor, with Crtl+C, or sfht +ins -> will paste "maria". wow. not the same clipboard buffer.buffer
« Last Edit: May 21, 2020, 02:46:17 PM by nick65go »

Offline nick65go

  • Hero Member
  • *****
  • Posts: 838
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #26 on: May 21, 2020, 03:02:18 PM »
Feed-back: testing between "aterm" and "editor"
1. in editor selected a word "maria" with touchpad, and copy it with ctrl+C. paste it in aterm with sfht+ins. OK. (ins=Fn+Prt_sc, crazy keyboard layout)
2. in aterm select with the touchpad a word "john", it means copy. It another aterm past it with sfht+ins. OK. But in editor, with Crtl+V, or sfht +ins -> will paste "maria". wow. not the same clipboard buffer.
3. copy "versions" word from firefox with touchpad, paste it OK in aterm (with sfht+ins) and in editor (with both ctrl+V, or shf+ins). But touchpad selecting is OK only between terminals aterm and aterm. Touchpad select "john" from aterm will paste into both editor and firefox the "version"!!
« Last Edit: May 21, 2020, 03:10:27 PM by nick65go »

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #27 on: May 21, 2020, 03:13:48 PM »
maybe possible accidental touch of pad, but i am 90% it is not. Maybe my mouse is a little warned/broken

So You use both touchpad and mouse? I can propose the hack - disconnect touchpad ) i did so and have  no jumping cursors anymore. But this is until You need to use laptop  somewhere else. Maybe You can advice me how to block the touchpad using software? Of course it would be much more appropriate.
 

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #28 on: May 21, 2020, 03:16:36 PM »

2. in aterm select with the touchpad a word "john", it means copy. It another aterm past it with sfht+ins. OK. But in editor, with Crtl+V, or sfht +ins -> will paste "maria". wow. not

Sorry, no. In aterm select with the touchpad AND Shift-Del means Copy.

Offline jazzbiker

  • Hero Member
  • *****
  • Posts: 934
Re: acpid scripts for laptop Fn+F2/3/6/7/8 functions
« Reply #29 on: May 21, 2020, 03:28:41 PM »
Sorry, nick65go, I was wrong. This doesn't work between terminal and X editor. Only between terminals. This are different clipboards, and I don't know how to combine them together.
This works for fifth browser.
« Last Edit: May 21, 2020, 03:31:19 PM by jazzbiker »