Skip to content

Commit

Permalink
Add a -b brightness flag to led-image-viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
jwheare committed Nov 29, 2015
1 parent 63a5da1 commit c6cce1f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions led-image-viewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ static int usage(const char *progname) {
"Default: 1\n"
"\t-c <chained> : Daisy-chained boards. Default: 1.\n"
"\t-L : Large 64x64 display made from four 32x32 in a chain\n"
"\t-d : Run as daemon.\n");
"\t-d : Run as daemon.\n"
"\t-b <brightnes>: Sets brightness percent. Default: 100.\n");
return 1;
}

Expand All @@ -166,17 +167,19 @@ int main(int argc, char *argv[]) {
int chain = 1;
int parallel = 1;
int pwm_bits = -1;
int brightness = 100;
bool large_display = false; // example for using Transformers
bool as_daemon = false;

int opt;
while ((opt = getopt(argc, argv, "r:P:c:p:dL")) != -1) {
while ((opt = getopt(argc, argv, "r:P:c:p:b:dL")) != -1) {
switch (opt) {
case 'r': rows = atoi(optarg); break;
case 'P': parallel = atoi(optarg); break;
case 'c': chain = atoi(optarg); break;
case 'p': pwm_bits = atoi(optarg); break;
case 'd': as_daemon = true; break;
case 'b': brightness = atoi(optarg); break;
case 'L':
chain = 4;
rows = 32;
Expand Down Expand Up @@ -205,6 +208,11 @@ int main(int argc, char *argv[]) {
return usage(argv[0]);
}

if (brightness < 1 || brightness > 100) {
fprintf(stderr, "Brightness is outside usable range.\n");
return usage(argv[0]);
}

if (optind >= argc) {
fprintf(stderr, "Expected image filename.\n");
return usage(argv[0]);
Expand Down Expand Up @@ -234,6 +242,8 @@ int main(int argc, char *argv[]) {
return 1;
}

matrix->SetBrightness(brightness);

// Here is an example where to add your own transformer. In this case, we
// just to the chain-of-four-32x32 => 64x64 transformer, but just use any
// of the transformers in transformer.h or write your own.
Expand Down

0 comments on commit c6cce1f

Please sign in to comment.