1.1 --- a/test.c Mon May 27 22:10:53 2013 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,177 +0,0 @@
1.4 -/*
1.5 - * Ben NanoNote and EM027AS012 E-Paper Display Adapter Board communication.
1.6 - *
1.7 - * Copyright (C) 2013 Paul Boddie
1.8 - *
1.9 - * This program is free software; you can redistribute it and/or modify it under
1.10 - * the terms of the GNU General Public License as published by the Free Software
1.11 - * Foundation; either version 3 of the License, or (at your option) any later
1.12 - * version.
1.13 - *
1.14 - * This program is distributed in the hope that it will be useful, but WITHOUT
1.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.16 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.17 - * details.
1.18 - *
1.19 - * You should have received a copy of the GNU General Public License along with
1.20 - * this program. If not, see <http://www.gnu.org/licenses/>.
1.21 - */
1.22 -
1.23 -#include <ubb/ubb.h>
1.24 -#include <stdio.h>
1.25 -#include <stdlib.h>
1.26 -#include <string.h>
1.27 -#include <ctype.h>
1.28 -#include <signal.h>
1.29 -#include <unistd.h>
1.30 -#include "images.h"
1.31 -#include "Display_Controller.h"
1.32 -#include "bsp.h"
1.33 -
1.34 -typedef enum {
1.35 - FALSE=0,
1.36 - TRUE=1
1.37 -} bool;
1.38 -
1.39 -/**
1.40 - * Handle termination of the process.
1.41 - */
1.42 -void shutdown(int signum)
1.43 -{
1.44 - printf("Closing...\n");
1.45 - ubb_close(0);
1.46 - exit(1);
1.47 -}
1.48 -
1.49 -/* Main program and basic initialisation. */
1.50 -
1.51 -int main(int argc, char *argv[])
1.52 -{
1.53 - uint8_t *current_image, *next_image, blank_image[176][33], image_number, arg;
1.54 - bool blank_screen, have_image;
1.55 - int delay;
1.56 -
1.57 - signal(SIGINT, &shutdown);
1.58 -
1.59 - if (ubb_open(0) < 0) {
1.60 - perror("ubb_open");
1.61 - return 1;
1.62 - }
1.63 -
1.64 - ubb_power(1);
1.65 - printf("Power on.\n");
1.66 -
1.67 - /* Need to initialise the board. */
1.68 -
1.69 - bsp_init();
1.70 - printf("Initialised.\n");
1.71 -
1.72 - /* Initialise an array containing the blank image. */
1.73 -
1.74 - memset((uint8_t*) &blank_image[0][0], 0xff, 176*33);
1.75 -
1.76 - /* Determine whether to blank the screen or leave an image on it. */
1.77 -
1.78 - if (argc < 2)
1.79 - {
1.80 - printf("Usage: %s ( --have <image number> | --blank | <image number> | --wait <delay in seconds>)...\n", argv[0]);
1.81 - ubb_close(0);
1.82 - return 1;
1.83 - }
1.84 -
1.85 - /* Assume a blank screen by default. */
1.86 -
1.87 - current_image = (uint8_t*) &blank_image[0][0];
1.88 -
1.89 - for (arg = 1; arg < argc; arg ++)
1.90 - {
1.91 - /* Wait for a specified delay. */
1.92 -
1.93 - if (strcmp(argv[arg], "--wait") == 0)
1.94 - {
1.95 - arg++;
1.96 -
1.97 - if (!isdigit(argv[arg][0]))
1.98 - {
1.99 - printf("Expected an delay in seconds instead of %s.\n", argv[arg]);
1.100 - ubb_close(0);
1.101 - return 1;
1.102 - }
1.103 -
1.104 - delay = atoi(argv[arg]);
1.105 - printf("Waiting for %d seconds...\n", delay);
1.106 - sleep(delay);
1.107 - continue;
1.108 - }
1.109 -
1.110 - /* Indicate an image presumably on screen already. */
1.111 -
1.112 - have_image = strcmp(argv[arg], "--have") == 0;
1.113 - blank_screen = strcmp(argv[arg], "--blank") == 0;
1.114 -
1.115 - if (have_image)
1.116 - arg++;
1.117 -
1.118 - /* If a blank screen operation is not requested, find the image
1.119 - specified. */
1.120 -
1.121 - if (!blank_screen)
1.122 - {
1.123 - if (!isdigit(argv[arg][0]))
1.124 - {
1.125 - printf("Expected an image number instead of %s.\n", argv[arg]);
1.126 - ubb_close(0);
1.127 - return 1;
1.128 - }
1.129 -
1.130 - image_number = atoi(argv[arg]);
1.131 -
1.132 - if (image_number > MAX_IMAGE)
1.133 - {
1.134 - printf("Image number cannot be greater than %d.\n", MAX_IMAGE);
1.135 - ubb_close(0);
1.136 - return 1;
1.137 - }
1.138 -
1.139 - /* If just specifying the current image, start the next iteration
1.140 - expecting an image to replace the current image. */
1.141 -
1.142 - if (have_image)
1.143 - {
1.144 - current_image = (uint8_t *) &image_data[image_number][0][0];
1.145 - printf("Set current image as %d.\n", image_number);
1.146 - continue;
1.147 - }
1.148 -
1.149 - /* Otherwise, choose the replacement image. */
1.150 -
1.151 - else
1.152 - {
1.153 - next_image = (uint8_t *) &image_data[image_number][0][0];
1.154 - printf("Set next image as %d.\n", image_number);
1.155 - }
1.156 - }
1.157 -
1.158 - /* To blank the screen choose the blank image as the next image. */
1.159 -
1.160 - else
1.161 - {
1.162 - next_image = (uint8_t*) &blank_image[0][0];
1.163 - printf("Set blank image.\n");
1.164 - }
1.165 -
1.166 - /* Call epd_DisplayImg with the new image and current image. */
1.167 -
1.168 - epd_DisplayImg(DISPLAY_IN_USE, next_image, current_image);
1.169 - printf("Updated image.\n");
1.170 -
1.171 - current_image = next_image;
1.172 - }
1.173 -
1.174 - /* Detach from the board. */
1.175 -
1.176 - printf("Closing...\n");
1.177 - ubb_close(0);
1.178 -
1.179 - return 0;
1.180 -}