1 /* picoproj - test program for libam7xxx
3 * Copyright (C) 2012 Antonio Ospite <ospite@studenti.unina.it>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include <sys/types.h>
30 static void usage(char *name)
32 printf("usage: %s [OPTIONS]\n\n", name);
34 printf("\t-f <filename>\t\tthe image file to upload\n");
35 printf("\t-F <format>\t\tthe image format to use (default is JPEG).\n");
36 printf("\t\t\t\tSUPPORTED FORMATS:\n");
37 printf("\t\t\t\t\t1 - JPEG\n");
38 printf("\t-W <image width>\tthe width of the image to upload\n");
39 printf("\t-H <image height>\tthe height of the image to upload\n");
40 printf("\t-h \t\t\tthis help message\n");
43 int main(int argc, char *argv[])
46 int exit_code = EXIT_SUCCESS;
49 char filename[FILENAME_MAX] = {0};
52 int format = AM7XXX_IMAGE_FORMAT_JPEG;
55 uint8_t *image = NULL;
56 unsigned int size = 59475;
58 while ((opt = getopt(argc, argv, "f:F:W:H:h")) != -1) {
61 strncpy(filename, optarg, FILENAME_MAX);
64 format = atoi(optarg);
66 fprintf(stderr, "Unsupported format\n");
73 fprintf(stderr, "Unsupported width\n");
78 height = atoi(optarg);
80 fprintf(stderr, "Unsupported height\n");
90 if (filename[0] != '\0') {
93 image_fd = open(filename, O_RDONLY);
96 exit_code = EXIT_FAILURE;
99 if (fstat(image_fd, &st) < 0) {
101 exit_code = EXIT_FAILURE;
102 goto out_close_image_fd;
106 image = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, image_fd, 0);
109 exit_code = EXIT_FAILURE;
110 goto out_close_image_fd;
116 perror("am7xxx_init");
117 exit_code = EXIT_FAILURE;
121 ret = am7xxx_send_image(dev, format, width, height, image, size);
123 perror("am7xxx_send_image");
124 exit_code = EXIT_FAILURE;
128 exit_code = EXIT_SUCCESS;
131 am7xxx_shutdown(dev);
135 ret = munmap(image, size);
142 ret = close(image_fd);