Reply
Thread Tools
Posts: 986 | Thanked: 1,526 times | Joined on Jul 2010
#11
Do you think it is possible to do a patchmanager3 patch from that script and execute code on Key events?
hmm? you mean apply patches on the fly via cmdline, or do you mean to install this script as a patch, or something else? (im pretty sure the answer is no either way)


Or is it a potential battery hog?
n9-button-monitor used almost no battery/cpu, but this works very differently from the already-existing hwbtn DBUS iface found on harmattan. afaict, sf-button-monitor uses very little CPU when buttons arent being pressed, but there is definitely the potential for performance problems

nice! are you running this as root btw, or does nemo have write perms on that brightness device? if the latter, ill happily add this as an action, and kb as a button, if it works at the same time as mine and you can test it on yours
__________________
~ teleshoes ~
 

The Following 2 Users Say Thank You to wolke For This Useful Post:
mosen's Avatar
Community Council | Posts: 1,669 | Thanked: 10,225 times | Joined on Nov 2014 @ Lower Rhine
#12
I was thinking how to have the script always running conveniently.
Monitoring it i found no obvious cpu usage, thats nice.

As a patch it would be started after boot but patches are ment to alter existing files, not to start up scripts, right?

They way i am doing currently is okish, only after boot i need to manually hit the Kbdlight starter and the script runs until killed.

But how to do this correct, is my noob question

The script runs without superuser privs, as regular nemo user.
 

The Following 2 Users Say Thank You to mosen For This Useful Post:
Posts: 986 | Thanked: 1,526 times | Joined on Jul 2010
#13
no idea the 'correct' way to do this, but patchmanager is probably not a good way to do it, if you even can make it start a long-lived script.

i personally do all my auto-start crap like this:

1) make service file to run /usr/local/bin/autostart
Code:
nemo@sx:~$ cat /usr/lib/systemd/user/auto-start.service
[Unit]
Description=Auto-start stuff after lipstick
Requires=lipstick.service
After=lipstick.service

[Service]
Type=oneshot
ExecStart=/usr/local/bin/autostart
RemainAfterExit=yes

[Install]
WantedBy=user-session.target
2) make that service user-session.target wants:
Code:
nemo@sx:~$ ls -al /home/nemo/.config/systemd/user/auto-start.service /home/nemo/.config/systemd/user/user-session.target.wants/auto-start.service 
lrwxrwxrwx 1 nemo nemo 40 Jan 19 02:55 /home/nemo/.config/systemd/user/auto-start.service -> /usr/lib/systemd/user/auto-start.service
lrwxrwxrwx 1 nemo nemo 40 Jan 19 02:55 /home/nemo/.config/systemd/user/user-session.target.wants/auto-start.service -> /usr/lib/systemd/user/auto-start.service
3) then i stick all sorts of stuff in /usr/local/bin/autostart:
Code:
nemo@sx:~$ cat /usr/local/bin/autostart 
#!/bin/sh
PATH=/home/nemo/bin:$PATH

/home/nemo/bin/screen-daemon backup-daemon --start
/home/nemo/bin/screen-daemon email-daemon --start
/home/nemo/bin/screen-daemon button-monitor --start
sudo cpu-enable fast
aliendalvik-post-start
__________________
~ teleshoes ~
 

The Following 4 Users Say Thank You to wolke For This Useful Post:
Posts: 1,335 | Thanked: 3,931 times | Joined on Jul 2010 @ Brittany, France
#14
Thanks to both of you for progressing this fast! I didn't actually had the time to try myself and you already got something working. I guess I'll wait until your changes are merged Mosen. :>

Originally Posted by mosen View Post
I guess the 100 is due to TheKits kernel mod to make it usable in sfos xkbd, right @kabouik?
The limit with xkb is 255, not 100, if I am not mistaken.
 

The Following 3 Users Say Thank You to Kabouik For This Useful Post:
mosen's Avatar
Community Council | Posts: 1,669 | Thanked: 10,225 times | Joined on Nov 2014 @ Lower Rhine
#15
Thanks for the explanation @wolke. That is some cool stuff. Will do for sure but i realize i derail your thread into things not related to your original topic.

In that regard it would be most interesting and useful to not only listen from one source $INPUT_DEV but multiple ones.

On Proš we have
/dev/input/by-path/platform-soc\:gpio_keys-event
For volume up, cam-button and Kbd-state

/dev/input/by-path/platform-c17a000.i2c-event-kbd
For the keys on the hwkbd

/dev/input/event0
For volume down and the power button.

How to combine those sources in one script to have all keys available to assign actions too?
 

The Following 2 Users Say Thank You to mosen For This Useful Post:
olf's Avatar
Posts: 304 | Thanked: 1,246 times | Joined on Aug 2015
#16
Originally Posted by mosen View Post
For deploying (and deleting when uninstalling) these files per RPM, you may use mount-sdcard's spec file as a template.
It also provides an example of a simple "one-shot" systemd system unit being deployed. Note that you have to deploy a user unit at the slightly different path /etc/systemd/user/ (= %{_sysconfdir}/systemd/user/, but do not use the OS' path /usr/lib/systemd/user/ as shown in section 1).
You also have to let RPM create the [Install] section links (result shown by @wolke in section 2) by a systemctl --user enable <unit> in a %post section and delete them per systemctl --user disable <unit> in a %preun section. Do not create them manually (either literally or in an RPM).

@mosen, you may even clone ("fork" in Github / Gitlab parlance) the mount-sdcard git repository as a starting point, as the git directory structure seems to fit well.

RPMs can be easily built on the device per:

* Preparation (once)
  • Creating necessary directories as nemo:
    Code:
    cd
    mkdir -p rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS}
  • Install rpmbuild (as root):
    Code:
    pkcon install rpm-build
