Skip to content
This repository
Browse code

Merge branch 'master' of github.com:todbot/blink1

  • Loading branch information...
commit 6cf807a8239b9391dd113bed6d6e1174ee8b2345 2 parents 1cf78fe + 8d59d27
Tod E. Kurt authored

Showing 1 changed file with 49 additions and 27 deletions. Show diff stats Hide diff stats

  1. 76  commandline/blink1-tool.c
76  commandline/blink1-tool.c
@@ -41,6 +41,7 @@ char  deviceIds[blink1_max_devices];
41 41
 char  cmdbuf[9]; 
42 42
 char rgbbuf[4];
43 43
 int verbose;
  44
+int quiet;
44 45
 
45 46
 
46 47
 //---------------------------------------------------------------------------- 
@@ -120,9 +121,10 @@ static void usage(char *myName)
120 121
 "  --eewrite <addr>,<val>      Write an EEPROM byte to blink(1) \n"
121 122
 "  --version                   Display blink(1) firmware version \n"
122 123
 "and [options] are: \n"
123  
-"  -g -nogamma                 Disable autogamma correction\n"
124 124
 "  -d dNums --id all|deviceIds Use these blink(1) ids (from --list) \n"
  125
+"  -g -nogamma                 Disable autogamma correction\n"
125 126
 "  -m ms,   --millis=millis    Set millisecs for color fading (default 300)\n"
  127
+"  -q, --quiet                 Mutes all stdout output (supercedes --verbose)\n"
126 128
 "  -t ms,   --delay=millis     Set millisecs between events (default 500)\n"
127 129
 "  --vid=vid --pid=pid         Specifcy alternate USB VID & PID\n"
128 130
 "  -v, --verbose               verbose debugging msgs\n"
@@ -180,10 +182,11 @@ int main(int argc, char** argv)
180 182
 
181 183
     // parse options
182 184
     int option_index = 0, opt;
183  
-    char* opt_str = "avm:t:d:U:u:g";
  185
