Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto start KindleLazy #7

Open
sunshinetech007 opened this issue Feb 26, 2019 · 6 comments
Open

Auto start KindleLazy #7

sunshinetech007 opened this issue Feb 26, 2019 · 6 comments

Comments

@sunshinetech007
Copy link

sunshinetech007 commented Feb 26, 2019

Ok one more thing :) I've been trying to get KindleLazy to autostart, but it wont' start when calling start.sh from udev. It works fine if I run start.sh on the command line. It works fine if I run it from a different script. I've added some logging stuff to try and troubleshoot. Here is my start.sh at this point.

#!/bin/sh
#start KindleLazy by inserting modules and running background app
echo "start.sh triggered" >> /tmp/udev.log
cd "$(dirname "$0")"
echo "user is:" >> /tmp/udev.log
echo $USER >> /tmp/udev.log
echo "whoami=" >> /tmp/udev.log
whoami >> /tmp/udev.log
echo "dirname var is:" >> /tmp/udev.log
echo "$(dirname "$0")" >> /tmp/udev.log
echo "working dir is" >> /tmp/udev.log
pwd >> /tmp/udev.log
sleep 8
{
insmod hid.ko
sleep 1
insmod usbhid.ko
sleep 1
insmod mousedev.ko
sleep 1
killall kindlelazy
sleep 3
./kindlelazy &
} >> /tmp/udev.log 2>>/tmp/udev.log

It works just fine using [root@kindle bin]# ./start.sh - I get this output:

start.sh triggered
user is:
root
whoami=
root
dirname var is:
bin
working dir is
/mnt/us/extensions/KindleLazy/bin
killall: kindlelazy: no process killed`

When I call start.sh from a udev rule, I get this:

start.sh triggered
user is:

whoami=
root
dirname var is:
/mnt/us/extensions/KindleLazy/bin
working dir is
/mnt/us/extensions/KindleLazy/bin
killall: kindlelazy: no process killed
ERROR opening evdev2 device
: No such file or directory
ERROR opening evdev3 device
: No such file or directory
ERROR Opening XDisplay
: No such file or directory
KindleLazy v0.9 - cearp

opened evdev1 touch screen`

My udev rule is this, and it works fine and calls the script every time.

KERNEL=="1-1", ATTR{idVendor}=="0458", ATTR{idProduct}=="0189", RUN+="/mnt/us/extensions/KindleLazy/bin/start.sh"

I tried putting a 2nd script in the KindleLazy directory that then calls bin/start.sh, because it looks like that's how the UI calls it, but that didn't help either. Calling the exact same full path to the script /mnt/us/extensions/KindleLazy/bin/start.sh also works, as long as it's command line.

The modules are all loaded.

[root@kindle bin]# lsmod
Module Size Used by
mousedev 9072 0
usbhid 18029 0
hid 67608 1 usbhid
ath6kl_sdio 197174 0
cfg80211 170499 1 ath6kl_sdio
g_file_storage 35635 0
arcotg_udc 26338 1 g_file_storage
cyttsp4_mt_b 8180 0
cyttsp4_core 41372 2
cyttsp4_i2c 2563 1
fuse 60020 2
ehci_hcd 53568 0
fsl_otg_arc 15613 3 ehci_hcd
mxc_epdc_fb 89693 3
mxc_epdc_eink 8771 1 mxc_epdc_fb

The character devices are all there and they work.

[root@kindle bin]# evtest /dev/input/event2
Input driver version is 1.0.1
Input device ID: bus 0x3 vendor 0x458 product 0x189 version 0x101
Input device name: "Genius Wireless Mouse"
Supported events:
Event type 0 (Sync)
Event type 1 (Key)
Event code 272 (LeftBtn)
Event code 273 (RightBtn)
Event code 274 (MiddleBtn)
Event code 275 (SideBtn)
Event code 276 (ExtraBtn)
Event type 2 (Relative)
Event code 0 (X)
Event code 1 (Y)
Event code 6 (HWheel)
Event code 8 (Wheel)
Event type 4 (Misc)
Event code 4 (ScanCode)
Testing ... (interrupt to exit)

The only difference I can find is that $USER is root at all times except when i'm calling start.sh from udev and then get the ERROR opening evdev2 device. I'm at a loss :/

@llakssz
Copy link
Owner

llakssz commented Feb 26, 2019

Nice idea, I never thought about this. Maybe because I (like most people) rarely reboot their kindle so it's not a big problem to start KindleLazy after each reboot.
I would presonally ask at mobileread and see what advice the kindle/unix gurus give, maybe it's something simple just being overlooked?

Maybe the /dev/input/event2 device simply isn't ready at that time KindleLazy is started? That's all I can assume from the error message.
Maybe it's possible with udev to make it run only after the input device is ready?

I guess it's possible to do a little investigation using the script.sh file, for example seeing if you can see if the event2 device is readable/exists at that time.

@sunshinetech007
Copy link
Author

Ok I'll post there. I do think it's a timing issue and some things just are not loaded yet, and udev is sensitive about how long a script runs so I can't wait forever. One workaround is to use the "at" command to hand off script execution from udev, but that command doesn't seem to be present on the kindle. I downloaded some other arm linux distros and couldn't find "at", either.

So you said you only start kindlelazy after a reboot....whenever my kindle goes to sleep and I wake it up, I have to restart kindlelazy. Does yours stay functional as long as you don't restart it?

After it sleeps and I wake it up, everything is working technically. modules are there, events get keycodes, and kindlelazy process is present, but it won't turn the page until I go start it again. That's what I was trying to avoid with this.

@sunshinetech007
Copy link
Author

sunshinetech007 commented Feb 27, 2019

Ok, I got it to work! See mobileread thread for the info if you're interested. Any interest in adding the changes here? Not sure how that works since you files have to be placed outside of /mnt/us and can't just be dropped in /mnt/us/extensions. The trick for XOpenDisplay to work under udev context was to export a display variable. Also I had to start one script, then hand off to "start.sh &" for some reason. I don't know why. Other main changes were adding some timing, and using kill -9 instead of killall. Killall wouldn't terminate process started under the udev context.

@llakssz
Copy link
Owner

llakssz commented Feb 28, 2019

Cool that you got some progress.
I'll take a look.
It's only loading KindleLazy at boot, right? Or does this method make it happen at every 'wake', making it so we no longer need to run manually KindleLazy ever again?
Because that would be the best thing! Kill at screen off, and start at screen on.

EDIT -- Ah, my mistake. The clue is in the word udev rules, so this runs when you plug the presenter in, fantastic!!

My kindle works exactly the same as your regarding KindleLazy, it needs to be started/restarted every once in a while etc. I haven't used it in a while to be honest so I forget the exact way to use it!

@sunshinetech007
Copy link
Author

yeah so far with my testing, it loads and unloads itself under every scenario properly - definitely not for just at bootup. It loads and unloads upon wake, sleep, plug in, unplug. I have not had to manually start it once for any reason yet.

@pureair
Copy link

pureair commented Mar 14, 2024

For anyone interested, the final script written by OP is here: https://www.mobileread.com/forums/showpost.php?p=3815253&postcount=261
I did some real search to find it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants