graphlcd-base/tools/lcdtestpattern/lcdtestpattern.c
author cpresser@slime-ws
Sat, 26 Jul 2008 14:22:38 +0200
changeset 25 96f051df5d60
parent 4 df6a40031aa5
permissions -rw-r--r--
added eeprom code
root@4
     1
/*
root@4
     2
 * GraphLCD tool lcdtestpattern
root@4
     3
 *
root@4
     4
 * lcdtestpattern.c  -  a tool to display some testpattern on an GLCD
root@4
     5
 *
root@4
     6
 * based on showpic.c of graphlcd-base
root@4
     7
 *   (c) 2004 Andreas Regel <andreas.regel AT powarman.de>
root@4
     8
 *
root@4
     9
 * This file is released under the GNU General Public License. Refer
root@4
    10
 * to the COPYING file distributed with this package.
root@4
    11
 *
root@4
    12
 * (c) 2007 Alexander Rieger (Alexander.Rieger AT inka.de)
root@4
    13
 */
root@4
    14
root@4
    15
//-----------------------------------------------------------------------------
root@4
    16
#include <stdio.h>
root@4
    17
#include <string.h>
root@4
    18
#include <stdlib.h>
root@4
    19
#include <getopt.h>
root@4
    20
#include <dlfcn.h>
root@4
    21
#include <unistd.h>
root@4
    22
#include <syslog.h>
root@4
    23
#include <signal.h>
root@4
    24
root@4
    25
#include <string>
root@4
    26
root@4
    27
#include <glcdgraphics/bitmap.h>
root@4
    28
#include <glcdgraphics/glcd.h>
root@4
    29
#include <glcdgraphics/image.h>
root@4
    30
#include <glcddrivers/config.h>
root@4
    31
#include <glcddrivers/common.h>
root@4
    32
#include <glcddrivers/driver.h>
root@4
    33
#include <glcddrivers/drivers.h>
root@4
    34
root@4
    35
//-----------------------------------------------------------------------------
root@4
    36
static const char *prgname = "lcdtestpattern";
root@4
    37
static const char *version = "0.1.0";
root@4
    38
root@4
    39
static const int kDefaultSleepMs = 0;
root@4
    40
static const char * kDefaultConfigFile = "/etc/graphlcd.conf";
root@4
    41
root@4
    42
static volatile bool stopProgramm = false;
root@4
    43
root@4
    44
//-----------------------------------------------------------------------------
root@4
    45
static void sighandler(int signal)
root@4
    46
{
root@4
    47
	switch (signal)
root@4
    48
	{
root@4
    49
		case SIGINT:
root@4
    50
		case SIGQUIT:
root@4
    51
		case SIGTERM:
root@4
    52
			stopProgramm = true;
root@4
    53
	} // switch
root@4
    54
} // sighandler()
root@4
    55
root@4
    56
//-----------------------------------------------------------------------------
root@4
    57
void usage()
root@4
    58
{
root@4
    59
    fprintf(stdout, "\n");
root@4
    60
    fprintf(stdout, "%s v%s\n", prgname, version);
root@4
    61
    fprintf(stdout, "%s is a tool to show test patterns on a LCD.\n", prgname);
root@4
    62
    fprintf(stdout, "\n");
root@4
    63
    fprintf(stdout, "  Usage: %s [-c CONFIGFILE] [-d DISPLAY] [-s SLEEP] [-uie]\n\n", prgname);
root@4
    64
    fprintf(stdout, "  -c  --config      specifies the location of the config file\n");
root@4
    65
    fprintf(stdout, "                    (default: /etc/graphlcd.conf)\n");
root@4
    66
    fprintf(stdout, "  -d  --display     specifies the output display (default is the first one)\n");
root@4
    67
    fprintf(stdout, "  -u  --upsidedown  rotates the output by 180 degrees (default: no)\n");
root@4
    68
    fprintf(stdout, "  -i  --invert      inverts the output (default: no)\n");
root@4
    69
    fprintf(stdout, "  -e  --endless     show all images in endless loop (default: no)\n");
root@4
    70
    fprintf(stdout, "  -s  --sleep       set sleeptime between two patterns [ms] (default: %d ms)\n", kDefaultSleepMs);
root@4
    71
    fprintf(stdout, "  -b  --brightness  set brightness for display if driver support it [%%]\n");
root@4
    72
    fprintf(stdout, "                    (default: config file value)\n");
root@4
    73
    fprintf(stdout, "\n" );
root@4
    74
    fprintf(stdout, "  examples: %s -c /etc/graphlcd.conf\n", prgname);
root@4
    75
    fprintf(stdout, "            %s -c /etc/graphlcd.conf -d LCD_T6963 -u -i\n", prgname);
root@4
    76
    fprintf(stdout, "\n" );
root@4
    77
} // usage()
root@4
    78
