View Single Post
Old 03-16-2014, 02:20 AM   #10
peterson
Connoisseur
peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.
 
Posts: 74
Karma: 889004
Join Date: Mar 2014
Device: Kindle PW2


The alarm seems to work very well. Still some minor parts I am unsure about, but it definitely works. Below is a shell function that will wait for a given amount of time. Last night I set my weather screensaver script to run in 30 minute intervals, and it did.

According to the log I created and the accompanying dmesg output, the device woke up every 30 minutes, downloaded the latest weather report, and then went back to sleep 90 seconds after that.

Code:
# the RTC to use
RTC=0

OUTPUTFILE=/tmp/alarmlogger

# sets an RTC alarm
# arguments: $1 - time in seconds from now

wait_for () {
        TS=`date +%s` 
        TS=$(($TS + $1))
        echo "Setting alarm to $TS ($1 seconds in the future)" >>$OUTPUTFILE

        echo 0 > /sys/class/rtc/rtc$RTC/wakealarm
        echo $TS > /sys/class/rtc/rtc$RTC/wakealarm

        if test $TS -ne `cat /sys/class/rtc/rtc$RTC/wakealarm`; then
                echo "Failure setting alarm on rtc$RTC, wanted $TS, got `cat /sys/class/rtc/rtc$RTC/wakealarm`" >>$OUTPUTFILE
        else
                echo "Success on rtc$RTC" >>$OUTPUTFILE

                # wait for the alarm to end
                while test 1 -eq 1; do
                        if test 0 -eq $((`cat /sys/class/rtc/rtc$RTC/wakealarm`)); then
                                break;
                        elif test `date +%s` -gt $((`cat /sys/class/rtc/rtc$RTC/wakealarm`)); then
                                break;
                        else
                                sleep 1
                        fi
                done
        fi

        # not sure whether this is required
        lipc-set-prop com.lab126.powerd -i deferSuspend 1
}
peterson is offline   Reply With Quote