* Building RPMs
  • Always as a simple user, never as root!
  • Download source tarball:
    Code:
    cd ~/rpmbuild/SOURCES/
    curl -LO <https://github.com/mosen/%{name}/archive/%{version}/%{name}-%{version}.tar.gz>
  • Extract and copy spec file:
    Code:
    cd ~/rpmbuild/
    tar -xvzf SOURCES/<%{name}-%{version}>.tar.gz
    cp <%{name}-%{version}>/rpm/*.spec SPECS/
  • Finally build the RPM per
    Code:
    rpmbuild -ba SPECS/<%{name}-%{version}>.spec

The only RPM documentation which comes somewhat close to a reference is still (though old and unmaintained): http://ftp.rpm.org/max-rpm/index.html
Plus many, many guides for noobs, absolute beginners, fresh starters, DAUs etc. exist (but none for advanced packagers) with lots of examples but no real explanations. The least worse of those are probably https://rpm-guide.readthedocs.io/en/latest/ and https://docs.fedoraproject.org/en-US...ide/index.html

P.S.: Better substitute every occurrence of /home/nemo/ in section 3 with ~/ to make it work for every user (as Jolla slowly prepares SailfishOS for multiple users).

HTH

Last edited by olf; 2020-01-22 at 19:52.
 

The Following 10 Users Say Thank You to olf For This Useful Post:
Posts: 986 | Thanked: 1,526 times | Joined on Jul 2010
#17
Originally Posted by mosen View Post
How to combine those sources in one script to have all keys available to assign actions too?
try doing something like:
open $fh, "-|", "cat", "file1", "file2";
see if that works.

im not sure its a good idea to do the kb events one tho, that device probably gets a LOT of output as you type, and my script assumes relatively infrequent events

EDIT: of course the above doesnt work, wasnt thinking. use IO::Select and do can_read
__________________
~ teleshoes ~

Last edited by wolke; 2020-01-22 at 05:35.
 

The Following 4 Users Say Thank You to wolke For This Useful Post:
Posts: 986 | Thanked: 1,526 times | Joined on Jul 2010
#18
try something like this:
(untested on my side, and i wont be trying to support keyboard keys, i think)
Code:
diff --git a/src/sf-button-monitor b/src/sf-button-monitor
index fd08e4e..ffe8c9d 100755
--- a/src/sf-button-monitor
+++ b/src/sf-button-monitor
@@ -166,12 +166,14 @@ sub main(@){
   my @pattern;
   my $lastButtonMillis = nowMillis();
   open $inputDevFH, "< $INPUT_DEV";
+  open $kbDevFH, "< $KEYBOARD_DEV";
 
   my $select = IO::Select->new();
   $select->add($inputDevFH);
+  $select->add($kbDevFH);
 
   while(1){
-    my ($buttonId, $value) = readButtonEvent($inputDevFH);
+    my ($buttonId, $value) = readButtonEvent($select);
 
     my $now = nowMillis();
     my $elapsedMillis = $now - $lastButtonMillis;
@@ -212,15 +214,18 @@ sub main(@){
 
 #blocks until a valid button press/release event and then returns it
 sub readButtonEvent($){
-  my ($inputDevFH) = @_;
+  my ($select) = @_;
   my $byteStr;
   while(1){
-    read $inputDevFH, $byteStr, 16;
-    my @bytesDec = map {ord $_} split //, $byteStr;
-    my $buttonId = $bytesDec[10];
-    my $value = $bytesDec[12];
-    if(defined $OK_BUTTON_IDS{$buttonId}){
-      return ($buttonId, $value);
+    my @fhs = $select->can_read();
+    if(@fhs > 0){
+      read $fhs[0], $byteStr, 16;
+      my @bytesDec = map {ord $_} split //, $byteStr;
+      my $buttonId = $bytesDec[10];
+      my $value = $bytesDec[12];
+      if(defined $OK_BUTTON_IDS{$buttonId}){
+        return ($buttonId, $value);
+      }
     }
   }
 }
__________________
~ teleshoes ~
 

The Following 4 Users Say Thank You to wolke For This Useful Post:
Posts: 1,335 | Thanked: 3,931 times | Joined on Jul 2010 @ Brittany, France
#19
Not directly related to wolke's script, but related to the current discussion: we now have keyboard backlight support on the Proš with mce thanks to Elros34: https://github.com/sailfish-on-fxtec...ment-577118740
 

The Following 5 Users Say Thank You to Kabouik For This Useful Post:
Posts: 986 | Thanked: 1,526 times | Joined on Jul 2010
#20
added a bunch of features:

conditions: always, screenLocked, screenUnlocked, home, app(REGEX), noapp, anyapp, android

actions: cmd(SHELL_CMD), torch, screenshot, reboot, shutdown, openCamera, selfie, newAlarm, newNote, writeEmail

patterns: e.g: VU(VD VD) => hold V+, press V- twice, release V-
__________________
~ teleshoes ~
 

The Following 5 Users Say Thank You to wolke For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 14:18.