root@4
    79
//-----------------------------------------------------------------------------
root@4
    80
int main(int argc, char *argv[])
root@4
    81
{
root@4
    82
    static struct option long_options[] =
root@4
    83
    {
root@4
    84
        {"config",     required_argument, NULL, 'c'},
root@4
    85
        {"display",    required_argument, NULL, 'd'},
root@4
    86
        {"sleep",      required_argument, NULL, 's'},
root@4
    87
        {"endless",          no_argument, NULL, 'e'},
root@4
    88
        {"upsidedown",       no_argument, NULL, 'u'},
root@4
    89
        {"invert",           no_argument, NULL, 'i'},
root@4
    90
        {"brightness", required_argument, NULL, 'b'},
root@4
    91
        {NULL}
root@4
    92
    };
root@4
    93
root@4
    94
    std::string configName = "";
root@4
    95
    std::string displayName = "";
root@4
    96
    bool upsideDown = false;
root@4
    97
    bool invert = false;
root@4
    98
    int brightness = -1;
root@4
    99
    bool delay = false;
root@4
   100
    int sleepMs = kDefaultSleepMs;
root@4
   101
    bool endless = false;
root@4
   102
    unsigned int displayNumber = 0;
root@4
   103
root@4
   104
    int c, option_index = 0;
root@4
   105
    while ((c = getopt_long(argc, argv, "c:d:s:euib:", long_options, &option_index)) != -1)
root@4
   106
    {
root@4
   107
        switch(c)
root@4
   108
        {
root@4
   109
          case 'c':
root@4
   110
              configName = optarg;
root@4
   111
              break;
root@4
   112
root@4
   113
          case 'd':
root@4
   114
              displayName = optarg;
root@4
   115
              break;
root@4
   116
root@4
   117
          case 'u':
root@4
   118
              upsideDown = true;
root@4
   119
              break;
root@4
   120
root@4
   121
          case 'i':
root@4
   122
              invert = true;
root@4
   123
              break;
root@4
   124
root@4
   125
          case 's':
root@4
   126
              sleepMs = atoi(optarg);
root@4
   127
              delay = true;
root@4
   128
              break;
root@4
   129
root@4
   130
          case 'e':
root@4
   131
              endless = true;
root@4
   132
              break;
root@4
   133
root@4
   134
          case 'b':
root@4
   135
              brightness = atoi(optarg);
root@4
   136
              if (brightness < 0) brightness = 0;
root@4
   137
              if (brightness > 100) brightness = 100;
root@4
   138
              break;
root@4
   139
root@4
   140
          default:
root@4
   141
              usage();
root@4
   142
              return 1;
root@4
   143
        } // switch
root@4
   144
    } // while
root@4
   145
root@4
   146
    if (configName.length() == 0)
root@4
   147
    {
root@4
   148
        configName = kDefaultConfigFile;
root@4
   149
        syslog(LOG_INFO, "Error: No config file specified, using default (%s).\n", configName.c_str());
root@4
   150
    } // if
root@4
   151
root@4
   152
    if (GLCD::Config.Load(configName) == false)
root@4
   153
    {
root@4
   154
        fprintf(stdout, "Error loading config file!\n");
root@4
   155
        return 2;
root@4
   156
    } // if
root@4
   157
root@4
   158
    if (GLCD::Config.driverConfigs.size() > 0)
root@4
   159
    {
root@4
   160
        if (displayName.length() > 0)
root@4
   161
        {
root@4
   162
            for (displayNumber = 0; displayNumber < GLCD::Config.driverConfigs.size(); displayNumber++)
root@4
   163
            {
root@4
   164
              if (GLCD::Config.driverConfigs[displayNumber].name == displayName)
root@4
   165
                break;
root@4
   166
            } // for
root@4
   167
root@4
   168
            if (displayNumber == GLCD::Config.driverConfigs.size())
root@4
   169
            {
root@4
   170
              fprintf(stdout, "ERROR: Specified display %s not found in config file!\n", displayName.c_str());
root@4
   171
              return 3;
root@4
   172
            } // if
root@4
   173
        }
root@4
   174
        else
root@4
   175
        {
root@4
   176
            fprintf(stdout, "WARNING: No display specified, using first one.\n");
root@4
   177
            displayNumber = 0;
root@4
   178
        } // if
root@4
   179
    }
root@4
   180
    else
root@4
   181
    {
root@4
   182
        fprintf(stdout, "ERROR: No displays specified in config file!\n");
root@4
   183
        return 4;
root@4
   184
    } // if
root@4
   185
root@4
   186
    GLCD::Config.driverConfigs[displayNumber].upsideDown ^= upsideDown;
root@4
   187
    GLCD::Config.driverConfigs[displayNumber].invert     ^= invert;
root@4
   188
root@4
   189
    if (brightness != -1)
root@4
   190
    {
root@4
   191
        GLCD::Config.driverConfigs[displayNumber].brightness = brightness;
root@4
   192
    } // if
root@4
   193
root@4
   194
    GLCD::cDriver * lcd = GLCD::CreateDriver(GLCD::Config.driverConfigs[displayNumber].id, &GLCD::Config.driverConfigs[displayNumber]);
root@4
   195
    if (!lcd)
root@4
   196
    {
root@4
   197
        fprintf(stderr, "ERROR: Failed creating display object %s\n", displayName.c_str());
root@4
   198
        return 6;
root@4
   199
    } // if
root@4
   200
root@4
   201
    if (lcd->Init() != 0)
root@4
   202
    {
root@4
   203
        fprintf(stderr, "ERROR: Failed initializing display %s\n", displayName.c_str());
root@4
   204
        delete lcd;
root@4
   205
        return 7;
root@4
   206
    } // if
root@4
   207
root@4
   208
    lcd->SetBrightness(GLCD::Config.driverConfigs[displayNumber].brightness);
root@4
   209
root@4
   210
    signal(SIGINT, sighandler);
root@4
   211
    signal(SIGQUIT, sighandler);
root@4
   212
    signal(SIGTERM, sighandler);
root@4
   213
    signal(SIGHUP, sighandler);
root@4
   214
root@4
   215
    //----- show horizontal lines -----
root@4
   216
    for (int aByte = 1; aByte <= 255 && !stopProgramm; ++aByte)
root@4
   217
    {
root@4
   218
        unsigned char aData = GLCD::ReverseBits(aByte);
root@4
   219
        printf("clear and test byte: 0x%02X\n", aByte);
root@4
   220
        lcd->Clear();
root@4
   221
root@4
   222
        for (int y = 0; y < lcd->Height() && !stopProgramm; ++y)
root@4
   223
        {
root@4
   224
            for (int x = 0; x < lcd->Width() && !stopProgramm; x += 8)
root@4
   225
            {
root@4
   226
               lcd->Set8Pixels(x, y, aData);
root@4
   227
            } // for
root@4
   228
        } // for
root@4
   229
root@4
   230
        lcd->Refresh(true);
root@4
   231
        usleep(sleepMs * 1000);
root@4
   232
    } // for
root@4
   233
root@4
   234
    //----- show vertial lines -----
root@4
   235
    for (int aByte = 1; aByte <= 255 && !stopProgramm; ++aByte)
root@4
   236
    {
root@4
   237
        printf("clear and test byte: 0x%02X\n", aByte);
root@4
   238
        lcd->Clear();
root@4
   239
root@4
   240
        for (int y = 0; y < lcd->Height() && !stopProgramm; ++y)
root@4
   241
        {
root@4
   242
            unsigned char aData = (((1 << (y % 8)) & aByte) == 0) ? 0x00 : 0xFF;
root@4
   243
            for (int x = 0; x < lcd->Width() && !stopProgramm; x += 8)
root@4
   244
            {
root@4
   245
               lcd->Set8Pixels(x, y, aData);
root@4
   246
            } // for
root@4
   247
        } // for
root@4
   248
root@4
   249
        lcd->Refresh(true);
root@4
   250
        usleep(sleepMs * 1000);
root@4
   251
    } // for
root@4
   252
root@4
   253
    //----- cleanup -----
root@4
   254
    lcd->Clear();
root@4
   255
    lcd->Refresh(true);
root@4
   256
    lcd->DeInit();
root@4
   257
    delete lcd;
root@4
   258
root@4
   259
    return 0;
root@4
   260
} // main()