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.

This commit is contained in:
Isaac Connor 2021-10-05 17:45:43 -04:00
parent ba26235763
commit 52129c94ec
1 changed files with 46 additions and 31 deletions

View File

@ -257,9 +257,16 @@ int main(int argc, char *argv[]) {
int image_idx = -1; int image_idx = -1;
int scale = -1; int scale = -1;
int brightness = -1; int brightness = -1;
bool have_brightness = false;
int contrast = -1; int contrast = -1;
bool have_contrast = false;
int hue = -1; int hue = -1;
bool have_hue = false;
int colour = -1; int colour = -1;
bool have_colour = false;
char *zoneString = nullptr; char *zoneString = nullptr;
char *username = nullptr; char *username = nullptr;
char *password = nullptr; char *password = nullptr;
@ -272,13 +279,13 @@ int main(int argc, char *argv[]) {
int option_index = 0; 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); 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; break;
} }
switch (c) { switch (c) {
case 'd': case 'd':
if ( optarg ) if (optarg)
device = optarg; device = optarg;
break; break;
case 'm': case 'm':
@ -292,7 +299,7 @@ int main(int argc, char *argv[]) {
break; break;
case 'i': case 'i':
function |= ZMU_IMAGE; function |= ZMU_IMAGE;
if ( optarg ) if (optarg)
image_idx = atoi(optarg); image_idx = atoi(optarg);
break; break;
case 'S': case 'S':
@ -300,7 +307,7 @@ int main(int argc, char *argv[]) {
break; break;
case 't': case 't':
function |= ZMU_TIME; function |= ZMU_TIME;
if ( optarg ) if (optarg)
image_idx = atoi(optarg); image_idx = atoi(optarg);
break; break;
case 'R': case 'R':
@ -317,7 +324,7 @@ int main(int argc, char *argv[]) {
break; break;
case 'z': case 'z':
function |= ZMU_ZONES; function |= ZMU_ZONES;
if ( optarg ) if (optarg)
zoneString = optarg; zoneString = optarg;
break; break;
case 'a': case 'a':
@ -349,23 +356,31 @@ int main(int argc, char *argv[]) {
break; break;
case 'B': case 'B':
function |= ZMU_BRIGHTNESS; function |= ZMU_BRIGHTNESS;
if ( optarg ) if (optarg) {
have_brightness = true;
brightness = atoi(optarg); brightness = atoi(optarg);
}
break; break;
case 'C': case 'C':
function |= ZMU_CONTRAST; function |= ZMU_CONTRAST;
if ( optarg ) if (optarg) {
have_contrast = true;
contrast = atoi(optarg); contrast = atoi(optarg);
}
break; break;
case 'H': case 'H':
function |= ZMU_HUE; function |= ZMU_HUE;
if ( optarg ) if (optarg) {
have_hue = true;
hue = atoi(optarg); hue = atoi(optarg);
}
break; break;
case 'O': case 'O':
function |= ZMU_COLOUR; function |= ZMU_COLOUR;
if ( optarg ) if (optarg) {
have_colour = true;
colour = atoi(optarg); colour = atoi(optarg);
}
break; break;
case 'U': case 'U':
username = optarg; username = optarg;
@ -650,60 +665,60 @@ int main(int argc, char *argv[]) {
monitor->DumpSettings(monString, verbose); monitor->DumpSettings(monString, verbose);
printf("%s\n", monString); printf("%s\n", monString);
} }
if ( function & ZMU_BRIGHTNESS ) { if (function & ZMU_BRIGHTNESS) {
if ( verbose ) { if (verbose) {
if ( brightness >= 0 ) if (have_brightness)
printf("New brightness: %d\n", monitor->actionBrightness(brightness)); printf("New brightness: %d\n", monitor->actionBrightness(brightness));
else else
printf("Current brightness: %d\n", monitor->actionBrightness()); printf("Current brightness: %d\n", monitor->actionBrightness());
} else { } else {
if ( have_output ) fputc(separator, stdout); if (have_output) fputc(separator, stdout);
if ( brightness >= 0 ) if (have_brightness)
printf("%d", monitor->actionBrightness(brightness)); printf("%d", monitor->actionBrightness(brightness));
else else
printf("%d", monitor->actionBrightness()); printf("%d", monitor->actionBrightness());
have_output = true; have_output = true;
} }
} }
if ( function & ZMU_CONTRAST ) { if (function & ZMU_CONTRAST) {
if ( verbose ) { if (verbose) {
if ( contrast >= 0 ) if (have_contrast)
printf("New brightness: %d\n", monitor->actionContrast(contrast)); printf("New contrast: %d\n", monitor->actionContrast(contrast));
else else
printf("Current contrast: %d\n", monitor->actionContrast()); printf("Current contrast: %d\n", monitor->actionContrast());
} else { } else {
if ( have_output ) fputc(separator, stdout); if (have_output) fputc(separator, stdout);
if ( contrast >= 0 ) if (have_contrast)
printf("%d", monitor->actionContrast(contrast)); printf("%d", monitor->actionContrast(contrast));
else else
printf("%d", monitor->actionContrast()); printf("%d", monitor->actionContrast());
have_output = true; have_output = true;
} }
} }
if ( function & ZMU_HUE ) { if (function & ZMU_HUE) {
if ( verbose ) { if (verbose) {
if ( hue >= 0 ) if (have_hue)
printf("New hue: %d\n", monitor->actionHue(hue)); printf("New hue: %d\n", monitor->actionHue(hue));
else else
printf("Current hue: %d\n", monitor->actionHue()); printf("Current hue: %d\n", monitor->actionHue());
} else { } else {
if ( have_output ) fputc(separator, stdout); if (have_output) fputc(separator, stdout);
if ( hue >= 0 ) if (have_hue)
printf("%d", monitor->actionHue(hue)); printf("%d", monitor->actionHue(hue));
else else
printf("%d", monitor->actionHue()); printf("%d", monitor->actionHue());
have_output = true; have_output = true;
} }
} }
if ( function & ZMU_COLOUR ) { if (function & ZMU_COLOUR) {
if ( verbose ) { if (verbose) {
if ( colour >= 0 ) if (have_colour)
printf("New colour: %d\n", monitor->actionColour(colour)); printf("New colour: %d\n", monitor->actionColour(colour));
else else
printf("Current colour: %d\n", monitor->actionColour()); printf("Current colour: %d\n", monitor->actionColour());
} else { } else {
if ( have_output ) fputc(separator, stdout); if (have_output) fputc(separator, stdout);
if ( colour >= 0 ) if (have_colour)
printf("%d", monitor->actionColour(colour)); printf("%d", monitor->actionColour(colour));
else else
printf("%d", monitor->actionColour()); printf("%d", monitor->actionColour());
@ -711,7 +726,7 @@ int main(int argc, char *argv[]) {
} }
} }
if ( have_output ) { if (have_output) {
printf("\n"); printf("\n");
} }
if ( !function ) { if ( !function ) {