Menu

Main Menu
Talk Get Daily Search

Member's Online

    User Name
    Password

    [Announce] [SFOS] Volume/Camera Button Monitor

    Reply
    Page 2 of 4 | Prev |   1   2   3     4   | Next
    wolke | # 11 | 2020-01-21, 20:28 | Report

    Originally Posted by
    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)


    Originally Posted by
    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

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 2 Users Say Thank You to wolke For This Useful Post:
    Amboss, juiceme

     
    mosen | # 12 | 2020-01-21, 21:25 | Report

    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.

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 2 Users Say Thank You to mosen For This Useful Post:
    Amboss, juiceme

     
    wolke | # 13 | 2020-01-21, 21:52 | Report

    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

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 4 Users Say Thank You to wolke For This Useful Post:
    Amboss, juiceme, mosen, mrsellout

     
    Kabouik | # 14 | 2020-01-21, 22:22 | Report

    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.

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 3 Users Say Thank You to Kabouik For This Useful Post:
    Amboss, juiceme, mosen

     
    mosen | # 15 | 2020-01-21, 22:34 | Report

    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?

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 2 Users Say Thank You to mosen For This Useful Post:
    Amboss, juiceme

     
    olf | # 16 | 2020-01-22, 00:07 | Report

    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

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by olf; 2020-01-22 at 19:52.
    The Following 10 Users Say Thank You to olf For This Useful Post:
    Amboss, Halftux, Jordi, juiceme, Kabouik, lal, mosen, mrsellout, robthebold, wolke

     
    wolke | # 17 | 2020-01-22, 05:27 | Report

    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

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by wolke; 2020-01-22 at 05:35.
    The Following 4 Users Say Thank You to wolke For This Useful Post:
    Amboss, imaginaryenemy, juiceme, mosen

     
    wolke | # 18 | 2020-01-22, 05:38 | Report

    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);
    +      }
         }
       }
     }

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 4 Users Say Thank You to wolke For This Useful Post:
    Amboss, imaginaryenemy, juiceme, mosen

     
    Kabouik | # 19 | 2020-01-22, 10:54 | Report

    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

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 5 Users Say Thank You to Kabouik For This Useful Post:
    Amboss, imaginaryenemy, juiceme, mosen, wolke

     
    wolke | # 20 | 2020-01-28, 23:25 | Report

    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-

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 5 Users Say Thank You to wolke For This Useful Post:
    juiceme, Kabouik, mosen, olf, robthebold

     
    Page 2 of 4 | Prev |   1   2   3     4   | Next
vBulletin® Version 3.8.8
Normal Logout