diff options
author | Joe Hillenbrand <joehillen@gmail.com> | 2011-02-25 19:52:18 -0800 |
---|---|---|
committer | Joe Hillenbrand <joehillen@gmail.com> | 2011-02-25 19:52:18 -0800 |
commit | 494d1e03de9fbee2bb151ef30835c24f11b0fcb7 (patch) | |
tree | ac096a77da65307a487e00ff444ab9b8be362f8c | |
parent | Update PO files. (diff) | |
download | redshift-ng-494d1e03de9fbee2bb151ef30835c24f11b0fcb7.tar.gz redshift-ng-494d1e03de9fbee2bb151ef30835c24f11b0fcb7.tar.bz2 redshift-ng-494d1e03de9fbee2bb151ef30835c24f11b0fcb7.tar.xz |
Added feature to manually set temperature without needing location data.
-rw-r--r-- | redshift.1 | 2 | ||||
-rw-r--r-- | src/redshift.c | 120 |
2 files changed, 80 insertions, 42 deletions
@@ -42,6 +42,8 @@ Method to use to set color temperature .TP \fB\-o\fR One shot mode (do not continously adjust color temperature) +\fB\-O\fR TEMP +One shot manual mode (set color temperature) .TP \fB\-x\fR Reset mode (remove adjustment from screen) diff --git a/src/redshift.c b/src/redshift.c index f5a7762..5042bd6 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -202,7 +202,8 @@ static const location_provider_t location_providers[] = { typedef enum { PROGRAM_MODE_CONTINUAL, PROGRAM_MODE_ONE_SHOT, - PROGRAM_MODE_RESET + PROGRAM_MODE_RESET, + PROGRAM_MODE_MANUAL } program_mode_t; @@ -296,6 +297,7 @@ print_help(const char *program_name) " \t\t(Type `list' to see available methods)\n" " -o\t\tOne shot mode (do not continously adjust" " color temperature)\n" + " -O TEMP\tOne shot manual mode (set color temperature)\n" " -x\t\tReset mode (remove adjustment from screen)\n" " -r\t\tDisable temperature transitions\n" " -t DAY:NIGHT\tColor temperature to set at daytime/night\n"), @@ -565,6 +567,19 @@ find_location_provider(const char *name) return provider; } +/* Check Color Temperature */ +void +check_temp(int temp) +{ + /* Color temperature at daytime */ + if (temp < MIN_TEMP || temp > MAX_TEMP) { + fprintf(stderr, + _("Temperature must be between %uK and %uK.\n"), + MIN_TEMP, MAX_TEMP); + exit(EXIT_FAILURE); + } +} + int main(int argc, char *argv[]) @@ -584,6 +599,7 @@ main(int argc, char *argv[]) /* Initialize settings to NULL values. */ char *config_filepath = NULL; + int temp_set = -1; int temp_day = -1; int temp_night = -1; float gamma[3] = { NAN, NAN, NAN }; @@ -601,7 +617,7 @@ main(int argc, char *argv[]) /* Parse command line arguments. */ int opt; - while ((opt = getopt(argc, argv, "c:g:hl:m:ort:vx")) != -1) { + while ((opt = getopt(argc, argv, "c:g:hl:m:oO:rt:vx")) != -1) { switch (opt) { case 'c': if (config_filepath != NULL) free(config_filepath); @@ -699,6 +715,22 @@ main(int argc, char *argv[]) case 'o': mode = PROGRAM_MODE_ONE_SHOT; break; + case 'O': + mode = PROGRAM_MODE_MANUAL; + + /* Remove K and k from argument just in case. */ + char* s = optarg; //arg string + char* p; // position + char* k = "Kk"; + for (int i = 0; i < strlen(k); i++) + { + if (p = strchr(s, k[i])) + memmove(p, p+1, strlen(p)); + } + + temp_set = atoi(s); + check_temp(temp_set); + break; case 'r': transition = 0; break; @@ -813,12 +845,16 @@ main(int argc, char *argv[]) if (isnan(gamma[0])) gamma[0] = gamma[1] = gamma[2] = DEFAULT_GAMMA; if (transition < 0) transition = 1; + float lat = NAN; + float lon = NAN; + /* Initialize location provider. If provider is NULL try all providers until one that works is found. */ location_state_t location_state; - /* Location is not needed for reset mode. */ - if (mode != PROGRAM_MODE_RESET) { + /* Location is not needed for reset mode + or for manual temperature setting */ + if (mode != PROGRAM_MODE_RESET && mode != PROGRAM_MODE_MANUAL) { if (provider != NULL) { /* Use provider specified on command line. */ r = provider_try_start(provider, &location_state, @@ -852,61 +888,47 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } } - } - - float lat = NAN; - float lon = NAN; - if (mode != PROGRAM_MODE_RESET) { /* Get current location. */ r = provider->get_location(&location_state, &lat, &lon); if (r < 0) { - fputs(_("Unable to get location from provider.\n"), - stderr); - exit(EXIT_FAILURE); + fputs(_("Unable to get location from provider.\n"), + stderr); + exit(EXIT_FAILURE); } - + provider->free(&location_state); - + if (verbose) { - /* TRANSLATORS: Append degree symbols if possible. */ - printf(_("Location: %f, %f\n"), lat, lon); + /* TRANSLATORS: Append degree symbols if possible. */ + printf(_("Location: %f, %f\n"), lat, lon); } - + /* Latitude */ if (lat < MIN_LAT || lat > MAX_LAT) { - /* TRANSLATORS: Append degree symbols if possible. */ - fprintf(stderr, - _("Latitude must be between %.1f and %.1f.\n"), - MIN_LAT, MAX_LAT); - exit(EXIT_FAILURE); + /* TRANSLATORS: Append degree symbols if possible. */ + fprintf(stderr, + _("Latitude must be between %.1f and %.1f.\n"), + MIN_LAT, MAX_LAT); + exit(EXIT_FAILURE); } - + /* Longitude */ if (lon < MIN_LON || lon > MAX_LON) { - /* TRANSLATORS: Append degree symbols if possible. */ - fprintf(stderr, - _("Longitude must be between" - " %.1f and %.1f.\n"), MIN_LON, MAX_LON); - exit(EXIT_FAILURE); + /* TRANSLATORS: Append degree symbols if possible. */ + fprintf(stderr, + _("Longitude must be between" + " %.1f and %.1f.\n"), MIN_LON, MAX_LON); + exit(EXIT_FAILURE); } - } - /* Color temperature at daytime */ - if (temp_day < MIN_TEMP || temp_day >= MAX_TEMP) { - fprintf(stderr, - _("Temperature must be between %uK and %uK.\n"), - MIN_TEMP, MAX_TEMP); - exit(EXIT_FAILURE); + /* Color temperature at daytime */ + check_temp(temp_day); + + /* Color temperature at night */ + check_temp(temp_night); } - /* Color temperature at night */ - if (temp_night < MIN_TEMP || temp_night >= MAX_TEMP) { - fprintf(stderr, - _("Temperature must be between %uK and %uK.\n"), - MIN_TEMP, MAX_TEMP); - exit(EXIT_FAILURE); - } /* Gamma */ if (gamma[0] < MIN_GAMMA || gamma[0] > MAX_GAMMA || @@ -989,6 +1011,20 @@ main(int argc, char *argv[]) } } break; + case PROGRAM_MODE_MANUAL: + { + if (verbose) printf(_("Color temperature: %uK\n"), temp_set); + + /* Adjust temperature */ + r = method->set_temperature(&state, temp_set, gamma); + if (r < 0) { + fputs(_("Temperature adjustment failed.\n"), stderr); + method->free(&state); + exit(EXIT_FAILURE); + } + + } + break; case PROGRAM_MODE_RESET: { /* Reset screen */ |