~popey/+junk/phablet-flash-wrapper

« back to all changes in this revision

Viewing changes to mirfbdump

  • Committer: Alan Pope
  • Date: 2013-10-17 10:04:29 UTC
  • Revision ID: alan.pope@canonical.com-20131017100429-jarrnpopci7igl14
add mirfbdump and other stuff

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
#
 
4
# Screen capture of Mir devices
 
5
#
 
6
 
 
7
# Copyright (C) 2013 Canonical
 
8
#
 
9
# Authors: Jean-Baptiste Lallement <jean-baptiste.lallement@canonical.com>
 
10
#
 
11
# This program is free software; you can redistribute it and/or modify it #
 
12
# under the terms of the GNU General Public License as published by the Free #
 
13
# Software Foundation; version 3.
 
14
#
 
15
# This program is distributed in the hope that it will be useful, but WITHOUT
 
16
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
 
17
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
18
# # details.
 
19
#
 
20
# You should have received a copy of the GNU General Public License along with
 
21
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
 
22
# Street, Fifth Floor, Boston, MA 02110-1301 USA
 
23
 
 
24
# TODO:
 
25
#   - detect that it is running Mir and fallback to screencap if it is SF
 
26
 
 
27
set -eu
 
28
 
 
29
PICDIR=$(mktemp -d /tmp/$(basename $0).XXXXXX)
 
30
FBDEV=fb0
 
31
ADBOPTS=""
 
32
#CONVERTOPTS="-alpha off -resize 50%"
 
33
CONVERTOPTS="-alpha off"
 
34
SUPPORTED="maguro mako manta grouper"
 
35
FILENAME=$HOME"/Pictures/device-`date +%Y-%m-%d-%H%M%S`.png"
 
36
SVR="popey.com"
 
37
SVRPATH="~/public_html/phablet"
 
38
PROTO="http://"
 
39
PUBPATH="~alan/phablet"
 
40
WEBADDR=$PROTO$SVR/$PUBPATH/`basename $FILENAME`
 
41
 
 
42
cleanup() {
 
43
    #
 
44
    # Cleanup temporary files
 
45
    #
 
46
    [ -d "$PICDIR" ] && rm -Rf "$PICDIR"
 
47
}
 
48
trap cleanup EXIT INT QUIT ABRT PIPE TERM
 
49
 
 
50
usage() {
 
51
    #
 
52
    # Print usage and exit
 
53
    #
 
54
    cat <<EOF
 
55
Usage: $(basename $0) [OPTIONS...] 
 
56
Dump /dev/$FBDEV from a touch device and write it to file
 
57
 
 
58
Options
 
59
    -d          Enable debug
 
60
    -h          This help
 
61
    -s SERIAL   Serial number of the device
 
62
 
 
63
EOF
 
64
    exit 1
 
65
}
 
66
 
 
67
check_prerequisites() {
 
68
    # Check list of required packages
 
69
    cmds="adb convert"
 
70
    okay=1
 
71
    for cmd in $cmds; do
 
72
        if ! type $cmd >/dev/null 2>&1; then
 
73
            okay=0
 
74
            pkg="$(dpkg -S usr/bin/$cmd|cut -d: -f1)"
 
75
            echo "E: Command '$cmd' not found in path. Please install package '$pkg'."
 
76
        fi
 
77
    done
 
78
 
 
79
    if [ $okay -ne 1 ]; then
 
80
        echo "E: pre-requisites are not met. Exiting!"
 
81
        exit 1
 
82
    fi
 
83
}
 
84
 
 
85
get_device() {
 
86
    # Get device name
 
87
    device=$(adb $ADBOPTS shell getprop ro.cm.device)
 
88
    echo "$device"|tr -d '\r'
 
89
}
 
90
 
 
91
get_mode() {
 
92
    # Find graphics mode
 
93
    size=$(adb $ADBOPTS shell head -1 /sys/devices/virtual/graphics/$FBDEV/modes| cut -d: -f2|cut -d 'p' -f1)
 
94
 
 
95
    # Fallback to hardcoded values
 
96
    #if ! echo "$size"|grep -qE '^\[0-9\]+x\[0-9\]+$' >/dev/null 2>&1; then
 
97
    if ! echo "$size"|grep -qE '^[0-9]+x[0-9]+$' >/dev/null 2>&1; then
 
98
        device="$(get_device)"
 
99
        case "$device" in
 
100
            maguro)
 
101
                size=720x1280
 
102
                ;;
 
103
            mako)
 
104
                size=768x1280
 
105
                ;;
 
106
            manta)
 
107
                size=1600x2560
 
108
                ;;
 
109
            grouper)
 
110
                size=800x1280
 
111
                ;;
 
112
            *)
 
113
                size=""
 
114
                echo "E: Device '$device' is not supported. Supported devives are: $SUPPORTED"
 
115
                ;;
 
116
        esac
 
117
    fi
 
118
    echo $size
 
119
}
 
120
 
 
121
SHORTOPTS="hds:"
 
122
LONGOPTS="help,debug,serial:"
 
123
 
 
124
TEMP=$(getopt -o $SHORTOPTS --long $LONGOPTS -- "$@")
 
125
eval set -- "$TEMP"
 
126
 
 
127
while true ; do
 
128
    case "$1" in
 
129
        -h|--help)
 
130
            usage;;
 
131
        -d|--debug)
 
132
            set -x
 
133
            shift;;
 
134
        -s|--serial)
 
135
            ADBOPTS="$ADBOPTS -s $2"
 
136
            shift 2;; 
 
137
        --) shift;
 
138
            break;;
 
139
        *) usage;;
 
140
    esac
 
141
done
 
142
 
 
143
DST=$FILENAME
 
144
 
 
145
check_prerequisites
 
146
 
 
147
# Set resolution and depth for device
 
148
depth=8
 
149
size="$(get_mode)"
 
150
if [ -z "$size" ]; then
 
151
    device="$(get_device)"
 
152
    echo "E: Device '$device' is not supported. Supported devives are: $SUPPORTED"
 
153
    exit 1
 
154
fi
 
155
CONVERTOPTS="$CONVERTOPTS -depth $depth -size $size"
 
156
 
 
157
echo "I: Dumping $FBDEV ..."
 
158
adb $ADBOPTS shell "kill -SIGSTOP \$(pidof unity8)"
 
159
adb $ADBOPTS pull /dev/$FBDEV ${PICDIR}/fb
 
160
adb $ADBOPTS shell "kill -SIGCONT \$(pidof unity8)"
 
161
 
 
162
convert $CONVERTOPTS rgba:${PICDIR}/fb[0] $DST
 
163
echo $DST
 
164
xdg-open $DST 2>&1 > /dev/null & 
 
165
scp $DST $SVR:$SVRPATH
 
166
echo $WEBADDR
 
167
#xdg-open $WEBADDR
 
168
echo "I: Done"