+    char* opt_str = "aqvm:t:d:U:u:g";
184 186
     static struct option loptions[] = {
185 187
         {"all",        no_argument,       0,      'a'},
186 188
         {"verbose",    optional_argument, 0,      'v'},
  189
+        {"quiet",      optional_argument, 0,      'q'},
187 190
         {"millis",     required_argument, 0,      'm'},
188 191
         {"delay",      required_argument, 0,      't'},
189 192
         {"id",         required_argument, 0,      'd'},
@@ -267,6 +270,10 @@ int main(int argc, char** argv)
267 270
         case 't':
268 271
             delayMillis = strtol(optarg,NULL,10);
269 272
             break;
  273
+        case 'q':
  274
+            if( optarg==NULL ) quiet++;
  275
+            else quiet = strtol(optarg,NULL,0);
  276
+            break;
270 277
         case 'v':
271 278
             if( optarg==NULL ) verbose++;
272 279
             else verbose = strtol(optarg,NULL,0);
@@ -297,7 +304,9 @@ int main(int argc, char** argv)
297 304
 
298 305
     //FIXME: confusing
299 306
     if( nogamma ) { 
300  
-        printf("disabling auto degamma\n");
  307
+        if ( !quiet ) {
  308
+        	printf("disabling auto degamma\n");
  309
+	}
301 310
         blink1_disableDegamma();  
302 311
     }
303 312
 
@@ -316,8 +325,10 @@ int main(int argc, char** argv)
316 325
 
317 326
     // get a list of all devices and their paths
318 327
     int count = blink1_enumerateByVidPid(vid,pid);
319  
-    if( count == 0 ) { 
320  
-        printf("no blink(1) devices found\n");
  328
+    if( count == 0 ) {
  329
+        if ( !quiet ) {
  330
+            printf("no blink(1) devices found\n");
  331
+        }
321 332
         exit(1);
322 333
     }
323 334
 
@@ -326,7 +337,7 @@ int main(int argc, char** argv)
326 337
     //if( !dev_serial ) 
327 338
     //    dev_serial = blink1_getCachedSerial( deviceIds[0] );
328 339
 
329  
-    if( verbose ) { 
  340
+    if( verbose && !quiet ) { 
330 341
         printf("deviceId[0] = %d\n", deviceIds[0]);
331 342
         //printf("cached path = '%ls'\n", dev_serial);
332 343
         for( int i=0; i< count; i++ ) { 
@@ -337,7 +348,9 @@ int main(int argc, char** argv)
337 348
     // actually open up the device to start talking to it
338 349
     dev = blink1_openById( deviceIds[0] );
339 350
     if( dev == NULL ) { 
340  
-        printf("cannot open blink(1), bad serial number\n");
  351
+        if ( !quiet ) {
  352
+            printf("cannot open blink(1), bad serial number\n");
  353
+        }
341 354
         exit(1);
342 355
     }
343 356
 
@@ -356,8 +369,10 @@ int main(int argc, char** argv)
356 369
             hexdump(cmdbuf, sizeof(cmdbuf));
357 370
         }
358 371
     } 
359  
-    else if( cmd == CMD_HIDWRITE ) { 
360  
-        printf("hidwrite: "); hexdump(cmdbuf,sizeof(cmdbuf));
  372
+    else if( cmd == CMD_HIDWRITE ) {
  373
+        if ( !quiet ) {
  374
+            printf("hidwrite: "); hexdump(cmdbuf,sizeof(cmdbuf));
  375
+        }
361 376
         if((rc = hid_send_feature_report(dev, cmdbuf, sizeof(cmdbuf))) == -1) {
362 377
             fprintf(stderr,"error writing data: %d\n",rc);
363 378
         }
@@ -373,9 +388,9 @@ int main(int argc, char** argv)
373 388
         }
374 389
     }
375 390
     else if( cmd == CMD_EEWRITE ) {  // FIXME
376  
-        printf("eewrite: \n");
  391
+        if ( !quiet ) { printf("eewrite: \n"); }
377 392
         rc = blink1_eewrite(dev, cmdbuf[0], cmdbuf[1] );
378  
-        if( rc==-1 ) { // error
  393
+        if( rc==-1  && !quiet ) { // error
379 394
             printf("error\n");
380 395
         }
381 396
     }
@@ -398,10 +413,12 @@ int main(int argc, char** argv)
398 413
         for( int i=0; i< numDevicesToUse; i++ ) {
399 414
             dev = blink1_openById( deviceIds[i] );
400 415
             if( dev == NULL ) continue;
401  
-            printf("set dev:%d to rgb:0x%2.2x,0x%2.2x,0x%2.2x over %d msec\n",
402  
-                   deviceIds[i],r,g,b,millis);
  416
+            if ( !quiet ) {
  417
+                printf("set dev:%d to rgb:0x%2.2x,0x%2.2x,0x%2.2x over %d msec\n",
  418
+                       deviceIds[i],r,g,b,millis);
  419
+            }
403 420
             rc = blink1_fadeToRGB(dev,millis, r,g,b);
404  
-            if( rc == -1 ) { // on error, do something, anything. come on.
  421
+            if( rc == -1 && !quiet ) { // on error, do something, anything. come on.
405 422
                 printf("error on fadeToRGB\n");
406 423
             }
407 424
             blink1_close( dev );
@@ -411,9 +428,9 @@ int main(int argc, char** argv)
411 428
         uint8_t play = cmdbuf[0];
412 429
         uint8_t pos = cmdbuf[1];
413 430
 
414  
-        printf("%s color pattern at pos %d\n", ((play)?"playing":"stopping"),pos);
  431
+        if ( !quiet ) { printf("%s color pattern at pos %d\n", ((play)?"playing":"stopping"),pos); }
415 432
         rc = blink1_play(dev, play, pos);
416  
-        if( rc == -1 ) { 
  433
+        if( rc == -1 && !quiet ) { 
417 434
         }
418 435
     }
419 436
     else if( cmd == CMD_SAVERGB ) {
@@ -421,9 +438,9 @@ int main(int argc, char** argv)
421 438
         uint8_t g = cmdbuf[1];
422 439
         uint8_t b = cmdbuf[2];
423 440
         uint8_t p = cmdbuf[3];
424  
-        printf("saving rgb: 0x%2.2x,0x%2.2x,0x%2.2x to pos %d\n", r,g,b,p );
  441
+        if ( !quiet ) { printf("saving rgb: 0x%2.2x,0x%2.2x,0x%2.2x to pos %d\n", r,g,b,p ); }
425 442
         rc = blink1_writePatternLine(dev, millis, r,g,b, p );
426  
-        if( rc==-1 ) {
  443
+        if( rc==-1 && !quiet ) {
427 444
             printf("error on writePatternLine\n");
428 445
         }
429 446
     }
@@ -433,7 +450,7 @@ int main(int argc, char** argv)
433 450
         uint16_t msecs;
434 451
         printf("reading rgb at pos %d: ", p );
435 452
         rc = blink1_readPatternLine(dev, &msecs, &r,&g,&b, p );
436  
-        if( rc==-1 ) {
  453
+        if( rc==-1 && !quiet ) {
437 454
             printf("error on writePatternLine\n");
438 455
         }
439 456
         printf("r,g,b = %x,%x,%x millis:%d\n", r,g,b, msecs);
@@ -441,20 +458,22 @@ int main(int argc, char** argv)
441 458
     else if( cmd == CMD_RANDOM ) { 
442 459
         int cnt = blink1_getCachedCount();
443 460
         if( cnt>1 ) blink1_close(dev); // close global device, open as needed
444  
-        printf("random %d times: \n", arg);
  461
+        if ( !quiet ) { printf("random %d times: \n", arg); }
445 462
         for( int i=0; i<arg; i++ ) { 
446 463
             uint8_t r = rand()%255;
447 464
             uint8_t g = rand()%255;
448 465
             uint8_t b = rand()%255 ;
449 466
             uint8_t id = rand() % blink1_getCachedCount();
450 467
 
451  
-            printf("%d: %d/%d : %2.2x,%2.2x,%2.2x \n", 
452  
-                   i, id, blink1_getCachedCount(), r,g,b);
  468
+            if ( !quiet ) {
  469
+                printf("%d: %d/%d : %2.2x,%2.2x,%2.2x \n", 
  470
+                       i, id, blink1_getCachedCount(), r,g,b);
  471
+            }
453 472
 
454 473
             hid_device* mydev = dev;
455 474
             if( cnt > 1 ) mydev = blink1_openById( id );
456 475
             rc = blink1_fadeToRGB(mydev, millis,r,g,b);
457  
-            if( rc == -1 ) { // on error, do something, anything. come on.
  476
+            if( rc == -1 && !quiet ) { // on error, do something, anything. come on.
458 477
 	        printf("error during random\n");
459 478
                 //break;
460 479
             }
@@ -471,7 +490,7 @@ int main(int argc, char** argv)
471 490
         if( r == 0 && b == 0 && g == 0 ) {
472 491
             r = g = b = 255;
473 492
         }
474  
-        printf("blink %d times rgb:%x,%x,%x: \n", n,r,g,b);
  493
+        if ( !quiet ) { printf("blink %d times rgb:%x,%x,%x: \n", n,r,g,b); }
475 494
         for( int i=0; i<n; i++ ) { 
476 495
             rc = blink1_fadeToRGB(dev, millis,r,g,b);
477 496
             blink1_sleep(delayMillis);
@@ -481,14 +500,17 @@ int main(int argc, char** argv)
481 500
     }
482 501
     else if( cmd == CMD_SERVERDOWN ) { 
483 502
         int on  = arg;
484  
-        printf("setting serverdown %s (at %d millis)\n", 
485  
-               ((on)?"ON":"OFF"), delayMillis);
  503
+        if ( !quiet ) {
  504
+            printf("setting serverdown %s (at %d millis)\n", 
  505
+                   ((on)?"ON":"OFF"), delayMillis);
  506
+        }
486 507
         blink1_serverdown( dev, on, delayMillis );
487 508
     }
488 509
     // use caution with this, could make your blink(1) unusable
489 510
     // --serialnumwrite abcd1234
490 511
     else if( cmd == CMD_SERIALNUMWRITE ) { 
491  
-        printf("serial number write: %s\n",tmpstr);
  512
+        if ( !quiet ) { printf("serial number write: %s\n",tmpstr); }
  513
+
492 514
         //for( int i=0; i<4; i++)  printf("%2.2X,",cmdbuf[i]);
493 515
         //printf("\n");
494 516
         if( (rc = blink1_serialnumwrite( dev, tmpstr)) == -1 ) { 

0 notes on commit 6cf807a

Please sign in to comment.
Something went wrong with that request. Please try again.