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