View Single Post
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