1 /* 2 * Ben NanoNote and EM027AS012 E-Paper Display Adapter Board communication. 3 * 4 * Copyright (C) 2013 Paul Boddie 5 * 6 * This program is free software; you can redistribute it and/or modify it under 7 * the terms of the GNU General Public License as published by the Free Software 8 * Foundation; either version 3 of the License, or (at your option) any later 9 * version. 10 * 11 * This program is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 14 * details. 15 * 16 * You should have received a copy of the GNU General Public License along with 17 * this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #include <ubb/ubb.h> 21 #include <stdio.h> 22 #include <stdlib.h> 23 #include <string.h> 24 #include <ctype.h> 25 #include <signal.h> 26 #include <unistd.h> 27 #include "images.h" 28 #include "Display_Controller.h" 29 #include "bsp.h" 30 31 typedef enum { 32 FALSE=0, 33 TRUE=1 34 } bool; 35 36 /** 37 * Handle termination of the process. 38 */ 39 void shutdown(int signum) 40 { 41 printf("Closing...\n"); 42 ubb_close(0); 43 exit(1); 44 } 45 46 /* Main program and basic initialisation. */ 47 48 int main(int argc, char *argv[]) 49 { 50 uint8_t *current_image, *next_image, blank_image[176][33], image_number, arg; 51 bool blank_screen, have_image; 52 int delay; 53 54 signal(SIGINT, &shutdown); 55 56 if (ubb_open(0) < 0) { 57 perror("ubb_open"); 58 return 1; 59 } 60 61 ubb_power(1); 62 printf("Power on.\n"); 63 64 /* Need to initialise the board. */ 65 66 bsp_init(); 67 printf("Initialised.\n"); 68 69 /* Initialise an array containing the blank image. */ 70 71 memset((uint8_t*) &blank_image[0][0], 0xff, 176*33); 72 73 /* Determine whether to blank the screen or leave an image on it. */ 74 75 if (argc < 2) 76 { 77 printf("Usage: %s ( --have <image number> | --blank | <image number> | --wait <delay in seconds>)...\n", argv[0]); 78 printf("The <image number> can be a number from 0 to %d inclusive.\n", MAX_IMAGE); 79 ubb_close(0); 80 return 1; 81 } 82 83 /* Assume a blank screen by default. */ 84 85 current_image = (uint8_t*) &blank_image[0][0]; 86 87 for (arg = 1; arg < argc; arg ++) 88 { 89 /* Wait for a specified delay. */ 90 91 if (strcmp(argv[arg], "--wait") == 0) 92 { 93 arg++; 94 95 if (!isdigit(argv[arg][0])) 96 { 97 printf("Expected an delay in seconds instead of %s.\n", argv[arg]); 98 ubb_close(0); 99 return 1; 100 } 101 102 delay = atoi(argv[arg]); 103 printf("Waiting for %d seconds...\n", delay); 104 sleep(delay); 105 continue; 106 } 107 108 /* Indicate an image presumably on screen already. */ 109 110 have_image = strcmp(argv[arg], "--have") == 0; 111 blank_screen = strcmp(argv[arg], "--blank") == 0; 112 113 if (have_image) 114 arg++; 115 116 /* If a blank screen operation is not requested, find the image 117 specified. */ 118 119 if (!blank_screen) 120 { 121 if (!isdigit(argv[arg][0])) 122 { 123 printf("Expected an image number instead of %s.\n", argv[arg]); 124 ubb_close(0); 125 return 1; 126 } 127 128 image_number = atoi(argv[arg]); 129 130 if (image_number > MAX_IMAGE) 131 { 132 printf("Image number cannot be greater than %d.\n", MAX_IMAGE); 133 ubb_close(0); 134 return 1; 135 } 136 137 /* If just specifying the current image, start the next iteration 138 expecting an image to replace the current image. */ 139 140 if (have_image) 141 { 142 current_image = (uint8_t *) &image_data[image_number][0][0]; 143 printf("Set current image as %d.\n", image_number); 144 continue; 145 } 146 147 /* Otherwise, choose the replacement image. */ 148 149 else 150 { 151 next_image = (uint8_t *) &image_data[image_number][0][0]; 152 printf("Set next image as %d.\n", image_number); 153 } 154 } 155 156 /* To blank the screen choose the blank image as the next image. */ 157 158 else 159 { 160 next_image = (uint8_t*) &blank_image[0][0]; 161 printf("Set blank image.\n"); 162 } 163 164 /* Call epd_DisplayImg with the new image and current image. */ 165 166 epd_DisplayImg(DISPLAY_IN_USE, next_image, current_image); 167 printf("Updated image.\n"); 168 169 current_image = next_image; 170 } 171 172 /* Detach from the board. */ 173 174 printf("Closing...\n"); 175 ubb_close(0); 176 177 return 0; 178 }