00001 #include "dc1394dialog.h"
00002 #include "ui_dc1394dialog.h"
00003 #include <QDebug>
00004 #include <iostream>
00005
00006 Dc1394Dialog::Dc1394Dialog(dc1394camera_t *camera, QWidget *parent)
00007 : QMainWindow(parent), ui(new Ui::Dc1394Dialog), camera(camera)
00008 {
00009 ui->setupUi(this);
00010
00011 bool initialized = initialize();
00012 qDebug() << "Initialize returned: " << initialized;
00013 }
00014
00015 Dc1394Dialog::~Dc1394Dialog()
00016 {
00017 delete ui;
00018 if (camera) dc1394_camera_free(camera);
00019 }
00020
00021 #define CHECK_ERROR(err, clean, msg) if (err!=DC1394_SUCCESS) { std::cerr << msg << std::endl; clean ; return false; }
00022 #define CHECK_ERROR(err, msg) if ((err)!=DC1394_SUCCESS) { std::cerr << msg << std::endl; }
00023 #define CHECK_ERROR(err) if ((err)!=DC1394_SUCCESS) { std::cerr << #err << std::endl; }
00024 bool Dc1394Dialog::initialize()
00025 {
00026 if (!camera) {
00027 dc1394_t *d = dc1394_new ();
00028 if (!d)
00029 return false;
00030 dc1394camera_list_t * list;
00031 dc1394error_t err=dc1394_camera_enumerate (d, &list);
00032
00033 if (list->num == 0) {
00034 dc1394_free (d);
00035 return false;
00036 }
00037
00038 camera = dc1394_camera_new (d, list->ids[0].guid);
00039 dc1394_camera_free_list (list);
00040 if (!camera) {
00041 dc1394_log_error("Failed to initialize camera");
00042 dc1394_free (d);
00043 return false;
00044 }
00045 }
00046
00047 dc1394_feature_get_all(camera, &features);
00048 dc1394_feature_print_all(&features, stderr);
00049
00050 setupFeature("Gain", DC1394_FEATURE_GAIN, ui->gainSpin);
00051 setupFeature("Exposure", DC1394_FEATURE_EXPOSURE, ui->exposureSpin);
00052 setupFeature("Shutter", DC1394_FEATURE_SHUTTER, ui->shutterSpin);
00053 setupFeature("Brightness", DC1394_FEATURE_BRIGHTNESS, ui->brightnessSpin);
00054
00055 timer = startTimer(2000);
00056 timerEvent(0);
00057 return true;
00058 }
00059
00060 void Dc1394Dialog::setupFeature(QString name, dc1394feature_t feature, QDoubleSpinBox *spin)
00061 {
00062 uint32_t vmin,vmax;
00063 dc1394_feature_get_boundaries(camera, feature, &vmin, &vmax);
00064 spin->setMaximum(vmax);
00065 spin->setMinimum(vmin);
00066
00067 dc1394switch_t power;
00068 dc1394_feature_get_power(camera, feature, &power);
00069 qDebug() << name << ", power: " << (power == DC1394_ON ? "on" : "off");
00070 }
00071
00072 void Dc1394Dialog::timerEvent( QTimerEvent *)
00073 {
00074 updateFeature(DC1394_FEATURE_GAIN, ui->gainSpin, ui->manualGain);
00075 updateFeature(DC1394_FEATURE_EXPOSURE, ui->exposureSpin, ui->manualExposure);
00076 updateFeature(DC1394_FEATURE_SHUTTER, ui->shutterSpin, ui->manualShutter);
00077 updateFeature(DC1394_FEATURE_BRIGHTNESS, ui->brightnessSpin, ui->manualBrightness);
00078
00079 uint32_t u_b_val, u_r_val;
00080 dc1394_feature_whitebalance_get_value(camera, &u_b_val, &u_r_val);
00081 ui->whiteBalSliderBlue->setValue(u_b_val);
00082 ui->whiteBalSliderRed->setValue(u_r_val);
00083
00084 }
00085
00086 void Dc1394Dialog::updateFeature(dc1394feature_t feature, QDoubleSpinBox *spin, QCheckBox *checkbox)
00087 {
00088 uint32_t val;
00089 CHECK_ERROR(dc1394_feature_get_value(camera, feature, &val));
00090 spin->setValue(val);
00091 dc1394feature_mode_t mode;
00092 CHECK_ERROR(dc1394_feature_get_mode(camera, feature, &mode));
00093 checkbox->setCheckState(mode == DC1394_FEATURE_MODE_AUTO ? Qt::Unchecked :Qt::Checked);
00094 }
00095
00096 void Dc1394Dialog::on_autoGain_clicked()
00097 {
00098 CHECK_ERROR(dc1394_feature_set_mode(camera, DC1394_FEATURE_GAIN, DC1394_FEATURE_MODE_ONE_PUSH_AUTO));
00099
00100 }
00101
00102
00103 void Dc1394Dialog::on_manualGain_toggled(bool checked)
00104 {
00105 qDebug() << "gain mode:" << (checked ? "manual" : "auto");
00106 CHECK_ERROR(dc1394_feature_set_mode(camera, DC1394_FEATURE_GAIN,
00107 (checked ? DC1394_FEATURE_MODE_MANUAL : DC1394_FEATURE_MODE_AUTO)));
00108
00109 }
00110
00111 void Dc1394Dialog::on_gainSpin_valueChanged(int gain)
00112 {
00113 CHECK_ERROR(dc1394_feature_set_value(camera, DC1394_FEATURE_GAIN, gain));
00114
00115 }
00116
00117
00118 void Dc1394Dialog::on_exposureSpin_valueChanged(double val)
00119 {
00120 CHECK_ERROR(dc1394_feature_set_value(camera, DC1394_FEATURE_EXPOSURE, val));
00121
00122 }
00123
00124 void Dc1394Dialog::on_autoExposure_clicked()
00125 {
00126 CHECK_ERROR(dc1394_feature_set_mode(camera, DC1394_FEATURE_EXPOSURE, DC1394_FEATURE_MODE_ONE_PUSH_AUTO));
00127
00128 }
00129
00130 void Dc1394Dialog::on_manualExposure_toggled(bool checked)
00131 {
00132 CHECK_ERROR(dc1394_feature_set_mode(camera, DC1394_FEATURE_EXPOSURE,
00133 (checked ? DC1394_FEATURE_MODE_MANUAL : DC1394_FEATURE_MODE_AUTO)));
00134
00135 }
00136
00137 void Dc1394Dialog::on_manualWhiteBal_toggled(bool checked)
00138 {
00139 CHECK_ERROR(dc1394_feature_set_mode(camera, DC1394_FEATURE_WHITE_BALANCE,
00140 (checked ? DC1394_FEATURE_MODE_MANUAL : DC1394_FEATURE_MODE_AUTO)));
00141
00142 }
00143
00144
00145 void Dc1394Dialog::on_whiteBalSliderBlue_sliderMoved(int position)
00146 {
00147 dc1394_feature_whitebalance_set_value(camera, position, ui->whiteBalSliderRed->value());
00148 }
00149
00150 void Dc1394Dialog::on_whiteBalSliderRed_sliderMoved(int position)
00151 {
00152 dc1394_feature_whitebalance_set_value(camera, ui->whiteBalSliderBlue->value(), position);
00153 }
00154
00155 void Dc1394Dialog::on_manualShutter_toggled(bool checked)
00156 {
00157 CHECK_ERROR(dc1394_feature_set_mode(camera, DC1394_FEATURE_SHUTTER,
00158 (checked ? DC1394_FEATURE_MODE_MANUAL : DC1394_FEATURE_MODE_AUTO)));
00159
00160 }
00161
00162 void Dc1394Dialog::on_shutterSpin_valueChanged(double val)
00163 {
00164 CHECK_ERROR(dc1394_feature_set_value(camera, DC1394_FEATURE_SHUTTER, val));
00165
00166 }
00167
00168 void Dc1394Dialog::on_autoShutter_clicked()
00169 {
00170 CHECK_ERROR(dc1394_feature_set_mode(camera, DC1394_FEATURE_SHUTTER, DC1394_FEATURE_MODE_ONE_PUSH_AUTO));
00171
00172 }
00173
00174 void Dc1394Dialog::on_manualBrightness_toggled(bool checked)
00175 {
00176 CHECK_ERROR(dc1394_feature_set_mode(camera, DC1394_FEATURE_BRIGHTNESS,
00177 (checked ? DC1394_FEATURE_MODE_MANUAL : DC1394_FEATURE_MODE_AUTO)));
00178 }