Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Amazon Kindle > Kindle Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 04-08-2014, 08:48 AM   #16
NiLuJe
BLAM!
NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.
 
NiLuJe's Avatar
 
Posts: 13,506
Karma: 26047202
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
KUAL/the Kindlet framework *might* be killing child processes on exit, can't remember right now.

Try starting you script over ssh (making sure it's correctly backgrounded).

Last edited by NiLuJe; 04-11-2014 at 03:56 PM.
NiLuJe is offline   Reply With Quote
Old 04-11-2014, 03:50 PM   #17
Eradicatore
i void warranties
Eradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheese
 
Eradicatore's Avatar
 
Posts: 22
Karma: 1038
Join Date: Apr 2014
Location: Wisconsin
Device: Kindle PW2
Hi, thanks for the reply. Sorry, for not getting back earlier. So I had already done this from ssh, but today I re-verified. I was logging into the kindle with ssh, I started the python script directly like this:

./ssloop.py &

And then I saw it update the screen a few times. Then, I exited my ssh login, and I unplugged USB. I saw 3 more screen updates (1 per minute) and then nothing. I would log back in with ssh, and typed:

ps -ef | grep ssloop

and the process is gone. I wondered if "screen" was available but it's not there. Not sure if that would help anyway. Is there any way from /var/logs to see who kills given processes?
Eradicatore is offline   Reply With Quote
Advert
Old 04-11-2014, 04:01 PM   #18
NiLuJe
BLAM!
NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.
 
NiLuJe's Avatar
 
Posts: 13,506
Karma: 26047202
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
No, but you can always go the old-fashioned way: riddle it with printfs, wrap it in something that pipes stderr & stdout to somewhere, and see where it dies.
NiLuJe is offline   Reply With Quote
Old 04-11-2014, 05:25 PM   #19
Eradicatore
i void warranties
Eradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheese
 
Eradicatore's Avatar
 
Posts: 22
Karma: 1038
Join Date: Apr 2014
Location: Wisconsin
Device: Kindle PW2
Yea, good point. AKA brute force.

I did verify that it will run fine for 20 minutes if I leave it plugged in and ssh logged in. So my only fear with a bunch of printf's and pipes is that it's getting killed abruptly on the way to suspend/deep sleep so it won't really log much.

So I'm wondering if something needs to go in /etc/upstart, or I need to use something like start-stop-daemon for it to not be killed in low power. That's all that I can think of that peterson's "onlinescreensaver" does (other than mine is python). I haven't actually tried the one from peterson. Do you NiLuJe know if it really works?

I mean it seems logical. Kindle would want to kill anything and everything it didn't know about when suspending. Maybe there is some other way to kick off a script with a RTC event happens? What I don't even know right now, since my process is dying, is if the RTC is really waking the kindle back up from suspend or not.
Eradicatore is offline   Reply With Quote
Old 04-11-2014, 11:19 PM   #20
Eradicatore
i void warranties
Eradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheese
 
Eradicatore's Avatar
 
Posts: 22
Karma: 1038
Join Date: Apr 2014
Location: Wisconsin
Device: Kindle PW2
Ok, I got it. I had a mistake in my logic. I thought it would just give two states. "active" or "screenSaver". With logging I found out easily that I was stopping on purpose, because the state wasn't "screenSaver" anymore. I did this originally to give an easy way to stop the quote rotations. The user just had to hit the wake button. But I failed to realize that there are two non-"active" states I want to let to run.

I'll post my "final" python here. I now want to make the simple adjustments to not do the rotation at night stave more power. Again, similar to Peterson's app, but since I don't have any online grabbing to do, I dumbed it all down into one simple python script.

Justin
Eradicatore is offline   Reply With Quote
Advert
Old 04-11-2014, 11:30 PM   #21
Eradicatore
i void warranties
Eradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheese
 
Eradicatore's Avatar
 
Posts: 22
Karma: 1038
Join Date: Apr 2014
Location: Wisconsin
Device: Kindle PW2
Fixed...

Here's the working one without the update to avoid changes at night (when nobody is there to see it in the office):

Code:
#!/usr/bin/python
import time;
import glob;
import random;
import subprocess;

def mainLoop ():
   # first make sure the screen saver is showing
   state = subprocess.check_output(['lipc-get-prop', 'com.lab126.powerd', 'state']).rstrip();
   while (state == "active"):
      subprocess.call(['lipc-set-prop', 'com.lab126.powerd', 'powerButton', '1']);
      time.sleep(1);
      state = subprocess.check_output(['lipc-get-prop', 'com.lab126.powerd', 'state']);

   last = "";
   while 1 == 1:
      state = subprocess.check_output(['lipc-get-prop', 'com.lab126.powerd', 'state']).rstrip();
      if (state ==  "active"):
          # User wants to stop, so they pressed "wake" button
          # maybe rm .lock file here?
          break;

      file = random.choice(glob.glob('/mnt/us/extensions/quoteRotation/bin/png/*.png'));
      # should add check for empty list of png's here
      while file == last:
          file = random.choice(glob.glob('/mnt/us/extensions/quoteRotation/bin/png/*.png'));

      last = file;
      tstring = time.strftime("%H:%M:%S")
      subprocess.call(['eips','-f','-g',file]);
      sleepForMin(60);

def getCurrTimeInSec ():
   "This function returns current time in seconds"
   return int(subprocess.check_output(['date','+%s']).rstrip())

def sleepForMin (mins):
   "this function will use the RTC to wake back up after so many minutes"
   endTime = str(getCurrTimeInSec() + (mins * 20));

   # disable/reset current alarm
   subprocess.call("echo 0 > /sys/class/rtc/rtc0/wakealarm", shell=True)

   # set new alarm
   subprocess.call("echo {} > /sys/class/rtc/rtc0/wakealarm".format(endTime), shell=True)

   alarmContents = (subprocess.check_output(['cat','/sys/class/rtc/rtc0/wakealarm']).rstrip())

                                                                                              
   if (endTime == alarmContents):                                                             
      while getCurrTimeInSec() < int(endTime):                                                
         remainingWait = int(endTime) - getCurrTimeInSec()                                    
         if (remainingWait > 0):                                                              
            # wait for device to suspend or to resume - this covers the sleep period during which the
            # time counting does not work reliably                                                   
            subprocess.check_output("lipc-wait-event -s {} com.lab126.powerd resuming || true".format(str(remainingWait)), shell=True)
   else:                                                                                                                              
      print "failed compare"                                                                                                          
                                                                                                                                      
   # not sure whether this is required                                                                                                
   #subprocess.check_output("lipc-set-prop com.lab126.powerd -i deferSuspend 1", shell=True)                                          
   return                                                                                                                             
                                                                                                                                      
mainLoop()

Last edited by Eradicatore; 04-12-2014 at 11:04 AM.
Eradicatore is offline   Reply With Quote
Old 04-12-2014, 08:29 AM   #22
NiLuJe
BLAM!
NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.
 
NiLuJe's Avatar
 
Posts: 13,506
Karma: 26047202
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
Ha!
NiLuJe is offline   Reply With Quote
Old 04-12-2014, 08:38 AM   #23
knc1
Going Viral
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
Is there really 20 Kindle-Seconds in a Kindle-Minute?

(There is, or at least there was, in long distance telephone switches, but in Kindles?)
knc1 is offline   Reply With Quote
Old 04-12-2014, 10:10 AM   #24
Eradicatore
i void warranties
Eradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheese
 
Eradicatore's Avatar
 
Posts: 22
Karma: 1038
Join Date: Apr 2014
Location: Wisconsin
Device: Kindle PW2
LOL, I'm busy. Who has time to actually wait a minute for anything these days.
Eradicatore is offline   Reply With Quote
Old 04-15-2014, 06:42 PM   #25
Eradicatore
i void warranties
Eradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheese
 
Eradicatore's Avatar
 
Posts: 22
Karma: 1038
Join Date: Apr 2014
Location: Wisconsin
Device: Kindle PW2
Latest version with some nice updates

Figured I would share this version. Eventually I should put it all on github, with all the png's I've made so far with quotes from Carlin, Lennon, Wilde, Ford, Berra, and others.

I added:
- low batt warning, shows a png at 7% or less and waits for charger insert
- only update from 8am to 5pm
- added logging so I could just be sure of the update timing

Code:
#!/usr/bin/python
import time;
import glob;
import random;
import subprocess;

def mainLoop ():
   fo = open("/mnt/us/extensions/quoteRotation/bin/log.txt", "a")
   fo.write("\n=== starting new rotation ===\n");

   # first make sure the screen saver is showing
   state = subprocess.check_output(['lipc-get-prop', 'com.lab126.powerd', 'state']).rstrip();
   while (state == "active"):
      subprocess.call(['lipc-set-prop', 'com.lab126.powerd', 'powerButton', '1']);
      time.sleep(1);
      state = subprocess.check_output(['lipc-get-prop', 'com.lab126.powerd', 'state']);

   last = "";

   while 1 == 1:
      # User wants to stop, so they pressed "wake" button
      state = subprocess.check_output(['lipc-get-prop', 'com.lab126.powerd', 'state']).rstrip();
      if (state ==  "active"):
          # maybe rm .lock file here?
          break;

      # Check if we should show low battery warning
      blevel = int(subprocess.check_output(['lipc-get-prop', 'com.lab126.powerd', 'battLevel']).rstrip());
      if (blevel < 8):
         subprocess.call(['eips','-f','-g','/mnt/us/extensions/quoteRotation/bin/png/lowBatt.png']);
         # Seems dangerous, but wait here for a charging event without a -s timeout.
         subprocess.check_output("lipc-wait-event com.lab126.powerd charging", shell=True)

      # 1 for charging, 0 if not 
      #cstate =  int(subprocess.check_output(['lipc-get-prop', 'com.lab126.powerd', 'isCharging']).rstrip());

      file = random.choice(glob.glob('/mnt/us/extensions/quoteRotation/bin/png/*.png'));
      # should add check for empty list of png's here
      while file == last:
          file = random.choice(glob.glob('/mnt/us/extensions/quoteRotation/bin/png/*.png'));
          
      last = file;
          
      tstring = time.strftime("%H:%M:%S")
      mstring = int(time.strftime("%M")) 
      hstring = int(time.strftime("%H")) #24Hour
                  
      # want to sleep from 5pm to 8am
      if (hstring < 8):
         sleepTimeMin = (60 - mstring) + ((7 - hstring) * 60)
      elif (hstring > 16):
         sleepTimeMin = ((60 - mstring) + ((23 - hstring) * 60)) + (8 * 60)
      else:
         sleepTimeMin = 60
         
      fo.write ("{}: sleep for {} minutes => screensaver path: {}\n".format(tstring,sleepTimeMin,file));
      fo.flush();
                     
      subprocess.call(['eips','-f','-g',file]);
      sleepForMin(sleepTimeMin);
                                                                      

def getCurrTimeInSec ():
   "This function returns current time in seconds"
   return int(subprocess.check_output(['date','+%s']).rstrip())

def sleepForMin (mins):
   "this function will use the RTC to wake back up after so many minutes"
   endTime = str(getCurrTimeInSec() + (mins * 60)); 
   
   # disable/reset current alarm
   subprocess.call("echo 0 > /sys/class/rtc/rtc0/wakealarm", shell=True)
   
   # set new alarm
   subprocess.call("echo {} > /sys/class/rtc/rtc0/wakealarm".format(endTime), shell=True)
   
   alarmContents = (subprocess.check_output(['cat','/sys/class/rtc/rtc0/wakealarm']).rstrip())
   
   if (endTime == alarmContents):
      while getCurrTimeInSec() < int(endTime):
         remainingWait = int(endTime) - getCurrTimeInSec()
         if (remainingWait > 0):
            # wait for device to suspend or to resume - this covers the sleep period during which the
            # time counting does not work reliably
            subprocess.check_output("lipc-wait-event -s {} com.lab126.powerd resuming || true".format(str(remainingWait)), shell=True)
   else:
      print "failed compare"

   # not sure whether this is required
   #subprocess.check_output("lipc-set-prop com.lab126.powerd -i deferSuspend 1", shell=True)
   return

mainLoop()
Eradicatore is offline   Reply With Quote
Old 04-15-2014, 10:18 PM   #26
Eradicatore
i void warranties
Eradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheeseEradicatore can extract oil from cheese
 
Eradicatore's Avatar
 
Posts: 22
Karma: 1038
Join Date: Apr 2014
Location: Wisconsin
Device: Kindle PW2
OK. Here is the finished product for my office wall. Thanks for everyone's help!!!

https://www.dropbox.com/s/0h56jrz6sl...2002.08.15.jpg

Last edited by Eradicatore; 04-15-2014 at 10:22 PM.
Eradicatore is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
invoking sql in a shell script Mingyar Kobo Developer's Corner 17 05-31-2013 06:50 PM
pdf to txt shell script Mr.Castro0o PDF 0 03-27-2013 07:39 AM
Shell script to wait for user input from K3g keyboard jmseight Kindle Developer's Corner 33 04-01-2012 04:32 PM
A way to execute files without shell access?!? scotsman iRex 8 03-13-2009 07:35 AM
Script to convert a directory full of files? mdibella Kindle Formats 2 10-14-2008 01:21 PM


All times are GMT -4. The time now is 08:42 PM.


MobileRead.com is a privately owned, operated and funded community.