-
Notifications
You must be signed in to change notification settings - Fork 9
/
kindle-gphotos.sh
137 lines (109 loc) · 3.6 KB
/
kindle-gphotos.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/sh
PWD=$(pwd)
LOG="/mnt/us/gphotos.log"
SLEEP_MINUTES=1440 #24h
FBINK="fbink -q"
FONT="regular=/usr/java/lib/fonts/Palatino-Regular.ttf"
### uncomment/adjust according to your hardware
#PW3
FBROTATE="/sys/devices/platform/imx_epdc_fb/graphics/fb0/rotate"
BACKLIGHT="/sys/devices/platform/imx-i2c.0/i2c-0/0-003c/max77696-bl.0/backlight/max77696-bl/brightness"
#PW2
#FBROTATE="/sys/devices/platform/mxc_epdc_fb/graphics/fb0/rotate"
#BACKLIGHT="/sys/devices/system/fl_tps6116x/fl_tps6116x0/fl_intensity"
wait_wlan_connected() {
return `lipc-get-prop com.lab126.wifid cmState | grep CONNECTED | wc -l`
}
wait_wlan_ready() {
return `lipc-get-prop com.lab126.wifid cmState | grep -e READY -e PENDING -e CONNECTED | wc -l`
}
### Dim Backlight
echo -n 0 > $BACKLIGHT
### Prepare Kindle, shutdown framework etc.
echo "------------------------------------------------------------------------" >> $LOG
echo "`date '+%Y-%m-%d_%H:%M:%S'`: Starting up, killing framework et. al." >> $LOG
### stop processes that we don't need
stop lab126_gui
### give an update to the outside world...
echo 0 > $FBROTATE
$FBINK -w -c -f -m -t $FONT,size=20,top=410,bottom=0,left=0,right=0 "Starting gphotos..." > /dev/null 2>&1
#echo 3 > $FBROTATE
sleep 1
### keep stopping stuff
stop otaupd
stop phd
stop tmd
stop x
stop todo
stop mcsd
stop archive
stop dynconfig
stop dpmd
stop appmgrd
stop stackdumpd
#stop powerd ### otherwise the pw3 is not going to suspend to RAM?
sleep 2
# At this point we should be left with a more or less Amazon-free environment
# I leave
# - powerd & deviced
# - lipc-daemon
# - rcm
# running.
### If we have a wan module installed...
#if [ -f /usr/sbin/wancontrol ]
#then
# wancontrol wanoffkill
#fi
### Disable Screensaver
lipc-set-prop com.lab126.powerd preventScreenSaver 1
echo "`date '+%Y-%m-%d_%H:%M:%S'`: Entering main loop..." >> $LOG
while true; do
NOW=$(date +%s)
let SLEEP_SECONDS=60*SLEEP_MINUTES
let WAKEUP_TIME=$NOW+SLEEP_SECONDS
echo `date '+%Y-%m-%d_%H:%M:%S'`: Wake-up time set for `date -d @${WAKEUP_TIME}` >> $LOG
### Dim Backlight
echo -n 0 > $BACKLIGHT
### Disable CPU Powersave
echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo 0 > $FBROTATE
lipc-set-prop com.lab126.cmd wirelessEnable 1
### Wait for wifi interface to come up
echo `date '+%Y-%m-%d_%H:%M:%S'`: Waiting for wifi interface to come up... >> $LOG
while wait_wlan_ready; do
sleep 1
done
### Wifi interface is up, connect to access point.
./wifi.sh
### Wait for WIFI connection
TRYCNT=0
NOWIFI=0
echo `date '+%Y-%m-%d_%H:%M:%S'`: Waiting for wifi interface to become ready... >> $LOG
while wait_wlan_connected; do
if [ ${TRYCNT} -gt 30 ]; then
### waited long enough
echo "`date '+%Y-%m-%d_%H:%M:%S'`: No Wifi... ($TRYCNT)" >> $LOG
NOWIFI=1
$FBINK -x 5 "No Wifi..."
break
fi
sleep 1
let TRYCNT=$TRYCNT+1
done
echo `date '+%Y-%m-%d_%H:%M:%S'`: WIFI connected! >> $LOG
BAT=$(gasgauge-info -c)
$FBINK -x 20 "Getting new image..."
./get_gphoto.py
fbink -q -c -f -i photo.jpg -g w=-1,h=-1,dither=PASSTHROUGH
fbink -q $BAT
echo `date '+%Y-%m-%d_%H:%M:%S'`: Battery level: $BAT >> $LOG
### Enable powersave
echo powersave > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
### flight mode on...
lipc-set-prop com.lab126.cmd wirelessEnable 0
sleep 2
### set wake up time to one hour
echo `date '+%Y-%m-%d_%H:%M:%S'`: Sleeping now... >> $LOG
rtcwake -d /dev/rtc0 -m mem -s $SLEEP_SECONDS
### Go into Suspend to Memory (STR)
done