2 * GraphLCD tool showpic
4 * showpic.c - a tool to show image files in GLCD format on a LCD
6 * based on graphlcd plugin 0.1.1 for the Video Disc Recorder
7 * (c) 2001-2004 Carsten Siebholz <c.siebholz AT t-online.de>
9 * This file is released under the GNU General Public License. Refer
10 * to the COPYING file distributed with this package.
12 * (c) 2004 Andreas Regel <andreas.regel AT powarman.de>
26 #include <glcdgraphics/bitmap.h>
27 #include <glcdgraphics/glcd.h>
28 #include <glcdgraphics/image.h>
29 #include <glcddrivers/config.h>
30 #include <glcddrivers/driver.h>
31 #include <glcddrivers/drivers.h>
33 static const char *prgname = "showpic";
34 static const char *version = "0.1.2";
36 static const int kDefaultSleepMs = 100;
37 static const char * kDefaultConfigFile = "/etc/graphlcd.conf";
39 static volatile bool stopProgramm = false;
41 static void sighandler(int signal)
54 fprintf(stdout, "\n");
55 fprintf(stdout, "%s v%s\n", prgname, version);
56 fprintf(stdout, "%s is a tool to show an image on a LCD.\n", prgname);
57 fprintf(stdout, "The image must be in a special format (*.glcd).\n");
58 fprintf(stdout, "You can create such images with the convpic tool.\n\n");
59 fprintf(stdout, " Usage: %s [-c CONFIGFILE] [-d DISPLAY] [-s SLEEP] [-uie] file [more files]\n\n", prgname);
60 fprintf(stdout, " -c --config specifies the location of the config file\n");
61 fprintf(stdout, " (default: /etc/graphlcd.conf)\n");
62 fprintf(stdout, " -d --display specifies the output display (default is the first one)\n");
63 fprintf(stdout, " -u --upsidedown rotates the output by 180 degrees (default: no)\n");
64 fprintf(stdout, " -i --invert inverts the output (default: no)\n");
65 fprintf(stdout, " -e --endless show all images in endless loop (default: no)\n");
66 fprintf(stdout, " -s --sleep set sleeptime between two images [ms] (default: %d ms)\n", kDefaultSleepMs);
67 fprintf(stdout, " -b --brightness set brightness for display if driver support it [%%]\n");
68 fprintf(stdout, " (default: config file value)\n");
69 fprintf(stdout, "\n" );
70 fprintf(stdout, " examples: %s -c /etc/graphlcd.conf vdr-logo.glcd\n", prgname);
71 fprintf(stdout, " %s -c /etc/graphlcd.conf -d LCD_T6963 -u -i vdr-logo.glcd\n", prgname);
72 fprintf(stdout, "\n" );
75 int main(int argc, char *argv[])
77 static struct option long_options[] =
79 {"config", required_argument, NULL, 'c'},
80 {"display", required_argument, NULL, 'd'},
81 {"sleep", required_argument, NULL, 's'},
82 {"endless", no_argument, NULL, 'e'},
83 {"upsidedown", no_argument, NULL, 'u'},
84 {"invert", no_argument, NULL, 'i'},
85 {"brightness", required_argument, NULL, 'b'},
89 std::string configName = "";
90 std::string displayName = "";
91 bool upsideDown = false;
97 unsigned int displayNumber = 0;
99 int c, option_index = 0;
100 while ((c = getopt_long(argc, argv, "c:d:s:euib:", long_options, &option_index)) != -1)
109 displayName = optarg;
121 sleepMs = atoi(optarg);
130 brightness = atoi(optarg);
131 if (brightness < 0) brightness = 0;
132 if (brightness > 100) brightness = 100;
141 if (configName.length() == 0)
143 configName = kDefaultConfigFile;
144 syslog(LOG_INFO, "Error: No config file specified, using default (%s).\n", configName.c_str());
147 if (GLCD::Config.Load(configName) == false)
149 fprintf(stdout, "Error loading config file!\n");
152 if (GLCD::Config.driverConfigs.size() > 0)
154 if (displayName.length() > 0)
156 for (displayNumber = 0; displayNumber < GLCD::Config.driverConfigs.size(); displayNumber++)
158 if (GLCD::Config.driverConfigs[displayNumber].name == displayName)
161 if (displayNumber == GLCD::Config.driverConfigs.size())
163 fprintf(stdout, "ERROR: Specified display %s not found in config file!\n", displayName.c_str());
169 fprintf(stdout, "WARNING: No display specified, using first one.\n");
175 fprintf(stdout, "ERROR: No displays specified in config file!\n");
182 fprintf(stderr, "ERROR: You have to specify the image\n");
186 GLCD::Config.driverConfigs[displayNumber].upsideDown ^= upsideDown;
187 GLCD::Config.driverConfigs[displayNumber].invert ^= invert;
188 if (brightness != -1)
189 GLCD::Config.driverConfigs[displayNumber].brightness = brightness;
190 GLCD::cDriver * lcd = GLCD::CreateDriver(GLCD::Config.driverConfigs[displayNumber].id, &GLCD::Config.driverConfigs[displayNumber]);
193 fprintf(stderr, "ERROR: Failed creating display object %s\n", displayName.c_str());
196 if (lcd->Init() != 0)
198 fprintf(stderr, "ERROR: Failed initializing display %s\n", displayName.c_str());
202 lcd->SetBrightness(GLCD::Config.driverConfigs[displayNumber].brightness);
203 printf("keys = %d\n",lcd->GetKey());
205 signal(SIGINT, sighandler);
206 signal(SIGQUIT, sighandler);
207 signal(SIGTERM, sighandler);
208 signal(SIGHUP, sighandler);
210 const GLCD::cBitmap * bitmap;
212 GLCD::cGLCDFile glcd;
217 while (optFile < argc && !stopProgramm)
219 picFile = argv[optFile++];
220 if (glcd.Load(image, picFile) == false)
222 fprintf(stderr, "ERROR: Failed loading file %s\n", picFile.c_str());
227 image.SetDelay(sleepMs);
229 while ((bitmap = image.GetBitmap()) != NULL && !stopProgramm)
231 lcd->SetScreen(bitmap->Data(), bitmap->Width(), bitmap->Height(), bitmap->LineSize());
232 printf("keys = %d\n",lcd->GetKey());
235 if (image.Next(0)) // Select next image
237 usleep(image.Delay() * 1000);
239 else if (endless && argc == (optind + 1)) // Endless and one and only image
242 usleep(image.Delay() * 1000);
248 if (optFile < argc || endless)
249 usleep(sleepMs * 1000);
250 if (optFile >= argc && endless)