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 "images.h" 27 #include "Display_Controller.h" 28 #include "bsp.h" 29 30 typedef enum { 31 FALSE=0, 32 TRUE=1 33 } bool; 34 35 /** 36 * Handle termination of the process. 37 */ 38 void shutdown(int signum) 39 { 40 printf("Closing...\n"); 41 ubb_close(0); 42 exit(1); 43 } 44 45 /* Main program and basic initialisation. */ 46 47 int main(int argc, char *argv[]) 48 { 49 uint8_t *current_image, *next_image, blank_image[176][33], image_number, image_number_arg; 50 bool blank_screen; 51 52 signal(SIGINT, &shutdown); 53 54 if (ubb_open(0) < 0) { 55 perror("ubb_open"); 56 return 1; 57 } 58 59 ubb_power(1); 60 printf("Power on.\n"); 61 62 /* Need to initialise the board. */ 63 64 bsp_init(); 65 printf("Initialised.\n"); 66 67 /* Initialise an array containing the blank image. */ 68 69 memset((uint8_t*) &blank_image[0][0], 0xff, 176*33); 70 71 /* Determine whether to blank the screen or leave an image on it. */ 72 73 blank_screen = (argc > 2) && (strcmp(argv[1], "--blank") == 0); 74 image_number_arg = blank_screen ? 2 : 1; 75 76 if ((argc < 2) || (!isdigit(argv[image_number_arg][0]))) 77 { 78 printf("Usage: %s [ --blank ] <image number>\n", argv[0]); 79 ubb_close(0); 80 return 1; 81 } 82 else 83 { 84 image_number = atoi(argv[image_number_arg]); 85 86 if (image_number > MAX_IMAGE) 87 { 88 printf("Image number cannot be greater than %d.\n", MAX_IMAGE); 89 ubb_close(0); 90 return 1; 91 } 92 93 /* When blanking, indicate an image presumably on screen already. */ 94 95 if (blank_screen) 96 { 97 next_image = (uint8_t*) &blank_image[0][0]; 98 current_image = (uint8_t *) &image_data[image_number][0][0]; 99 printf("Set blank image.\n"); 100 } 101 102 /* When leaving an image on screen, indicate that the screen starts off 103 being blank. */ 104 105 else 106 { 107 next_image = (uint8_t *) &image_data[image_number][0][0]; 108 current_image = (uint8_t*) &blank_image[0][0]; 109 printf("Set first image.\n"); 110 } 111 } 112 113 /* Call epd_DisplayImg with the new image and current image. */ 114 115 epd_DisplayImg(DISPLAY_IN_USE, next_image, current_image); 116 printf("Updated image.\n"); 117 118 /* Detach from the board. */ 119 120 printf("Closing...\n"); 121 ubb_close(0); 122 123 return 0; 124 }