From 52129c94ec03ddce96033b9b35fe712032235e74 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 5 Oct 2021 17:45:43 -0400 Subject: [PATCH] spacing. Use a separate boolean to tell if we have specified a new value for controls. This allows negative settings. Fix zmy outputting brightness when contrast is specified. --- src/zmu.cpp | 77 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/src/zmu.cpp b/src/zmu.cpp index ddf66a3dd..ec4ae7b86 100644 --- a/src/zmu.cpp +++ b/src/zmu.cpp @@ -257,9 +257,16 @@ int main(int argc, char *argv[]) { int image_idx = -1; int scale = -1; int brightness = -1; + bool have_brightness = false; + int contrast = -1; + bool have_contrast = false; + int hue = -1; + bool have_hue = false; int colour = -1; + bool have_colour = false; + char *zoneString = nullptr; char *username = nullptr; char *password = nullptr; @@ -272,13 +279,13 @@ int main(int argc, char *argv[]) { int option_index = 0; int c = getopt_long(argc, argv, "d:m:vsEDLurwei::S:t::fz::ancqhlB::C::H::O::RWU:P:A:V:T:", long_options, &option_index); - if ( c == -1 ) { + if (c == -1) { break; } switch (c) { case 'd': - if ( optarg ) + if (optarg) device = optarg; break; case 'm': @@ -292,7 +299,7 @@ int main(int argc, char *argv[]) { break; case 'i': function |= ZMU_IMAGE; - if ( optarg ) + if (optarg) image_idx = atoi(optarg); break; case 'S': @@ -300,7 +307,7 @@ int main(int argc, char *argv[]) { break; case 't': function |= ZMU_TIME; - if ( optarg ) + if (optarg) image_idx = atoi(optarg); break; case 'R': @@ -317,7 +324,7 @@ int main(int argc, char *argv[]) { break; case 'z': function |= ZMU_ZONES; - if ( optarg ) + if (optarg) zoneString = optarg; break; case 'a': @@ -349,23 +356,31 @@ int main(int argc, char *argv[]) { break; case 'B': function |= ZMU_BRIGHTNESS; - if ( optarg ) + if (optarg) { + have_brightness = true; brightness = atoi(optarg); + } break; case 'C': function |= ZMU_CONTRAST; - if ( optarg ) + if (optarg) { + have_contrast = true; contrast = atoi(optarg); + } break; case 'H': function |= ZMU_HUE; - if ( optarg ) + if (optarg) { + have_hue = true; hue = atoi(optarg); + } break; case 'O': function |= ZMU_COLOUR; - if ( optarg ) + if (optarg) { + have_colour = true; colour = atoi(optarg); + } break; case 'U': username = optarg; @@ -650,60 +665,60 @@ int main(int argc, char *argv[]) { monitor->DumpSettings(monString, verbose); printf("%s\n", monString); } - if ( function & ZMU_BRIGHTNESS ) { - if ( verbose ) { - if ( brightness >= 0 ) + if (function & ZMU_BRIGHTNESS) { + if (verbose) { + if (have_brightness) printf("New brightness: %d\n", monitor->actionBrightness(brightness)); else printf("Current brightness: %d\n", monitor->actionBrightness()); } else { - if ( have_output ) fputc(separator, stdout); - if ( brightness >= 0 ) + if (have_output) fputc(separator, stdout); + if (have_brightness) printf("%d", monitor->actionBrightness(brightness)); else printf("%d", monitor->actionBrightness()); have_output = true; } } - if ( function & ZMU_CONTRAST ) { - if ( verbose ) { - if ( contrast >= 0 ) - printf("New brightness: %d\n", monitor->actionContrast(contrast)); + if (function & ZMU_CONTRAST) { + if (verbose) { + if (have_contrast) + printf("New contrast: %d\n", monitor->actionContrast(contrast)); else printf("Current contrast: %d\n", monitor->actionContrast()); } else { - if ( have_output ) fputc(separator, stdout); - if ( contrast >= 0 ) + if (have_output) fputc(separator, stdout); + if (have_contrast) printf("%d", monitor->actionContrast(contrast)); else printf("%d", monitor->actionContrast()); have_output = true; } } - if ( function & ZMU_HUE ) { - if ( verbose ) { - if ( hue >= 0 ) + if (function & ZMU_HUE) { + if (verbose) { + if (have_hue) printf("New hue: %d\n", monitor->actionHue(hue)); else printf("Current hue: %d\n", monitor->actionHue()); } else { - if ( have_output ) fputc(separator, stdout); - if ( hue >= 0 ) + if (have_output) fputc(separator, stdout); + if (have_hue) printf("%d", monitor->actionHue(hue)); else printf("%d", monitor->actionHue()); have_output = true; } } - if ( function & ZMU_COLOUR ) { - if ( verbose ) { - if ( colour >= 0 ) + if (function & ZMU_COLOUR) { + if (verbose) { + if (have_colour) printf("New colour: %d\n", monitor->actionColour(colour)); else printf("Current colour: %d\n", monitor->actionColour()); } else { - if ( have_output ) fputc(separator, stdout); - if ( colour >= 0 ) + if (have_output) fputc(separator, stdout); + if (have_colour) printf("%d", monitor->actionColour(colour)); else printf("%d", monitor->actionColour()); @@ -711,7 +726,7 @@ int main(int argc, char *argv[]) { } } - if ( have_output ) { + if (have_output) { printf("\n"); } if ( !function ) {