00001 #include "Flash.h"
00002 #include "V4L2Sensor.h"
00003 #include <linux/videodev2.h>
00004 #include <sys/ioctl.h>
00005
00006 namespace FCam {
00007 namespace N900 {
00008
00009 Flash::Flash() : flashHistory(512) {
00010 }
00011
00012 Flash::~Flash() {}
00013
00014 void Flash::setBrightness(float b) {
00015 if (b < minBrightness()) b = minBrightness();
00016 if (b > maxBrightness()) b = maxBrightness();
00017 struct v4l2_control ctrl;
00018 ctrl.id = V4L2_CID_FLASH_INTENSITY;
00019 ctrl.value = b;
00020 int fd = V4L2Sensor::instance("/dev/video0")->getFD();
00021 if (fd < 0) {
00022 V4L2Sensor::instance("/dev/video0")->open();
00023 fd = V4L2Sensor::instance("/dev/video0")->getFD();
00024 }
00025 if (ioctl(fd, VIDIOC_S_CTRL, &ctrl) < 0) {
00026 perror("VIDIOC_S_CTRL");
00027 return;
00028 }
00029 }
00030
00031
00032 void Flash::setDuration(int d) {
00033 if (d < minDuration()) d = minDuration();
00034 if (d > maxDuration()) d = maxDuration();
00035 struct v4l2_control ctrl;
00036 ctrl.id = V4L2_CID_FLASH_TIMEOUT;
00037 ctrl.value = d;
00038 int fd = V4L2Sensor::instance("/dev/video0")->getFD();
00039 if (fd < 0) {
00040 V4L2Sensor::instance("/dev/video0")->open();
00041 fd = V4L2Sensor::instance("/dev/video0")->getFD();
00042 }
00043 if (ioctl(fd, VIDIOC_S_CTRL, &ctrl) < 0) {
00044 perror("VIDIOC_S_CTRL");
00045 return;
00046 }
00047 }
00048
00049 void Flash::fire(float brightness, int duration) {
00050 setBrightness(brightness);
00051 setDuration(duration);
00052
00053 struct v4l2_control ctrl;
00054 ctrl.id = V4L2_CID_FLASH_STROBE;
00055 ctrl.value = 0;
00056 int fd = V4L2Sensor::instance("/dev/video0")->getFD();
00057 if (fd < 0) {
00058 V4L2Sensor::instance("/dev/video0")->open();
00059 fd = V4L2Sensor::instance("/dev/video0")->getFD();
00060 }
00061 if (ioctl(fd, VIDIOC_S_CTRL, &ctrl) < 0) {
00062 perror("VIDIOC_S_CTRL");
00063 }
00064 }
00065
00066
00067 }
00068 }