Page 1 of 1

SOLVED: How To Keep My Trackball Wakeup Flag Enabled?

Posted: Sun Jul 22, 2018 12:15 am
by Oblias
Hello, all. After running Windows for the last 20+ years, I finally got up the courage to travel into the unknown, mysterious forest of Linux. After doing some deep searching and reading, Linux Mint Cinnamon 19 is what I chose to install on my desktop computer. I'd like it to be known that I am duly impressed! It didn't take me long to throw away my axe, my shotgun, and my bear spray, because I found that this Linux forest is not as perilous as I had always thought it to be. So, with that intro out of the way, I can confidently say that I am a new convert and intend to use LMC as my daily driver...

I could use some help in getting my Kensington Trackball set up, however. The basic functions of the trackball are all fine, no problems there. It's when I put the computer to sleep (suspend) mode, that I found out there is a slight oddity. From years of habit, I have developed the routine of clicking on a trackball button to bring my computer out of sleep mode. That doesn't happen with LMC. I have done quite a lot of searching, reading, and digging into this issue, and here's what I have come up with.

For some reason, LMC changes the wakeup flag ( hope I'm using the right term for that ) of my usb trackball from 'enabled' to 'disabled' every time it comes out of sleep, or every time it boots up, or does a reboot. After much time searching, the solution I found that sets that flag back to 'enabled' is this:

In the terminal, I first have to do the sudo su command, and then enter my password. Once that is done, I issue this command:

Code: Select all

echo enabled > /sys/bus/usb/devices/5-4/power/wakeup


My trackball is, of course, device 5-4. So, after entering that command, and exiting from sudo su mode, I run this command to make sure that the flag was changed:

Code: Select all

grep . /sys/bus/usb/devices/*/power/wakeup
That always gives me this result:

Code: Select all

/sys/bus/usb/devices/10-1/power/wakeup:enabled
/sys/bus/usb/devices/4-5/power/wakeup:enabled
/sys/bus/usb/devices/5-3/power/wakeup:disabled
/sys/bus/usb/devices/5-4/power/wakeup:enabled
/sys/bus/usb/devices/5-5/power/wakeup:disabled
/sys/bus/usb/devices/usb10/power/wakeup:disabled
/sys/bus/usb/devices/usb11/power/wakeup:disabled
/sys/bus/usb/devices/usb1/power/wakeup:disabled
/sys/bus/usb/devices/usb2/power/wakeup:disabled
/sys/bus/usb/devices/usb3/power/wakeup:disabled
/sys/bus/usb/devices/usb4/power/wakeup:disabled
/sys/bus/usb/devices/usb5/power/wakeup:disabled
/sys/bus/usb/devices/usb6/power/wakeup:disabled
/sys/bus/usb/devices/usb7/power/wakeup:disabled
/sys/bus/usb/devices/usb8/power/wakeup:disabled
/sys/bus/usb/devices/usb9/power/wakeup:disabled
OK, so the problem is solved to the point that next time I put the computer to sleep, I can use the trackball to wake it up.

What I would really appreciate some help with is in finding out if this whole procedure can somehow be done automatically? Or at the very least, is there an easier/faster way to enable that wakeup flag? I have some experience in Windows making scripts and running them, but I'm finding that it's not the same here in Linux land.

So, would anyone have any suggestions for me? (Other than going back to Windows, which I really have no intention of doing) The reason I'm even going to this trouble of getting the trackball enabled to wake the computer, is because the only other way I found to wake the computer from sleep is to keep tapping on random keyboard keys until it comes out of sleep. Seems like a rather crazy procedure to me..

The ideal solution for me would be in finding out how to set that flag every time I boot/reboot in an automatic way, and also how to do it after coming out of sleep mode, either automatically or in an easier way than what I've been doing.

Many thanks for reading this long-winded post!!

Oblias (The new guy in the forest)

Re: How To Keep My Trackball Wakeup Flag Enabled?

Posted: Sun Jul 22, 2018 1:11 am
by Oblias
I just read where it helps if I post my system specs, so here it is:

Code: Select all

System:    Host: chaser-mint Kernel: 4.15.0-29-generic x86_64 bits: 64 gcc: 7.3.0
           Desktop: Cinnamon 3.8.8 (Gtk 3.22.30-1ubuntu1) Distro: Linux Mint 19 Tara
Machine:   Device: desktop Mobo: ASUSTeK model: SABERTOOTH 990FX v: Rev 1.xx serial: N/A
           UEFI: American Megatrends v: 1604 date: 10/16/2012
CPU:       8 core AMD FX-8320 Eight-Core (-MCP-) arch: Bulldozer rev.0 cache: 16384 KB
           flags: (lm nx sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm) bmips: 56188
           clock speeds: max: 3808 MHz 1: 3808 MHz 2: 3726 MHz 3: 3469 MHz 4: 3641 MHz 5: 3426 MHz 6: 3393 MHz
           7: 3764 MHz 8: 3780 MHz
Graphics:  Card: Advanced Micro Devices [AMD/ATI] Tonga XT / Amethyst XT [Radeon R9 380X / R9 M295X]
           bus-ID: 01:00.0
           Display Server: x11 (X.Org 1.19.6 ) drivers: amdgpu (unloaded: modesetting,fbdev,vesa)
           Resolution: 1920x1080@60.00hz, 1920x1080@60.00hz
           OpenGL: renderer: AMD Radeon R9 380 Series (TONGA / DRM 3.23.0 / 4.15.0-29-generic, LLVM 6.0.0)
           version: 4.5 Mesa 18.0.5 Direct Render: Yes
Audio:     Card-1 Advanced Micro Devices [AMD/ATI] Tonga HDMI Audio [Radeon R9 285/380]
           driver: snd_hda_intel bus-ID: 01:00.1
           Card-2 Advanced Micro Devices [AMD/ATI] SBx00 Azalia (Intel HDA)
           driver: snd_hda_intel bus-ID: 00:14.2
           Sound: Advanced Linux Sound Architecture v: k4.15.0-29-generic
Network:   Card: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
           driver: r8169 v: 2.3LK-NAPI port: a000 bus-ID: 08:00.0
           IF: enp8s0 state: up speed: 1000 Mbps duplex: full mac: <filter>
Drives:    HDD Total Size: 7251.5GB (5.9% used)
           ID-1: /dev/sda model: Samsung_SSD_850 size: 250.1GB
           ID-2: /dev/sdb model: Hitachi_HDS72101 size: 1000.2GB
           ID-3: /dev/sdc model: WDC_WD10EZEX size: 1000.2GB
           ID-4: /dev/sdd model: Hitachi_HDS72302 size: 2000.4GB
           ID-5: /dev/sde model: WDC_WD10EZEX size: 1000.2GB
           ID-6: /dev/sdf model: ST1000NM0033 size: 1000.2GB
           ID-7: USB /dev/sdg model: ASMT1153e size: 1000.2GB
Partition: ID-1: / size: 63G used: 11G (19%) fs: ext4 dev: /dev/sda6
RAID:      No RAID devices: /proc/mdstat, md_mod kernel module present
Sensors:   System Temperatures: cpu: 26.0C mobo: N/A gpu: 40.0
           Fan Speeds (in rpm): cpu: 0
Info:      Processes: 293 Uptime: 46 min Memory: 1756.6/15986.4MB Init: systemd runlevel: 5 Gcc sys: 7.3.0
           Client: Shell (bash 4.4.191) inxi: 2.3.56 

Re: How To Keep My Trackball Wakeup Flag Enabled?

Posted: Sun Jul 22, 2018 5:18 pm
by Oblias
Anyone?? Anything would help.... even a pointer in the right direction as to how I could make a script to do this??

Re: How To Keep My Trackball Wakeup Flag Enabled?

Posted: Sun Jul 22, 2018 6:13 pm
by jimallyn
People generally suggest waiting 24 to 48 hours for a response before bumping or getting impatient. The person that knows the answer to your question - and there almost certainly is one - could be at work, or sleeping, or whatever. I must say that, for a newcomer, you've done a fine job getting as far as you have! I've been using Linux for 16 years, and didn't know about that stuff.

There are a series of scripts that run when you boot up, and I imagine you would need to put that command in one of them, but I don't know which one. Look in the rcx.d folders in /etc. And I assume there is a similar process for waking up from suspend.

Welcome to Linux Mint and the Mint forums!

Re: How To Keep My Trackball Wakeup Flag Enabled?

Posted: Sun Jul 22, 2018 7:16 pm
by Oblias
I was not aware that I should have waited for up to 48 hrs before bumping. I am aware now, thanks!

The only reason I have the information that I do have, which I posted, was because I have spent literally hours searching the web for an answer to this issue.

Thanks again, and I shall wait patiently for someone to hopefully help me figure this out.

Re: How To Keep My Trackball Wakeup Flag Enabled?

Posted: Sun Jul 22, 2018 11:55 pm
by AZgl1800
some of my requests for help sit for 4 or 5 days before the "the guy/gal with the answer" happens across your post, and also, I have found that I have had to rethink my "Title Phrasing" to solicit good replies.

ambling along with a lot of extraneous info, seems to irritate a lot of folks.

Re: How To Keep My Trackball Wakeup Flag Enabled?

Posted: Mon Jul 23, 2018 5:41 am
by Oblias
AZgl1500 wrote: Sun Jul 22, 2018 11:55 pm some of my requests for help sit for 4 or 5 days before the "the guy/gal with the answer" happens across your post, and also, I have found that I have had to rethink my "Title Phrasing" to solicit good replies.

ambling along with a lot of extraneous info, seems to irritate a lot of folks.
I really don't know of a way to re-phrase the title of this thread. I would welcome a recommendation.

As to my 'ambling along with a lot of extraneous info', it was my intent to provide that as information by way of my introducing myself to the forum. Certainly did not mean to irritate a lot of folks. Seems I made a grave error. I will be concise and to the point in future posts.

Thank you!

Re: How To Keep My Trackball Wakeup Flag Enabled?

Posted: Mon Jul 23, 2018 6:31 am
by gm10
Personally I'd say you've got a better chance of getting a reply by not bumping your thread and not multi-posting in it, either. A thread with replies implies to me that you are already being helped, so I may not click on it unless the topic interests me (as in this case). Also the forums have a function to look for threads without replies, that makes unanswered threads easy to find for those looking to help.

So back to the present case, I didn't actually know how the wakeup flag was set, so I learned something. Good job with your googling. :)
I don't know if there are better ways but as long as it works that's good enough, right?

I can however help you with setting the flag at boot and resume. For boot-time execution we create this script:

Code: Select all

sudo nano /etc/rc.local
paste this into it (Ctrl+Shift+V to paste):

Code: Select all

#!/bin/sh
echo enabled > /sys/bus/usb/devices/5-4/power/wakeup
Press Ctrl+X, Y, Enter to save.

For execution after a resume we need another script:

Code: Select all

sudo nano /lib/systemd/system-sleep/trackball_wakeup
and we paste this

Code: Select all

#!/bin/sh
case $1/$2 in
post/*)
echo enabled > /sys/bus/usb/devices/5-4/power/wakeup
;;
esac
Save it as above.

Last but not least, for now those two scripts are just text files, to make them executable we do

Code: Select all

sudo chmod +x /etc/rc.local
sudo chmod +x /lib/systemd/system-sleep/trackball_wakeup
Disclaimer: We didn't need to use a text mode editor (or even an editor at all) but it's always good to know how to use one for when you've got nothing else available. Welcome to Linux. ;)

Re: How To Keep My Trackball Wakeup Flag Enabled?

Posted: Mon Jul 23, 2018 8:55 am
by Oblias
Thank you VERY much!

Your solution worked for setting the flag upon reboot, or boot from an off state, however it does not set the flag when waking up from sleep. So, it's 50% effective, and I call that progress!

I also have now learned a bit of how to make executable script files, and I also thank you for that! Any ideas as to why it won't work when the computer wakes?

Re: How To Keep My Trackball Wakeup Flag Enabled?

Posted: Mon Jul 23, 2018 9:36 am
by gm10
Oblias wrote: Mon Jul 23, 2018 8:55 am Any ideas as to why it won't work when the computer wakes?
Actually no, might be it gets executed too early and the system resets it later again? As I said, I have no experience with the flag itself.

Also looking at what I suggested to you I just facepalmed because I took your question too literally. You asked to set the flag on boot and on resume, but on second thought I don't think that's actually necessary, it should be enough if you set it just before you sleep. So let's try, we'll remove the first script again:

Code: Select all

sudo rm /etc/rc.local
and we'll change the second script instead. I'll let you use a GUI editor this time: :D

Code: Select all

xed admin:///lib/systemd/system-sleep/trackball_wakeup
Replace contents with this:

Code: Select all

#!/bin/sh
case "$1" in
    pre)
        echo enabled > /sys/bus/usb/devices/5-4/power/wakeup
        ;;
esac
Now instead of executing "post" sleep we're setting the flag "pre" sleep.

Give it a try, see if it works, I'll be over here enjoying my teaching moment, haha. :P

Re: How To Keep My Trackball Wakeup Flag Enabled?

Posted: Mon Jul 23, 2018 11:01 am
by Oblias
gm10 wrote: Mon Jul 23, 2018 9:36 am
Also looking at what I suggested to you I just facepalmed because I took your question too literally. You asked to set the flag on boot and on resume, but on second thought I don't think that's actually necessary, it should be enough if you set it just before you sleep............

Give it a try, see if it works, I'll be over here enjoying my teaching moment, haha. :P
At first, I didn't quite understand what you meant when you talked about your sudden epiphany. And then all the sudden, it also became clear to me. No reason for me or anyone else to have that flag set when the computer starts, or reboots. The only time it's needed is when it's coming out of sleep. So your logic was indeed quite sound, and the updated script was a complete success.

I'm not saying that at this moment, I understand what all those commands in the script mean, but I can remedy that in due time via study and search.

You have found, and shared, the final solution. Thank you for taking the time and effort to help and to teach!!! 🤓

Re: How To Keep My Trackball Wakeup Flag Enabled?

Posted: Mon Jul 23, 2018 11:12 am
by gm10
Oblias wrote: Mon Jul 23, 2018 11:01 am So your logic was indeed quite sound, and the updated script was a complete success.
That's good to hear!

Enjoy learning more about Linux - it's a bit more hands on than Windows but also offers you much more freedom because of it. Also please take a moment to edit the subject line of the OP and add a [SOLVED] so everybody knows the question has been solved, helps those looking for a solution in the future.

Re: SOLVED: How To Keep My Trackball Wakeup Flag Enabled?

Posted: Mon Jul 23, 2018 11:17 am
by Oblias
Ha, was doing that exact thing, as you were writing your last post...

I do believe I'm going to enjoy LM for a long time, I love to learn!!

Re: How To Keep My Trackball Wakeup Flag Enabled?

Posted: Thu Aug 09, 2018 6:57 am
by thx-1138
gm10 wrote: Mon Jul 23, 2018 9:36 am Replace contents with this:

Code: Select all

#!/bin/sh
case "$1" in
    pre)
        echo enabled > /sys/bus/usb/devices/5-4/power/wakeup
        ;;
esac
Now instead of executing "post" sleep we're setting the flag "pre" sleep.

Give it a try, see if it works, I'll be over here enjoying my teaching moment, haha. :P
...Trying to understand the "why" in the syntax of this ultra-small script above...
hopefully you're in the mood for more teaching moments ;-)

...looking in my 18.3, i also found /lib/systemd/system-sleep/hdparm:

Code: Select all

#!/bin/sh
case $1 in
  post)
    /usr/lib/pm-utils/power.d/95hdparm-apm resume
    ;;
esac
So far so good - Question 1:
The pre & post directives in those scripts above are obviously pretty self-explanatory in what they do, but...
where do those get assigned - why are they being 'recognized' in the first place?
If i understand it correctly, it's systemd-suspend itself which answers that / recognizes pre & post 'automagically'?

...and, Question 2: This page here explains in much detail how 'case' works, ie. why a double semicolon is further needed etc...
However, on a much more elementary level...why is the variable set to "$1"? Why not say "$2", "$7" or...i dunno, say "$George"? :)
The very same guide describes quite a few pages earlier:
Positional parameters...$0 is the name of the script itself, $1 is the first argument, $2 the second, $3 the third, etc etc etc...
Hmmm...

...and now comes what might be the stupidest question i've done since quite some time, you've been warned... :lol:
In the very first script variant that you posted above..."$1/$2"?
Ridiculous as it may sound - but this totally escapes me - why / where / how?

Re: How To Keep My Trackball Wakeup Flag Enabled?

Posted: Thu Aug 09, 2018 7:28 am
by gm10
thx-1138 wrote: Thu Aug 09, 2018 6:57 am Trying to understand the "why" in the syntax of this ultra-small script above...
hopefully you're in the mood for more teaching moments ;-)
Sure, no problem, although I didn't read any of your links, so my answer won't reference them. Not needed, it's all pretty simple.

re Q1: Just read man systemd-suspend.service, it's fairly short and also answers the questions you didn't have yet. ;)

re Q2: If you carefully read that manual then you already understand why it's only $1/the first parameter we care about here.

re Q3: not a stupid question at all, but maybe a stupid answer: the reason is laziness. I had quickly ripped that out of a larger script of mine which handled both parameters (see manual from answer to Q1 for the second parameter, it allows you to handle e.g. suspend and hibernation differently). Both variants work in the present case, but I decided to clean it up/simplify it and add some indentation (not necessary, it's not python, just makes it easier to read) for my revised response in the spirit of my "teaching moment". :idea:

Re: How To Keep My Trackball Wakeup Flag Enabled?

Posted: Thu Aug 09, 2018 8:13 am
by thx-1138
gm10 wrote: Thu Aug 09, 2018 7:28 am...why it's only $1/the first parameter we care about here...
...ripped that out of a larger script of mine which handled both parameters...
...thank you gm10 - that's exactly the piece(s) of info that i needed to 'decode' the above :)