1.1 --- a/test.c Mon May 27 14:42:12 2013 +0000
1.2 +++ b/test.c Mon May 27 21:15:27 2013 +0000
1.3 @@ -23,6 +23,7 @@
1.4 #include <string.h>
1.5 #include <ctype.h>
1.6 #include <signal.h>
1.7 +#include <unistd.h>
1.8 #include "images.h"
1.9 #include "Display_Controller.h"
1.10 #include "bsp.h"
1.11 @@ -46,8 +47,9 @@
1.12
1.13 int main(int argc, char *argv[])
1.14 {
1.15 - uint8_t *current_image, *next_image, blank_image[176][33], image_number, image_number_arg;
1.16 - bool blank_screen;
1.17 + uint8_t *current_image, *next_image, blank_image[176][33], image_number, arg;
1.18 + bool blank_screen, have_image;
1.19 + int delay;
1.20
1.21 signal(SIGINT, &shutdown);
1.22
1.23 @@ -70,51 +72,102 @@
1.24
1.25 /* Determine whether to blank the screen or leave an image on it. */
1.26
1.27 - blank_screen = (argc > 2) && (strcmp(argv[1], "--blank") == 0);
1.28 - image_number_arg = blank_screen ? 2 : 1;
1.29 -
1.30 - if ((argc < 2) || (!isdigit(argv[image_number_arg][0])))
1.31 + if (argc < 2)
1.32 {
1.33 - printf("Usage: %s [ --blank ] <image number>\n", argv[0]);
1.34 + printf("Usage: %s ( --have <image number> | --blank | <image number> | --wait <delay in seconds>)...\n", argv[0]);
1.35 ubb_close(0);
1.36 return 1;
1.37 }
1.38 - else
1.39 +
1.40 + /* Assume a blank screen by default. */
1.41 +
1.42 + current_image = (uint8_t*) &blank_image[0][0];
1.43 +
1.44 + for (arg = 1; arg < argc; arg ++)
1.45 {
1.46 - image_number = atoi(argv[image_number_arg]);
1.47 + /* Wait for a specified delay. */
1.48
1.49 - if (image_number > MAX_IMAGE)
1.50 + if (strcmp(argv[arg], "--wait") == 0)
1.51 {
1.52 - printf("Image number cannot be greater than %d.\n", MAX_IMAGE);
1.53 - ubb_close(0);
1.54 - return 1;
1.55 + arg++;
1.56 +
1.57 + if (!isdigit(argv[arg][0]))
1.58 + {
1.59 + printf("Expected an delay in seconds instead of %s.\n", argv[arg]);
1.60 + ubb_close(0);
1.61 + return 1;
1.62 + }
1.63 +
1.64 + delay = atoi(argv[arg]);
1.65 + printf("Waiting for %d seconds...\n", delay);
1.66 + sleep(delay);
1.67 + continue;
1.68 }
1.69
1.70 - /* When blanking, indicate an image presumably on screen already. */
1.71 + /* Indicate an image presumably on screen already. */
1.72 +
1.73 + have_image = strcmp(argv[arg], "--have") == 0;
1.74 + blank_screen = strcmp(argv[arg], "--blank") == 0;
1.75 +
1.76 + if (have_image)
1.77 + arg++;
1.78 +
1.79 + /* If a blank screen operation is not requested, find the image
1.80 + specified. */
1.81 +
1.82 + if (!blank_screen)
1.83 + {
1.84 + if (!isdigit(argv[arg][0]))
1.85 + {
1.86 + printf("Expected an image number instead of %s.\n", argv[arg]);
1.87 + ubb_close(0);
1.88 + return 1;
1.89 + }
1.90 +
1.91 + image_number = atoi(argv[arg]);
1.92
1.93 - if (blank_screen)
1.94 + if (image_number > MAX_IMAGE)
1.95 + {
1.96 + printf("Image number cannot be greater than %d.\n", MAX_IMAGE);
1.97 + ubb_close(0);
1.98 + return 1;
1.99 + }
1.100 +
1.101 + /* If just specifying the current image, start the next iteration
1.102 + expecting an image to replace the current image. */
1.103 +
1.104 + if (have_image)
1.105 + {
1.106 + current_image = (uint8_t *) &image_data[image_number][0][0];
1.107 + printf("Set current image as %d.\n", image_number);
1.108 + continue;
1.109 + }
1.110 +
1.111 + /* Otherwise, choose the replacement image. */
1.112 +
1.113 + else
1.114 + {
1.115 + next_image = (uint8_t *) &image_data[image_number][0][0];
1.116 + printf("Set next image as %d.\n", image_number);
1.117 + }
1.118 + }
1.119 +
1.120 + /* To blank the screen choose the blank image as the next image. */
1.121 +
1.122 + else
1.123 {
1.124 next_image = (uint8_t*) &blank_image[0][0];
1.125 - current_image = (uint8_t *) &image_data[image_number][0][0];
1.126 printf("Set blank image.\n");
1.127 }
1.128
1.129 - /* When leaving an image on screen, indicate that the screen starts off
1.130 - being blank. */
1.131 + /* Call epd_DisplayImg with the new image and current image. */
1.132
1.133 - else
1.134 - {
1.135 - next_image = (uint8_t *) &image_data[image_number][0][0];
1.136 - current_image = (uint8_t*) &blank_image[0][0];
1.137 - printf("Set first image.\n");
1.138 - }
1.139 + epd_DisplayImg(DISPLAY_IN_USE, next_image, current_image);
1.140 + printf("Updated image.\n");
1.141 +
1.142 + current_image = next_image;
1.143 }
1.144
1.145 - /* Call epd_DisplayImg with the new image and current image. */
1.146 -
1.147 - epd_DisplayImg(DISPLAY_IN_USE, next_image, current_image);
1.148 - printf("Updated image.\n");
1.149 -
1.150 /* Detach from the board. */
1.151
1.152 printf("Closing...\n");