Пример #1
0
int main(int argc, char* argv[]) {
    if (argc < 2) {
        fprintf(stderr, "Expected an argument specifying an increment\n");
        exit(1);
    }

    char* backend = getenv(ENV_BRIGHTNESS_BACKEND);
    if (!backend) {
        backend = DEFAULT_BACKEND;
    }

    int current_brightness = get_brightness(backend, "brightness");
    int max_brightness = get_brightness(backend, "max_brightness");

    char c = argv[1][0];
    double increment = atof(argv[1]) / 100 * max_brightness + 0.5;
    int brightness = c == '+' || c == '-' ?
        current_brightness + increment : increment;

    if (brightness < 0) brightness = 0;
    else if (brightness > max_brightness) brightness = max_brightness;
    double percent = 100.0 * brightness / max_brightness;

    set_brightness(backend, "brightness", brightness);

    printf("%.0f%%\n", percent);
    return 0;
}
Пример #2
0
void process_lamp_job(LAMP_JOB_t job)
{
    int16_t tmp;
    int16_t tmp2;

    switch(job) {
    case LJ_MANUAL_UP:
        up(MANUAL_UP_DELAY);
        break;
    case LJ_MANUAL_DOWN:
        down(MANUAL_DOWN_DELAY);
        break;
    case LJ_FADE_IN:
        tmp = get_brightness();
        tmp2 = (tmp<LAMP_BRIGHTNESS_MAX/2)?LAMP_BRIGHTNESS_MAX/2:LAMP_BRIGHTNESS_MAX;
        fade(tmp,tmp2,AUTO_FADE_IN_DELAY);
        break;
    case LJ_FADE_OUT:
        tmp = get_brightness();
        tmp2 = (tmp>LAMP_BRIGHTNESS_MAX/2)?LAMP_BRIGHTNESS_MAX/2:0;
        fade(tmp,tmp2,AUTO_FADE_IN_DELAY);
        break;
#ifdef USE_SOFT_UART
    case LJ_SEND_REMOTE_UP:
        soft_uart_send('+');
        break;
    case LJ_SEND_REMOTE_DOWN:
        soft_uart_send('-');
        break;
    case LJ_SEND_REMOTE_FADE_IN:
        soft_uart_send('F');
        break;
    case LJ_SEND_REMOTE_FADE_OUT:
        soft_uart_send('f');
        break;
    case LJ_RECVD_REMOTE_UP:
        up(MANUAL_UP_DELAY);
        break;
    case LJ_RECVD_REMOTE_DOWN:
        down(MANUAL_DOWN_DELAY);
        break;
    case LJ_RECVD_REMOTE_FADE_IN:
        tmp = get_brightness();
        tmp2 = (tmp<LAMP_BRIGHTNESS_MAX/2)?LAMP_BRIGHTNESS_MAX/2:LAMP_BRIGHTNESS_MAX;
        fade(tmp,tmp2,AUTO_FADE_IN_DELAY);
        break;
    case LJ_RECVD_REMOTE_FADE_OUT:
        tmp = get_brightness();
        tmp2 = (tmp>LAMP_BRIGHTNESS_MAX/2)?LAMP_BRIGHTNESS_MAX/2:0;
        fade(tmp,tmp2,AUTO_FADE_IN_DELAY);
        break;
#endif
    default:
        // LJ_NOP
        break;
    }
}
Пример #3
0
/*
 ** This code is based on the manpages on strtol. It removed an atoi() call
 ** and will just take 1 parameter. It will further check for the parameter
 ** to be within a certain range. If it does not match it will be set to the
 ** closest bound.
 */
