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