1.1 --- a/test.c Sat May 25 23:01:04 2013 +0000
1.2 +++ b/test.c Mon May 27 14:42:12 2013 +0000
1.3 @@ -21,11 +21,17 @@
1.4 #include <stdio.h>
1.5 #include <stdlib.h>
1.6 #include <string.h>
1.7 +#include <ctype.h>
1.8 #include <signal.h>
1.9 #include "images.h"
1.10 #include "Display_Controller.h"
1.11 #include "bsp.h"
1.12
1.13 +typedef enum {
1.14 + FALSE=0,
1.15 + TRUE=1
1.16 +} bool;
1.17 +
1.18 /**
1.19 * Handle termination of the process.
1.20 */
1.21 @@ -40,7 +46,8 @@
1.22
1.23 int main(int argc, char *argv[])
1.24 {
1.25 - uint8_t *current_image, blank_image[176][33];
1.26 + uint8_t *current_image, *next_image, blank_image[176][33], image_number, image_number_arg;
1.27 + bool blank_screen;
1.28
1.29 signal(SIGINT, &shutdown);
1.30
1.31 @@ -57,26 +64,55 @@
1.32 bsp_init();
1.33 printf("Initialised.\n");
1.34
1.35 - /* Initialise an array containing the current image. */
1.36 + /* Initialise an array containing the blank image. */
1.37
1.38 memset((uint8_t*) &blank_image[0][0], 0xff, 176*33);
1.39 - current_image = (uint8_t*) &blank_image[0][0];
1.40 - printf("Set blank image.\n");
1.41 +
1.42 + /* Determine whether to blank the screen or leave an image on it. */
1.43 +
1.44 + blank_screen = (argc > 2) && (strcmp(argv[1], "--blank") == 0);
1.45 + image_number_arg = blank_screen ? 2 : 1;
1.46 +
1.47 + if ((argc < 2) || (!isdigit(argv[image_number_arg][0])))
1.48 + {
1.49 + printf("Usage: %s [ --blank ] <image number>\n", argv[0]);
1.50 + ubb_close(0);
1.51 + return 1;
1.52 + }
1.53 + else
1.54 + {
1.55 + image_number = atoi(argv[image_number_arg]);
1.56 +
1.57 + if (image_number > MAX_IMAGE)
1.58 + {
1.59 + printf("Image number cannot be greater than %d.\n", MAX_IMAGE);
1.60 + ubb_close(0);
1.61 + return 1;
1.62 + }
1.63 +
1.64 + /* When blanking, indicate an image presumably on screen already. */
1.65 +
1.66 + if (blank_screen)
1.67 + {
1.68 + next_image = (uint8_t*) &blank_image[0][0];
1.69 + current_image = (uint8_t *) &image_data[image_number][0][0];
1.70 + printf("Set blank image.\n");
1.71 + }
1.72 +
1.73 + /* When leaving an image on screen, indicate that the screen starts off
1.74 + being blank. */
1.75 +
1.76 + else
1.77 + {
1.78 + next_image = (uint8_t *) &image_data[image_number][0][0];
1.79 + current_image = (uint8_t*) &blank_image[0][0];
1.80 + printf("Set first image.\n");
1.81 + }
1.82 + }
1.83
1.84 /* Call epd_DisplayImg with the new image and current image. */
1.85
1.86 - epd_DisplayImg(DISPLAY_IN_USE, (uint8_t *) &image_data[0][0][0], current_image);
1.87 - printf("Updated image. Press Enter...\n");
1.88 -
1.89 - fgetc(stdin);
1.90 -
1.91 - /* Set the current image to the new image. */
1.92 -
1.93 - current_image = &image_data[0][0][0];
1.94 -
1.95 - /* Call epd_DisplayImg with the new image and current image. */
1.96 -
1.97 - epd_DisplayImg(DISPLAY_IN_USE, (uint8_t *) &image_data[1][0][0], current_image);
1.98 + epd_DisplayImg(DISPLAY_IN_USE, next_image, current_image);
1.99 printf("Updated image.\n");
1.100
1.101 /* Detach from the board. */