int main(int argc, char *argv[])
{
        if (argc != 2) {
                fprintf(stderr, "Usage: %s str\n", argv[0]);
                exit(EXIT_FAILURE);
        }

        struct data *brgt = malloc(sizeof(struct data));
        memset(brgt, 0, sizeof(struct data));
        FILE *fp = fopen(path_val, "rb+");

        if (!fp) {
                perror("fopen failed");
                exit(EXIT_FAILURE);
        }

        FILE *fp2 = fopen(path_max_val, "rb");

        if (!fp2) {
                perror("fopen failed");
                exit(EXIT_FAILURE);
        }

        process_input(argv[1], brgt);
        long val = get_brightness(fp);
        long max_val = get_brightness(fp2);
        long min_val = 1; /* set to 1 for lcd-backlight */

        if (fclose(fp2)) {
                perror("fclose failed");
                exit(EXIT_FAILURE);
        }

        /* We have a relative value to set */
        if (brgt->sign) {
                brgt->brightness = val + brgt->brightness;
        }

        /* Check and set sensible bounds */
        if (brgt->brightness > max_val) {
                brgt->brightness = max_val;
        } else if (brgt->brightness < min_val) {
                brgt->brightness = min_val;
        }

        size_t write = set_brightness(fp, brgt->brightness);
        
        if (fclose(fp)) {
                perror("fclose failed");
                exit(EXIT_FAILURE);
        }

        free(brgt);

        exit(EXIT_SUCCESS);
}
Пример #4
0
Файл: lsc.c Проект: wcheswick/ex
void
kbd_hit(char key) {
	set_active();
	switch (key) {
	case 'd':
		dump_screen(0);
		break;
	case 'w':
	case 'W':
		save_image();
		break;
	case 'q':
	case 'Q':
	case 'x':
	case 'X':	/* exit the program */
		end_display();
		exit(0);
	case 'v':
		show_video_settings = !show_video_settings;
		refresh_screen = 1;
		break;
	case 'h':
		set_hue(get_hue() - 1);
		refresh_screen = 1;
		break;
	case 'H':
		set_hue(get_hue() + 1);
		refresh_screen = 1;
		break;
	case 's':
		set_saturation(get_saturation() - 1);
		refresh_screen = 1;
		break;
	case 'S':
		set_saturation(get_saturation() + 1);
		refresh_screen = 1;
		break;
	case 'b':
		set_brightness(get_brightness() - 1);
		refresh_screen = 1;
		break;
	case 'B':
		set_brightness(get_brightness() + 1);
		refresh_screen = 1;
		break;
	case 'c':
		set_contrast(get_contrast() - 1);
		refresh_screen = 1;
		break;
	case 'C':
		set_contrast(get_contrast() + 1);
		refresh_screen = 1;
		break;
	}
}
Пример #5
0
static int imanager_backlight_init(struct device *dev,
				   struct imanager_backlight_data *data)
{
	struct backlight_device *bd;
	struct backlight_properties props;

	memset(&props, 0, sizeof(props));
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38)
	props.type = BACKLIGHT_PLATFORM;
#endif
	props.max_brightness = BL_MAX_BRIGHTNESS;
	bd = backlight_device_register("imanager_backlight", dev, data,
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34)
					&imanager_bl_ops);
#else
					&imanager_bl_ops, &props);
#endif

	if (IS_ERR(bd)) {
		data->bl = NULL;
		dev_err(dev, "Unable to register backlight device\n");
		return PTR_ERR(bd);
	}

	data->bl = bd;

	bd->props.brightness = get_brightness(bd);
	bd->props.power = FB_BLANK_UNBLANK;
	backlight_update_status(bd);

	return 0;
}
Пример #6
0
END_TEST

