summaryrefslogtreecommitdiff
path: root/slideshow
diff options
context:
space:
mode:
authorSami Tolvanen <samitolvanen@google.com>2015-02-19 10:44:12 +0000
committerSami Tolvanen <samitolvanen@google.com>2015-02-27 15:35:46 +0000
commita0f13e0a10ecf306fa88b5fbe68dddf81bf8cd8b (patch)
tree8ddfbee08e854a9a3d91478f5459903bf9ceabaa /slideshow
parent3d5ff951a033ffa7b679fac3e3a5a6c03fcbe15a (diff)
downloadextras-a0f13e0a10ecf306fa88b5fbe68dddf81bf8cd8b.tar.gz
Add a program to display a slideshow at early boot
Add a small program to display a slideshow of images (specified on the command line) on the framebuffer device. Images are switched after a timeout, or user input. The timeout can be optionally set using the -t command line parameter and defaults to 5s. If user input occurred, the program will wait for the power button to be pressed after the last image before exiting. To avoid draining the battery after an accidental reboot, the program exists after 30s even if the power button is not pressed. Change-Id: I58c79a7f3ac747eec0d73a10f018d3d8ade9df7d (Moved from I743c68b5f38038abcaaf5ae08233fa72fd823c8e)
Diffstat (limited to 'slideshow')
-rw-r--r--slideshow/Android.mk16
-rw-r--r--slideshow/slideshow.cpp154
2 files changed, 170 insertions, 0 deletions
diff --git a/slideshow/Android.mk b/slideshow/Android.mk
new file mode 100644
index 00000000..8c782c30
--- /dev/null
+++ b/slideshow/Android.mk
@@ -0,0 +1,16 @@
+# Copyright 2015 The Android Open Source Project
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := slideshow.cpp
+LOCAL_MODULE := slideshow
+LOCAL_MODULE_TAGS := optional
+LOCAL_FORCE_STATIC_EXECUTABLE := true
+LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT_SBIN)
+LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_SBIN_UNSTRIPPED)
+
+LOCAL_CFLAGS := -D__STDC_LIMIT_MACROS -Werror
+LOCAL_C_INCLUDES := bootable/recovery
+LOCAL_STATIC_LIBRARIES := libminui libpng libz libutils libstdc++ libcutils liblog libm libc
+include $(BUILD_EXECUTABLE)
diff --git a/slideshow/slideshow.cpp b/slideshow/slideshow.cpp
new file mode 100644
index 00000000..25a22062
--- /dev/null
+++ b/slideshow/slideshow.cpp
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <time.h>
+#include <linux/input.h>
+#include <cutils/klog.h>
+#include "minui/minui.h"
+
+#define NEXT_TIMEOUT_MS 5000
+#define LAST_TIMEOUT_S 30
+
+#define LOGE(x...) do { KLOG_ERROR("slideshow", x); } while (0)
+
+static int input_cb(int fd, unsigned int epevents, void *data)
+{
+ struct input_event ev;
+ int *key_code = (int *)data;
+
+ *key_code = -1;
+
+ if (ev_get_input(fd, epevents, &ev)) {
+ return -1;
+ }
+
+ if (ev.type == EV_KEY) {
+ *key_code = ev.code;
+ }
+
+ return 0;
+}
+
+static void clear()
+{
+ gr_color(0, 0, 0, 0);
+ gr_clear();
+ gr_flip();
+}
+
+static void draw(const char *resname)
+{
+ gr_surface surface;
+ int w, h, x, y;
+
+ if (res_create_display_surface(resname, &surface) < 0) {
+ LOGE("failed to create surface for %s\n", resname);
+ return;
+ }
+
+ w = gr_get_width(surface);
+ h = gr_get_height(surface);
+ x = (gr_fb_width() - w) / 2;
+ y = (gr_fb_height() - h) / 2;
+
+ gr_blit(surface, 0, 0, w, h, x, y);
+ gr_flip();
+
+ res_free_surface(surface);
+}
+
+int usage()
+{
+ LOGE("usage: slideshow [-t timeout] image.png [image2.png ...] last.png\n");
+ return EXIT_FAILURE;
+}
+
+int main(int argc, char **argv)
+{
+ int key_code = -1;
+ int input = false;
+ int opt;
+ long int timeout = NEXT_TIMEOUT_MS;
+ time_t start;
+
+ while ((opt = getopt(argc, argv, "t")) != -1) {
+ switch (opt) {
+ case 't':
+ timeout = strtol(optarg, NULL, 0);
+
+ if (timeout < 0 || timeout >= LONG_MAX) {
+ timeout = NEXT_TIMEOUT_MS;
+ LOGE("invalid timeout %s, defaulting to %u\n", optarg,
+ timeout);
+ }
+ break;
+ default:
+ return usage();
+ }
+ }
+
+ if (optind >= argc) {
+ return usage();
+ }
+
+ if (gr_init() == -1 || ev_init(input_cb, &key_code) == -1) {
+ LOGE("failed to initialize minui\n");
+ return EXIT_FAILURE;
+ }
+
+ /* display all images except the last one, switch to next image after
+ * timeout or user input */
+
+ while (optind < argc - 1) {
+ draw(argv[optind++]);
+
+ if (ev_wait(timeout) == 0) {
+ ev_dispatch();
+
+ if (key_code != -1) {
+ input = true;
+ }
+ }
+ };
+
+ /* if there was user input while showing the images, display the last
+ * image and wait until the power button is pressed or LAST_TIMEOUT_S
+ * has elapsed */
+
+ if (input) {
+ start = time(NULL);
+ draw(argv[optind]);
+
+ do {
+ if (ev_wait(timeout) == 0) {
+ ev_dispatch();
+ }
+
+ if (time(NULL) - start >= LAST_TIMEOUT_S) {
+ break;
+ }
+ } while (key_code != KEY_POWER);
+ }
+
+ clear();
+ gr_exit();
+ ev_exit();
+
+ return EXIT_SUCCESS;
+}