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@1 | 24 | #include <signal.h> |
paul@7 | 25 | #include "images.h" |
paul@1 | 26 | #include "Display_Controller.h" |
paul@1 | 27 | #include "bsp.h" |
paul@1 | 28 | |
paul@1 | 29 | /** |
paul@1 | 30 | * Handle termination of the process. |
paul@1 | 31 | */ |
paul@1 | 32 | void shutdown(int signum) |
paul@1 | 33 | { |
paul@1 | 34 | printf("Closing...\n"); |
paul@1 | 35 | ubb_close(0); |
paul@1 | 36 | exit(1); |
paul@1 | 37 | } |
paul@1 | 38 | |
paul@1 | 39 | /* Main program and basic initialisation. */ |
paul@1 | 40 | |
paul@1 | 41 | int main(int argc, char *argv[]) |
paul@1 | 42 | { |
paul@1 | 43 | uint8_t *current_image, blank_image[176][33]; |
paul@1 | 44 | |
paul@1 | 45 | signal(SIGINT, &shutdown); |
paul@1 | 46 | |
paul@1 | 47 | if (ubb_open(0) < 0) { |
paul@1 | 48 | perror("ubb_open"); |
paul@1 | 49 | return 1; |
paul@1 | 50 | } |
paul@1 | 51 | |
paul@1 | 52 | ubb_power(1); |
paul@1 | 53 | printf("Power on.\n"); |
paul@1 | 54 | |
paul@1 | 55 | /* Need to initialise the board. */ |
paul@1 | 56 | |
paul@1 | 57 | bsp_init(); |
paul@1 | 58 | printf("Initialised.\n"); |
paul@1 | 59 | |
paul@1 | 60 | /* Initialise an array containing the current image. */ |
paul@1 | 61 | |
paul@1 | 62 | memset((uint8_t*) &blank_image[0][0], 0xff, 176*33); |
paul@1 | 63 | current_image = (uint8_t*) &blank_image[0][0]; |
paul@1 | 64 | printf("Set blank image.\n"); |
paul@1 | 65 | |
paul@1 | 66 | /* Call epd_DisplayImg with the new image and current image. */ |
paul@1 | 67 | |
paul@1 | 68 | epd_DisplayImg(DISPLAY_IN_USE, (uint8_t *) &image_data[0][0][0], current_image); |
paul@7 | 69 | printf("Updated image. Press Enter...\n"); |
paul@7 | 70 | |
paul@7 | 71 | fgetc(stdin); |
paul@1 | 72 | |
paul@1 | 73 | /* Set the current image to the new image. */ |
paul@1 | 74 | |
paul@1 | 75 | current_image = &image_data[0][0][0]; |
paul@1 | 76 | |
paul@7 | 77 | /* Call epd_DisplayImg with the new image and current image. */ |
paul@7 | 78 | |
paul@7 | 79 | epd_DisplayImg(DISPLAY_IN_USE, (uint8_t *) &image_data[1][0][0], current_image); |
paul@7 | 80 | printf("Updated image.\n"); |
paul@7 | 81 | |
paul@7 | 82 | /* Detach from the board. */ |
paul@7 | 83 | |
paul@1 | 84 | printf("Closing...\n"); |
paul@1 | 85 | ubb_close(0); |
paul@1 | 86 | |
paul@1 | 87 | return 0; |
paul@1 | 88 | } |