1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/graphlcd-base/tools/lcdtestpattern/lcdtestpattern.c Wed Feb 06 17:32:55 2008 +0000
1.3 @@ -0,0 +1,260 @@
1.4 +/*
1.5 + * GraphLCD tool lcdtestpattern
1.6 + *
1.7 + * lcdtestpattern.c - a tool to display some testpattern on an GLCD
1.8 + *
1.9 + * based on showpic.c of graphlcd-base
1.10 + * (c) 2004 Andreas Regel <andreas.regel AT powarman.de>
1.11 + *
1.12 + * This file is released under the GNU General Public License. Refer
1.13 + * to the COPYING file distributed with this package.
1.14 + *
1.15 + * (c) 2007 Alexander Rieger (Alexander.Rieger AT inka.de)
1.16 + */
1.17 +
1.18 +//-----------------------------------------------------------------------------
1.19 +#include <stdio.h>
1.20 +#include <string.h>
1.21 +#include <stdlib.h>
1.22 +#include <getopt.h>
1.23 +#include <dlfcn.h>
1.24 +#include <unistd.h>
1.25 +#include <syslog.h>
1.26 +#include <signal.h>
1.27 +
1.28 +#include <string>
1.29 +
1.30 +#include <glcdgraphics/bitmap.h>
1.31 +#include <glcdgraphics/glcd.h>
1.32 +#include <glcdgraphics/image.h>
1.33 +#include <glcddrivers/config.h>
1.34 +#include <glcddrivers/common.h>
1.35 +#include <glcddrivers/driver.h>
1.36 +#include <glcddrivers/drivers.h>
1.37 +
1.38 +//-----------------------------------------------------------------------------
1.39 +static const char *prgname = "lcdtestpattern";
1.40 +static const char *version = "0.1.0";
1.41 +
1.42 +static const int kDefaultSleepMs = 0;
1.43 +static const char * kDefaultConfigFile = "/etc/graphlcd.conf";
1.44 +
1.45 +static volatile bool stopProgramm = false;
1.46 +
1.47 +//-----------------------------------------------------------------------------
1.48 +static void sighandler(int signal)
1.49 +{
1.50 + switch (signal)
1.51 + {
1.52 + case SIGINT:
1.53 + case SIGQUIT:
1.54 + case SIGTERM:
1.55 + stopProgramm = true;
1.56 + } // switch
1.57 +} // sighandler()
1.58 +
1.59 +//-----------------------------------------------------------------------------
1.60 +void usage()
1.61 +{
1.62 + fprintf(stdout, "\n");
1.63 + fprintf(stdout, "%s v%s\n", prgname, version);
1.64 + fprintf(stdout, "%s is a tool to show test patterns on a LCD.\n", prgname);
1.65 + fprintf(stdout, "\n");
1.66 + fprintf(stdout, " Usage: %s [-c CONFIGFILE] [-d DISPLAY] [-s SLEEP] [-uie]\n\n", prgname);
1.67 + fprintf(stdout, " -c --config specifies the location of the config file\n");
1.68 + fprintf(stdout, " (default: /etc/graphlcd.conf)\n");
1.69 + fprintf(stdout, " -d --display specifies the output display (default is the first one)\n");
1.70 + fprintf(stdout, " -u --upsidedown rotates the output by 180 degrees (default: no)\n");
1.71 + fprintf(stdout, " -i --invert inverts the output (default: no)\n");
1.72 + fprintf(stdout, " -e --endless show all images in endless loop (default: no)\n");
1.73 + fprintf(stdout, " -s --sleep set sleeptime between two patterns [ms] (default: %d ms)\n", kDefaultSleepMs);
1.74 + fprintf(stdout, " -b --brightness set brightness for display if driver support it [%%]\n");
1.75 + fprintf(stdout, " (default: config file value)\n");
1.76 + fprintf(stdout, "\n" );
1.77 + fprintf(stdout, " examples: %s -c /etc/graphlcd.conf\n", prgname);
1.78 + fprintf(stdout, " %s -c /etc/graphlcd.conf -d LCD_T6963 -u -i\n", prgname);
1.79 + fprintf(stdout, "\n" );
1.80 +} // usage()
1.81 +
1.82 +//-----------------------------------------------------------------------------
1.83 +int main(int argc, char *argv[])
1.84 +{
1.85 + static struct option long_options[] =
1.86 + {
1.87 + {"config", required_argument, NULL, 'c'},
1.88 + {"display", required_argument, NULL, 'd'},
1.89 + {"sleep", required_argument, NULL, 's'},
1.90 + {"endless", no_argument, NULL, 'e'},
1.91 + {"upsidedown", no_argument, NULL, 'u'},
1.92 + {"invert", no_argument, NULL, 'i'},
1.93 + {"brightness", required_argument, NULL, 'b'},
1.94 + {NULL}
1.95 + };
1.96 +
1.97 + std::string configName = "";
1.98 + std::string displayName = "";
1.99 + bool upsideDown = false;
1.100 + bool invert = false;
1.101 + int brightness = -1;
1.102 + bool delay = false;
1.103 + int sleepMs = kDefaultSleepMs;
1.104 + bool endless = false;
1.105 + unsigned int displayNumber = 0;
1.106 +
1.107 + int c, option_index = 0;
1.108 + while ((c = getopt_long(argc, argv, "c:d:s:euib:", long_options, &option_index)) != -1)
1.109 + {
1.110 + switch(c)
1.111 + {
1.112 + case 'c':
1.113 + configName = optarg;
1.114 + break;
1.115 +
1.116 + case 'd':
1.117 + displayName = optarg;
1.118 + break;
1.119 +
1.120 + case 'u':
1.121 + upsideDown = true;
1.122 + break;
1.123 +
1.124 + case 'i':
1.125 + invert = true;
1.126 + break;
1.127 +
1.128 + case 's':
1.129 + sleepMs = atoi(optarg);
1.130 + delay = true;
1.131 + break;
1.132 +
1.133 + case 'e':
1.134 + endless = true;
1.135 + break;
1.136 +
1.137 + case 'b':
1.138 + brightness = atoi(optarg);
1.139 + if (brightness < 0) brightness = 0;
1.140 + if (brightness > 100) brightness = 100;
1.141 + break;
1.142 +
1.143 + default:
1.144 + usage();
1.145 + return 1;
1.146 + } // switch
1.147 + } // while
1.148 +
1.149 + if (configName.length() == 0)
1.150 + {
1.151 + configName = kDefaultConfigFile;
1.152 + syslog(LOG_INFO, "Error: No config file specified, using default (%s).\n", configName.c_str());
1.153 + } // if
1.154 +
1.155 + if (GLCD::Config.Load(configName) == false)
1.156 + {
1.157 + fprintf(stdout, "Error loading config file!\n");
1.158 + return 2;
1.159 + } // if
1.160 +
1.161 + if (GLCD::Config.driverConfigs.size() > 0)
1.162 + {
1.163 + if (displayName.length() > 0)
1.164 + {
1.165 + for (displayNumber = 0; displayNumber < GLCD::Config.driverConfigs.size(); displayNumber++)
1.166 + {
1.167 + if (GLCD::Config.driverConfigs[displayNumber].name == displayName)
1.168 + break;
1.169 + } // for
1.170 +
1.171 + if (displayNumber == GLCD::Config.driverConfigs.size())
1.172 + {
1.173 + fprintf(stdout, "ERROR: Specified display %s not found in config file!\n", displayName.c_str());
1.174 + return 3;
1.175 + } // if
1.176 + }
1.177 + else
1.178 + {
1.179 + fprintf(stdout, "WARNING: No display specified, using first one.\n");
1.180 + displayNumber = 0;
1.181 + } // if
1.182 + }
1.183 + else
1.184 + {
1.185 + fprintf(stdout, "ERROR: No displays specified in config file!\n");
1.186 + return 4;
1.187 + } // if
1.188 +
1.189 + GLCD::Config.driverConfigs[displayNumber].upsideDown ^= upsideDown;
1.190 + GLCD::Config.driverConfigs[displayNumber].invert ^= invert;
1.191 +
1.192 + if (brightness != -1)
1.193 + {
1.194 + GLCD::Config.driverConfigs[displayNumber].brightness = brightness;
1.195 + } // if
1.196 +
1.197 + GLCD::cDriver * lcd = GLCD::CreateDriver(GLCD::Config.driverConfigs[displayNumber].id, &GLCD::Config.driverConfigs[displayNumber]);
1.198 + if (!lcd)
1.199 + {
1.200 + fprintf(stderr, "ERROR: Failed creating display object %s\n", displayName.c_str());
1.201 + return 6;
1.202 + } // if
1.203 +
1.204 + if (lcd->Init() != 0)
1.205 + {
1.206 + fprintf(stderr, "ERROR: Failed initializing display %s\n", displayName.c_str());
1.207 + delete lcd;
1.208 + return 7;
1.209 + } // if
1.210 +
1.211 + lcd->SetBrightness(GLCD::Config.driverConfigs[displayNumber].brightness);
1.212 +
1.213 + signal(SIGINT, sighandler);
1.214 + signal(SIGQUIT, sighandler);
1.215 + signal(SIGTERM, sighandler);
1.216 + signal(SIGHUP, sighandler);
1.217 +
1.218 + //----- show horizontal lines -----
1.219 + for (int aByte = 1; aByte <= 255 && !stopProgramm; ++aByte)
1.220 + {
1.221 + unsigned char aData = GLCD::ReverseBits(aByte);
1.222 + printf("clear and test byte: 0x%02X\n", aByte);
1.223 + lcd->Clear();
1.224 +
1.225 + for (int y = 0; y < lcd->Height() && !stopProgramm; ++y)
1.226 + {
1.227 + for (int x = 0; x < lcd->Width() && !stopProgramm; x += 8)
1.228 + {
1.229 + lcd->Set8Pixels(x, y, aData);
1.230 + } // for
1.231 + } // for
1.232 +
1.233 + lcd->Refresh(true);
1.234 + usleep(sleepMs * 1000);
1.235 + } // for
1.236 +
1.237 + //----- show vertial lines -----
1.238 + for (int aByte = 1; aByte <= 255 && !stopProgramm; ++aByte)
1.239 + {
1.240 + printf("clear and test byte: 0x%02X\n", aByte);
1.241 + lcd->Clear();
1.242 +
1.243 + for (int y = 0; y < lcd->Height() && !stopProgramm; ++y)
1.244 + {
1.245 + unsigned char aData = (((1 << (y % 8)) & aByte) == 0) ? 0x00 : 0xFF;
1.246 + for (int x = 0; x < lcd->Width() && !stopProgramm; x += 8)
1.247 + {
1.248 + lcd->Set8Pixels(x, y, aData);
1.249 + } // for
1.250 + } // for
1.251 +
1.252 + lcd->Refresh(true);
1.253 + usleep(sleepMs * 1000);
1.254 + } // for
1.255 +
1.256 + //----- cleanup -----
1.257 + lcd->Clear();
1.258 + lcd->Refresh(true);
1.259 + lcd->DeInit();
1.260 + delete lcd;
1.261 +
1.262 + return 0;
1.263 +} // main()