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 ubb_close(0); 79 return 1; 80 } 81 82 /* Assume a blank screen by default. */ 83 84 current_image = (uint8_t*) &blank_image[0][0]; 85 86 for (arg = 1; arg < argc; arg ++) 87 { 88 /* Wait for a specified delay. */ 89 90 if (strcmp(argv[arg], "--wait") == 0) 91 { 92 arg++; 93 94 if (!isdigit(argv[arg][0])) 95 { 96 printf("Expected an delay in seconds instead of %s.\n", argv[arg]); 97 ubb_close(0); 98 return 1; 99 } 100 101 delay = atoi(argv[arg]); 102 printf("Waiting for %d seconds...\n", delay); 103 sleep(delay); 104 continue; 105 } 106 107 /* Indicate an image presumably on screen already. */ 108 109 have_image = strcmp(argv[arg], "--have") == 0; 110 blank_screen = strcmp(argv[arg], "--blank") == 0; 111 112 if (have_image) 113 arg++; 114 115 /* If a blank screen operation is not requested, find the image 116 specified. */ 117 118 if (!blank_screen) 119 { 120 if (!isdigit(argv[arg][0])) 121 { 122 printf("Expected an image number instead of %s.\n", argv[arg]); 123 ubb_close(0); 124 return 1; 125 } 126 127 image_number = atoi(argv[arg]); 128 129 if (image_number > MAX_IMAGE) 130 { 131 printf("Image number cannot be greater than %d.\n", MAX_IMAGE); 132 ubb_close(0); 133 return 1; 134 } 135 136 /* If just specifying the current image, start the next iteration 137 expecting an image to replace the current image. */ 138 139 if (have_image) 140 { 141 current_image = (uint8_t *) &image_data[image_number][0][0]; 142 printf("Set current image as %d.\n", image_number); 143 continue; 144 } 145 146 /* Otherwise, choose the replacement image. */ 147 148 else 149 { 150 next_image = (uint8_t *) &image_data[image_number][0][0]; 151 printf("Set next image as %d.\n", image_number); 152 } 153 } 154 155 /* To blank the screen choose the blank image as the next image. */ 156 157 else 158 { 159 next_image = (uint8_t*) &blank_image[0][0]; 160 printf("Set blank image.\n"); 161 } 162 163 /* Call epd_DisplayImg with the new image and current image. */ 164 165 epd_DisplayImg(DISPLAY_IN_USE, next_image, current_image); 166 printf("Updated image.\n"); 167 168 current_image = next_image; 169 } 170 171 /* Detach from the board. */ 172 173 printf("Closing...\n"); 174 ubb_close(0); 175 176 return 0; 177 }