START_TEST(test_ann)
{
    ck_assert( get_brightness(ann, 17.933842, 0.117967) == 0 );
    ck_assert( get_brightness(ann, 0.408988, 0.241489) == 1 );
    ck_assert( get_brightness(ann, 8.668308, 0.742252) == 2 );
    ck_assert( get_brightness(ann, 166.338012, 0.016205) == 0 );
    ck_assert( get_brightness(ann, 0.135857, 0.245151) == 1 );
    ck_assert( get_brightness(ann, -0.159653, 0.557191) == 2 );
}
Пример #7
0
static void 
timeout_handler(void)
{
#if DEV_BOARD
	leds_toggle(LEDS_GREEN);
#endif	


#if HAS_TEMP_SENSOR
	my_temp = get_temperature();
	read_temperature();
#endif

#if HAS_LIGHT_SENSOR
	my_light = get_brightness();
	light_sensor_start_conversion();
#endif

}
Пример #8
0
static PyObject *
flea_get_brightness(PyObject *self, PyObject *args)
{
	int handle = -1;
	fleaCamera* cam = NULL;
	float brightness;

	if (!PyArg_ParseTuple(args, "i", &handle))
		return NULL;

	if (handle >= 0 && handle < NUM_CAMERA_HANDLES && cameras[handle]) {
		cam = cameras[handle];
		brightness = get_brightness(cam);
	} else {
		PyErr_SetString(FleaError, "Invalid Handle");
		return NULL;
	}

	return Py_BuildValue("f", brightness);
}
Пример #9
0
static bright_adjust(int event_value, int delta)
{
	int new_value;

	if (max_brightness == -1) {
		max_brightness_init();
		if (max_brightness == -1)
			return;
	}

	if (event_value == 0) { // key release
		dev_file_close();
		return;
	}

	if (event_value == 1) { // new key press (not a repeat)
		// Make sure we fetch an up-to-date value in the next step.
		dev_file_close();
		current_value = -1;
	}

	if (current_value == -1) {
		current_value = get_brightness();
		if (current_value == -1)
			return;
	}

	new_value = current_value + delta;
	if (new_value < MIN_BRIGHTNESS)
		new_value = MIN_BRIGHTNESS;
	else if (new_value > max_brightness)
		new_value = max_brightness;

	if (new_value != current_value) {
		current_value = new_value;
		set_brightness(current_value);
	}
}
Пример #10
0
/*******************************************************************************************
    Video capture routines

 - set input
 - setup_pixelformat
 - set_geometry

 - set_brightness 
 - set_chroma
 - set_contrast
 - set_channelset
 - set_channel
 - set_capture_mode

*/
static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, 
                                unsigned short input, unsigned short norm, unsigned long freq)
{
    int dev_bktr = viddev->fd_bktr;
    struct sigaction act, old;
    //int dev_tunner = viddev->fd_tuner;
    /* to ensure that all device will be support the capture mode 
      _TODO_ : Autodected the best capture mode .
    */
    int dummy = 1;
//    int pixelformat = BSD_VIDFMT_I420;

    void *map;

    /* if we have choose the tuner is needed to setup the frequency */
    if ((viddev->tuner_device != NULL) && (input == IN_TV)) {
        if (!freq) {
            motion_log(LOG_ERR, 0, "%s: Not valid Frequency [%lu] for Source input [%i]",
                       __FUNCTION__, freq, input);
            return NULL;
        } else if (set_freq(viddev, freq) == -1) {
            motion_log(LOG_ERR, 0, "%s: Frequency [%lu] Source input [%i]", 
                       __FUNCTION__, freq, input);
            return NULL;
        }
    }
    
    /* FIXME if we set as input tuner , we need to set option for tuner not for bktr */

    if ((dummy = set_input(viddev, input)) == -1) {
        motion_log(LOG_ERR, 0, "%s: set input [%d]", __FUNCTION__, input);
        return NULL;
    }

    viddev->input = dummy;

    if ((dummy = set_input_format(viddev, norm)) == -1) {
        motion_log(LOG_ERR, 0, "%s: set input format [%d]", __FUNCTION__, norm);
        return NULL;
    }

    viddev->norm = dummy;

    if (set_geometry(viddev, width, height) == -1) {
        motion_log(LOG_ERR, 0, "%s: set geometry [%d]x[%d]", __FUNCTION__, width, height);
        return NULL;
    }
/*
    if (ioctl(dev_bktr, METEORSACTPIXFMT, &pixelformat) < 0) {
        motion_log(LOG_ERR, 1, "set encoding method BSD_VIDFMT_I420"); 
        return NULL;
    }


    NEEDED !? FIXME 

    if (setup_pixelformat(viddev) == -1)
        return NULL;
*/

    if (freq) {
        if (debug_level >= CAMERA_DEBUG)    
            motion_log(-1, 0, "%s: Frequency set (no implemented yet", __FUNCTION__);
    /*
     TODO missing implementation
        set_channelset(viddev);
        set_channel(viddev);
        if (set_freq (viddev, freq) == -1) {
            return NULL;
        }
    */
    }


    /* set capture mode and capture buffers */

    /* That is the buffer size for capture images ,
     so is dependent of color space of input format / FIXME */

    viddev->v4l_bufsize = (((width * height * 3 / 2)) * sizeof(unsigned char *));
    viddev->v4l_fmt = VIDEO_PALETTE_YUV420P;
    

    map = mmap((caddr_t)0, viddev->v4l_bufsize, PROT_READ|PROT_WRITE, MAP_SHARED, dev_bktr, (off_t)0);

    if (map == MAP_FAILED){
        motion_log(LOG_ERR, 1, "%s: mmap failed", __FUNCTION__);
        return NULL;
    }

    /* FIXME double buffer */ 
    if (0) {
        viddev->v4l_maxbuffer = 2;
        viddev->v4l_buffers[0] = map;
        viddev->v4l_buffers[1] = (unsigned char *)map + 0; /* 0 is not valid just a test */
        //viddev->v4l_buffers[1] = map+vid_buf.offsets[1];
    } else {
        viddev->v4l_buffers[0] = map;
        viddev->v4l_maxbuffer = 1;
    }

    viddev->v4l_curbuffer = 0;

    /* Clear the buffer */

    if (ioctl(dev_bktr, BT848SCBUF, &dummy) < 0) {
        motion_log(LOG_ERR, 1, "%s: BT848SCBUF", __FUNCTION__);
        return NULL;
    }

    /* signal handler to know when data is ready to be read() */
         
    memset(&act, 0, sizeof(act));
    sigemptyset(&act.sa_mask);
    act.sa_handler = catchsignal;
    sigaction(SIGUSR2, &act, &old);
     
    dummy = SIGUSR2;

    //viddev->capture_method = METEOR_CAP_CONTINOUS;
    //viddev->capture_method = METEOR_CAP_SINGLE;
    
    if ((viddev->capture_method == METEOR_CAP_CONTINOUS) && (ioctl(dev_bktr, METEORSSIGNAL, &dummy) < 0)) {
        motion_log(LOG_ERR, 1, "%s: METEORSSIGNAL", __FUNCTION__);
        motion_log(LOG_INFO, 0 , "%s: METEORSSIGNAL", __FUNCTION__);
        viddev->capture_method = METEOR_CAP_SINGLE;
        if (ioctl(dev_bktr, METEORCAPTUR, &viddev->capture_method) < 0) {
            motion_log(LOG_ERR, 1, "%s: METEORCAPTUR using single method "
                       "Error capturing", __FUNCTION__);
            motion_log(LOG_INFO, 0, "%s: METEORCAPTUR using single method "
                       "Error capturing", __FUNCTION__);
        }    
    } else {
        if (ioctl(dev_bktr, METEORCAPTUR, &viddev->capture_method) < 0) {
            viddev->capture_method = METEOR_CAP_SINGLE;
            if (ioctl(dev_bktr, METEORCAPTUR, &viddev->capture_method) < 0) {
                motion_log(LOG_ERR, 1, "%s: METEORCAPTUR using single method "
                           "Error capturing", __FUNCTION__);
                motion_log(LOG_INFO, 0, "%s: METEORCAPTUR using single method "
                           "Error capturing", __FUNCTION__);
            }    
        }    
    }            
        
    if (viddev->capture_method == METEOR_CAP_CONTINOUS)
        motion_log(LOG_INFO, 0, "%s: METEORCAPTUR METEOR_CAP_CONTINOUS", __FUNCTION__);    
    else        
        motion_log(LOG_INFO, 0, "%s: METEORCAPTUR METEOR_CAP_SINGLE", __FUNCTION__);
    
    // settle , sleep(1) replaced
    SLEEP(1, 0);

    /* FIXME*/
    switch (viddev->v4l_fmt) {
    case VIDEO_PALETTE_YUV420P:
        viddev->v4l_bufsize = (width * height * 3) / 2;
        break;
    case VIDEO_PALETTE_YUV422:
        viddev->v4l_bufsize = (width * height * 2);
        break;
    case VIDEO_PALETTE_RGB24:
        viddev->v4l_bufsize = (width * height * 3);
        break;
    case VIDEO_PALETTE_GREY:
        viddev->v4l_bufsize = width * height;
        break;
    }
    
    motion_log(LOG_INFO, 0, "HUE [%d]", get_hue(dev_bktr, &dummy));
    motion_log(LOG_INFO, 0, "SATURATION [%d]", get_saturation(dev_bktr, &dummy));
    motion_log(LOG_INFO, 0, "BRIGHTNESS [%d]", get_brightness(dev_bktr, &dummy));
    motion_log(LOG_INFO, 0, "CONTRAST [%d]", get_contrast(dev_bktr, &dummy));
    
    return map;
}