?? pwc-ctrl.c
字號:
/* SATURATION *//* return a value between [-100 , 100] */int pwc_get_saturation(struct pwc_device *pdev, int *value){ char buf; int ret, saturation_register; if (pdev->type < 675) return -EINVAL; if (pdev->type < 730) saturation_register = SATURATION_MODE_FORMATTER2; else saturation_register = SATURATION_MODE_FORMATTER1; ret = RecvControlMsg(GET_CHROM_CTL, saturation_register, 1); if (ret < 0) return ret; *value = (signed)buf; return 0;}/* @param value saturation color between [-100 , 100] */int pwc_set_saturation(struct pwc_device *pdev, int value){ char buf; int saturation_register; if (pdev->type < 675) return -EINVAL; if (value < -100) value = -100; if (value > 100) value = 100; if (pdev->type < 730) saturation_register = SATURATION_MODE_FORMATTER2; else saturation_register = SATURATION_MODE_FORMATTER1; return SendControlMsg(SET_CHROM_CTL, saturation_register, 1);}/* AGC */int pwc_set_agc(struct pwc_device *pdev, int mode, int value){ char buf; int ret; if (mode) buf = 0x0; /* auto */ else buf = 0xff; /* fixed */ ret = SendControlMsg(SET_LUM_CTL, AGC_MODE_FORMATTER, 1); if (!mode && ret >= 0) { if (value < 0) value = 0; if (value > 0xffff) value = 0xffff; buf = (value >> 10) & 0x3F; ret = SendControlMsg(SET_LUM_CTL, PRESET_AGC_FORMATTER, 1); } if (ret < 0) return ret; return 0;}int pwc_get_agc(struct pwc_device *pdev, int *value){ unsigned char buf; int ret; ret = RecvControlMsg(GET_LUM_CTL, AGC_MODE_FORMATTER, 1); if (ret < 0) return ret; if (buf != 0) { /* fixed */ ret = RecvControlMsg(GET_LUM_CTL, PRESET_AGC_FORMATTER, 1); if (ret < 0) return ret; if (buf > 0x3F) buf = 0x3F; *value = (buf << 10); } else { /* auto */ ret = RecvControlMsg(GET_STATUS_CTL, READ_AGC_FORMATTER, 1); if (ret < 0) return ret; /* Gah... this value ranges from 0x00 ... 0x9F */ if (buf > 0x9F) buf = 0x9F; *value = -(48 + buf * 409); } return 0;}int pwc_set_shutter_speed(struct pwc_device *pdev, int mode, int value){ char buf[2]; int speed, ret; if (mode) buf[0] = 0x0; /* auto */ else buf[0] = 0xff; /* fixed */ ret = SendControlMsg(SET_LUM_CTL, SHUTTER_MODE_FORMATTER, 1); if (!mode && ret >= 0) { if (value < 0) value = 0; if (value > 0xffff) value = 0xffff; if (DEVICE_USE_CODEC2(pdev->type)) { /* speed ranges from 0x0 to 0x290 (656) */ speed = (value / 100); buf[1] = speed >> 8; buf[0] = speed & 0xff; } else if (DEVICE_USE_CODEC3(pdev->type)) { /* speed seems to range from 0x0 to 0xff */ buf[1] = 0; buf[0] = value >> 8; } ret = SendControlMsg(SET_LUM_CTL, PRESET_SHUTTER_FORMATTER, 2); } return ret;} /* This function is not exported to v4l1, so output values between 0 -> 256 */int pwc_get_shutter_speed(struct pwc_device *pdev, int *value){ unsigned char buf[2]; int ret; ret = RecvControlMsg(GET_STATUS_CTL, READ_SHUTTER_FORMATTER, 2); if (ret < 0) return ret; *value = buf[0] + (buf[1] << 8); if (DEVICE_USE_CODEC2(pdev->type)) { /* speed ranges from 0x0 to 0x290 (656) */ *value *= 256/656; } else if (DEVICE_USE_CODEC3(pdev->type)) { /* speed seems to range from 0x0 to 0xff */ } return 0;}/* POWER */int pwc_camera_power(struct pwc_device *pdev, int power){ char buf; if (pdev->type < 675 || (pdev->type < 730 && pdev->release < 6)) return 0; /* Not supported by Nala or Timon < release 6 */ if (power) buf = 0x00; /* active */ else buf = 0xFF; /* power save */ return SendControlMsg(SET_STATUS_CTL, SET_POWER_SAVE_MODE_FORMATTER, 1);}/* private calls */int pwc_restore_user(struct pwc_device *pdev){ char buf; /* dummy */ return SendControlMsg(SET_STATUS_CTL, RESTORE_USER_DEFAULTS_FORMATTER, 0);}int pwc_save_user(struct pwc_device *pdev){ char buf; /* dummy */ return SendControlMsg(SET_STATUS_CTL, SAVE_USER_DEFAULTS_FORMATTER, 0);}int pwc_restore_factory(struct pwc_device *pdev){ char buf; /* dummy */ return SendControlMsg(SET_STATUS_CTL, RESTORE_FACTORY_DEFAULTS_FORMATTER, 0);} /* ************************************************* */ /* Patch by Alvarado: (not in the original version */ /* * the camera recognizes modes from 0 to 4: * * 00: indoor (incandescant lighting) * 01: outdoor (sunlight) * 02: fluorescent lighting * 03: manual * 04: auto */ int pwc_set_awb(struct pwc_device *pdev, int mode){ char buf; int ret; if (mode < 0) mode = 0; if (mode > 4) mode = 4; buf = mode & 0x07; /* just the lowest three bits */ ret = SendControlMsg(SET_CHROM_CTL, WB_MODE_FORMATTER, 1); if (ret < 0) return ret; return 0;}int pwc_get_awb(struct pwc_device *pdev){ unsigned char buf; int ret; ret = RecvControlMsg(GET_CHROM_CTL, WB_MODE_FORMATTER, 1); if (ret < 0) return ret; return buf;}int pwc_set_red_gain(struct pwc_device *pdev, int value){ unsigned char buf; if (value < 0) value = 0; if (value > 0xffff) value = 0xffff; /* only the msb is considered */ buf = value >> 8; return SendControlMsg(SET_CHROM_CTL, PRESET_MANUAL_RED_GAIN_FORMATTER, 1);}int pwc_get_red_gain(struct pwc_device *pdev, int *value){ unsigned char buf; int ret; ret = RecvControlMsg(GET_CHROM_CTL, PRESET_MANUAL_RED_GAIN_FORMATTER, 1); if (ret < 0) return ret; *value = buf << 8; return 0;}int pwc_set_blue_gain(struct pwc_device *pdev, int value){ unsigned char buf; if (value < 0) value = 0; if (value > 0xffff) value = 0xffff; /* only the msb is considered */ buf = value >> 8; return SendControlMsg(SET_CHROM_CTL, PRESET_MANUAL_BLUE_GAIN_FORMATTER, 1);}int pwc_get_blue_gain(struct pwc_device *pdev, int *value){ unsigned char buf; int ret; ret = RecvControlMsg(GET_CHROM_CTL, PRESET_MANUAL_BLUE_GAIN_FORMATTER, 1); if (ret < 0) return ret; *value = buf << 8; return 0;}/* The following two functions are different, since they only read the internal red/blue gains, which may be different from the manual gains set or read above. */ static int pwc_read_red_gain(struct pwc_device *pdev, int *value){ unsigned char buf; int ret; ret = RecvControlMsg(GET_STATUS_CTL, READ_RED_GAIN_FORMATTER, 1); if (ret < 0) return ret; *value = buf << 8; return 0;}static int pwc_read_blue_gain(struct pwc_device *pdev, int *value){ unsigned char buf; int ret; ret = RecvControlMsg(GET_STATUS_CTL, READ_BLUE_GAIN_FORMATTER, 1); if (ret < 0) return ret; *value = buf << 8; return 0;}static int pwc_set_wb_speed(struct pwc_device *pdev, int speed){ unsigned char buf; /* useful range is 0x01..0x20 */ buf = speed / 0x7f0; return SendControlMsg(SET_CHROM_CTL, AWB_CONTROL_SPEED_FORMATTER, 1);}static int pwc_get_wb_speed(struct pwc_device *pdev, int *value){ unsigned char buf; int ret; ret = RecvControlMsg(GET_CHROM_CTL, AWB_CONTROL_SPEED_FORMATTER, 1); if (ret < 0) return ret; *value = buf * 0x7f0; return 0;}static int pwc_set_wb_delay(struct pwc_device *pdev, int delay){ unsigned char buf; /* useful range is 0x01..0x3F */ buf = (delay >> 10); return SendControlMsg(SET_CHROM_CTL, AWB_CONTROL_DELAY_FORMATTER, 1);}static int pwc_get_wb_delay(struct pwc_device *pdev, int *value){ unsigned char buf; int ret; ret = RecvControlMsg(GET_CHROM_CTL, AWB_CONTROL_DELAY_FORMATTER, 1); if (ret < 0) return ret; *value = buf << 10; return 0;}int pwc_set_leds(struct pwc_device *pdev, int on_value, int off_value){ unsigned char buf[2]; if (pdev->type < 730) return 0; on_value /= 100; off_value /= 100; if (on_value < 0) on_value = 0; if (on_value > 0xff) on_value = 0xff; if (off_value < 0) off_value = 0; if (off_value > 0xff) off_value = 0xff; buf[0] = on_value; buf[1] = off_value; return SendControlMsg(SET_STATUS_CTL, LED_FORMATTER, 2);}int pwc_get_leds(struct pwc_device *pdev, int *on_value, int *off_value){ unsigned char buf[2]; int ret; if (pdev->type < 730) { *on_value = -1; *off_value = -1; return 0; } ret = RecvControlMsg(GET_STATUS_CTL, LED_FORMATTER, 2); if (ret < 0) return ret; *on_value = buf[0] * 100; *off_value = buf[1] * 100; return 0;}int pwc_set_contour(struct pwc_device *pdev, int contour){ unsigned char buf; int ret; if (contour < 0) buf = 0xff; /* auto contour on */ else buf = 0x0; /* auto contour off */ ret = SendControlMsg(SET_LUM_CTL, AUTO_CONTOUR_FORMATTER, 1); if (ret < 0) return ret; if (contour < 0) return 0; if (contour > 0xffff) contour = 0xffff; buf = (contour >> 10); /* contour preset is [0..3f] */ ret = SendControlMsg(SET_LUM_CTL, PRESET_CONTOUR_FORMATTER, 1); if (ret < 0) return ret; return 0;}int pwc_get_contour(struct pwc_device *pdev, int *contour){ unsigned char buf; int ret; ret = RecvControlMsg(GET_LUM_CTL, AUTO_CONTOUR_FORMATTER, 1); if (ret < 0) return ret; if (buf == 0) { /* auto mode off, query current preset value */ ret = RecvControlMsg(GET_LUM_CTL, PRESET_CONTOUR_FORMATTER, 1); if (ret < 0) return ret; *contour = buf << 10; } else *contour = -1; return 0;}int pwc_set_backlight(struct pwc_device *pdev, int backlight){ unsigned char buf; if (backlight) buf = 0xff; else buf = 0x0; return SendControlMsg(SET_LUM_CTL, BACK_LIGHT_COMPENSATION_FORMATTER, 1);}int pwc_get_backlight(struct pwc_device *pdev, int *backlight){ int ret; unsigned char buf; ret = RecvControlMsg(GET_LUM_CTL, BACK_LIGHT_COMPENSATION_FORMATTER, 1); if (ret < 0) return ret; *backlight = !!buf; return 0;}int pwc_set_colour_mode(struct pwc_device *pdev, int colour){ unsigned char buf; if (colour) buf = 0xff; else buf = 0x0; return SendControlMsg(SET_CHROM_CTL, COLOUR_MODE_FORMATTER, 1);}int pwc_get_colour_mode(struct pwc_device *pdev, int *colour){ int ret; unsigned char buf; ret = RecvControlMsg(GET_CHROM_CTL, COLOUR_MODE_FORMATTER, 1); if (ret < 0) return ret; *colour = !!buf; return 0;}int pwc_set_flicker(struct pwc_device *pdev, int flicker){ unsigned char buf; if (flicker) buf = 0xff; else buf = 0x0; return SendControlMsg(SET_LUM_CTL, FLICKERLESS_MODE_FORMATTER, 1);}int pwc_get_flicker(struct pwc_device *pdev, int *flicker){ int ret; unsigned char buf; ret = RecvControlMsg(GET_LUM_CTL, FLICKERLESS_MODE_FORMATTER, 1); if (ret < 0) return ret; *flicker = !!buf; return 0;}int pwc_set_dynamic_noise(struct pwc_device *pdev, int noise){ unsigned char buf; if (noise < 0) noise = 0; if (noise > 3) noise = 3; buf = noise; return SendControlMsg(SET_LUM_CTL, DYNAMIC_NOISE_CONTROL_FORMATTER, 1);}int pwc_get_dynamic_noise(struct pwc_device *pdev, int *noise){ int ret; unsigned char buf; ret = RecvControlMsg(GET_LUM_CTL, DYNAMIC_NOISE_CONTROL_FORMATTER, 1); if (ret < 0) return ret; *noise = buf; return 0;}static int _pwc_mpt_reset(struct pwc_device *pdev, int flags){ unsigned char buf;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -