# HG changeset patch # User Paul Boddie # Date 1369689327 0 # Node ID 4b490542bb6224fa63ec3b33694303e08cbad007 # Parent f496318bed7884d2f1e17f901ad9a95a13fcad97 Expanded the command options to support simple image slideshows. diff -r f496318bed78 -r 4b490542bb62 test.c --- a/test.c Mon May 27 14:42:12 2013 +0000 +++ b/test.c Mon May 27 21:15:27 2013 +0000 @@ -23,6 +23,7 @@ #include #include #include +#include #include "images.h" #include "Display_Controller.h" #include "bsp.h" @@ -46,8 +47,9 @@ int main(int argc, char *argv[]) { - uint8_t *current_image, *next_image, blank_image[176][33], image_number, image_number_arg; - bool blank_screen; + uint8_t *current_image, *next_image, blank_image[176][33], image_number, arg; + bool blank_screen, have_image; + int delay; signal(SIGINT, &shutdown); @@ -70,51 +72,102 @@ /* Determine whether to blank the screen or leave an image on it. */ - blank_screen = (argc > 2) && (strcmp(argv[1], "--blank") == 0); - image_number_arg = blank_screen ? 2 : 1; - - if ((argc < 2) || (!isdigit(argv[image_number_arg][0]))) + if (argc < 2) { - printf("Usage: %s [ --blank ] \n", argv[0]); + printf("Usage: %s ( --have | --blank | | --wait )...\n", argv[0]); ubb_close(0); return 1; } - else + + /* Assume a blank screen by default. */ + + current_image = (uint8_t*) &blank_image[0][0]; + + for (arg = 1; arg < argc; arg ++) { - image_number = atoi(argv[image_number_arg]); + /* Wait for a specified delay. */ - if (image_number > MAX_IMAGE) + if (strcmp(argv[arg], "--wait") == 0) { - printf("Image number cannot be greater than %d.\n", MAX_IMAGE); - ubb_close(0); - return 1; + arg++; + + if (!isdigit(argv[arg][0])) + { + printf("Expected an delay in seconds instead of %s.\n", argv[arg]); + ubb_close(0); + return 1; + } + + delay = atoi(argv[arg]); + printf("Waiting for %d seconds...\n", delay); + sleep(delay); + continue; } - /* When blanking, indicate an image presumably on screen already. */ + /* Indicate an image presumably on screen already. */ + + have_image = strcmp(argv[arg], "--have") == 0; + blank_screen = strcmp(argv[arg], "--blank") == 0; + + if (have_image) + arg++; + + /* If a blank screen operation is not requested, find the image + specified. */ + + if (!blank_screen) + { + if (!isdigit(argv[arg][0])) + { + printf("Expected an image number instead of %s.\n", argv[arg]); + ubb_close(0); + return 1; + } + + image_number = atoi(argv[arg]); - if (blank_screen) + if (image_number > MAX_IMAGE) + { + printf("Image number cannot be greater than %d.\n", MAX_IMAGE); + ubb_close(0); + return 1; + } + + /* If just specifying the current image, start the next iteration + expecting an image to replace the current image. */ + + if (have_image) + { + current_image = (uint8_t *) &image_data[image_number][0][0]; + printf("Set current image as %d.\n", image_number); + continue; + } + + /* Otherwise, choose the replacement image. */ + + else + { + next_image = (uint8_t *) &image_data[image_number][0][0]; + printf("Set next image as %d.\n", image_number); + } + } + + /* To blank the screen choose the blank image as the next image. */ + + else { next_image = (uint8_t*) &blank_image[0][0]; - current_image = (uint8_t *) &image_data[image_number][0][0]; printf("Set blank image.\n"); } - /* When leaving an image on screen, indicate that the screen starts off - being blank. */ + /* Call epd_DisplayImg with the new image and current image. */ - else - { - next_image = (uint8_t *) &image_data[image_number][0][0]; - current_image = (uint8_t*) &blank_image[0][0]; - printf("Set first image.\n"); - } + epd_DisplayImg(DISPLAY_IN_USE, next_image, current_image); + printf("Updated image.\n"); + + current_image = next_image; } - /* Call epd_DisplayImg with the new image and current image. */ - - epd_DisplayImg(DISPLAY_IN_USE, next_image, current_image); - printf("Updated image.\n"); - /* Detach from the board. */ printf("Closing...\n");