# Copyright (C) 2006 Alessandro Di Marco # # LazyCD is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License as published by the Free Software # Foundation; version 2 of the License. # # LazyCD is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along # with LazyCD; if not, write to the Free Software Foundation, Inc., 51 # Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # --- old/smartdimmer/src/smartdimmer.c 2005-07-24 05:13:46.000000000 +0200 +++ new/smartdimmer/src/smartdimmer.c 2006-12-20 23:38:51.000000000 +0100 @@ -6,6 +6,8 @@ * * * July 23, 2005 * * Erik Waling * + * * + * Fading logic by Alessandro Di Marco * ******************************************************************************/ #include @@ -16,6 +18,8 @@ static struct option long_opts[] = { { "get" , no_argument , 0, 'g' }, + { "fade" , required_argument, 0, 'f' }, + { "delay" , required_argument, 0, 'e' }, { "set" , required_argument, 0, 's' }, { "increase", no_argument , 0, 'i' }, { "decrease", no_argument , 0, 'd' }, @@ -30,6 +34,8 @@ printf("Options:\n"); printf("\t-g --get\t\tQuery brightness level.\n"); printf("\t-s --set \tSet brightness level (%d-%d)\n", MIN_LEVEL, MAX_LEVEL); + printf("\t-f --fade \tFade in/out up to the given brightness level (%d-%d)\n", MIN_LEVEL, MAX_LEVEL); + printf("\t-e --delay \tFade cycle delay\n"); printf("\t-i --increase\t\tIncrease brightness with one level.\n"); printf("\t-d --decrease\t\tDecrease brightness with one level.\n"); printf("\t-h --help\t\tPrints this help text.\n\n"); @@ -46,6 +52,27 @@ nv_card.PMC[PMC_SMARTDIM_OFFSET/4] = (level << SMARTDIM_SHIFT) | (nv_card.PMC[PMC_SMARTDIM_OFFSET/4] & ~SMARTDIM_MASK); } +void sd_fade_level(int end, unsigned long delay) { + int i, start = sd_get_level(); + + if (end < MIN_LEVEL) + end = MIN_LEVEL; + if (end > MAX_LEVEL) + end = MAX_LEVEL; + + if (end >= start) { + for (i = start + 1; i <= end; i++) { + nv_card.PMC[PMC_SMARTDIM_OFFSET/4] = (i << SMARTDIM_SHIFT) | (nv_card.PMC[PMC_SMARTDIM_OFFSET/4] & ~SMARTDIM_MASK); + usleep(delay); + } + } else { + for (i = start - 1; i >= end; i--) { + nv_card.PMC[PMC_SMARTDIM_OFFSET/4] = (i << SMARTDIM_SHIFT) | (nv_card.PMC[PMC_SMARTDIM_OFFSET/4] & ~SMARTDIM_MASK); + usleep(delay); + } + } +} + int sd_get_level() { return (nv_card.PMC[PMC_SMARTDIM_OFFSET/4] & SMARTDIM_MASK) >> SMARTDIM_SHIFT; } @@ -65,6 +92,7 @@ int main(int argc, char *argv[]) { int optind = 0, options = 0, setvalue = 0; + unsigned long delay = 7000; int c; if (argc < 2) { @@ -72,7 +100,7 @@ return 0; } - while ((c = getopt_long(argc, argv, "gs:idh", long_opts, &optind)) != -1) { + while ((c = getopt_long(argc, argv, "gf:s:e:idh", long_opts, &optind)) != -1) { switch (c) { case '?': fprintf(stderr, "\nTry `%s --help' for help.\n", argv[0]); @@ -93,6 +121,26 @@ return 1; } break; + case 'e': + if (isdigit(*optarg)) { + delay = atol(optarg); + options |= DEL_BIT; + } else { + fprintf(stderr, "Illegal option value (-e): " + "Value has to be a non-negative number.\n"); + return 1; + } + break; + case 'f': + if (isdigit(*optarg)) { + setvalue = atoi(optarg); + options |= FAD_BIT; + } else { + fprintf(stderr, "Illegal option value (-f): " + "Value has to be a non-negative number.\n"); + return 1; + } + break; case 'i': options |= INC_BIT; break; @@ -102,7 +150,7 @@ } } - if (!options) { + if (!options || ((options & DEL_BIT) && !(options & FAD_BIT))) { sd_usage(argv[0]); return 1; } @@ -125,6 +173,9 @@ if (options & SET_BIT) sd_set_level(setvalue); + if (options & FAD_BIT) + sd_fade_level(setvalue, delay); + if (options & GET_BIT) printf("SmartDimmer level: %d\n", sd_get_level()); --- old/smartdimmer/src/smartdimmer.h 2005-07-24 05:11:50.000000000 +0200 +++ new/smartdimmer/src/smartdimmer.h 2006-12-20 23:23:07.000000000 +0100 @@ -27,9 +27,12 @@ #define GET_BIT 2 #define INC_BIT 4 #define DEC_BIT 8 +#define FAD_BIT 16 +#define DEL_BIT 32 /* function prototypes */ void sd_set_level(int level); +void sd_fade_level(int level, unsigned long delay); int sd_get_level(); int sd_init(); void sd_usage();