00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "v4lphilips.h"
00024 #include "webcam/pwc-ioctl.h"
00025
00026 V4L_Philips::V4L_Philips() : V4L_Driver()
00027 {
00028
00029 }
00030
00031 V4L_Philips::~V4L_Philips()
00032 {
00033
00034 }
00035
00036 void V4L_Philips::initCamBase()
00037 {
00038 #ifdef HAVE_LINUX_VIDEODEV2_H
00039 v4l_base = new V4L2_Base();
00040 #else
00041 v4l_pwc = new V4L1_PWC();
00042 v4l_base = (V4L1_Base *) v4l_pwc;
00043 #endif
00044 }
00045
00046 void V4L_Philips::initProperties(const char *dev)
00047 {
00048
00049
00050 V4L_Driver::initProperties(dev);
00051
00052 fillSwitch(&BackLightS[0], "ON", "", ISS_OFF);
00053 fillSwitch(&BackLightS[1], "OFF", "", ISS_ON);
00054 fillSwitchVector(&BackLightSP, BackLightS, NARRAY(BackLightS), dev, "Back Light", "", IMAGE_CONTROL, IP_RW, ISR_1OFMANY, 0 , IPS_IDLE);
00055
00056 fillSwitch(&AntiFlickerS[0], "ON", "", ISS_OFF);
00057 fillSwitch(&AntiFlickerS[1], "OFF", "", ISS_ON);
00058 fillSwitchVector(&AntiFlickerSP, AntiFlickerS, NARRAY(AntiFlickerS), dev, "Anti Flicker", "", IMAGE_CONTROL, IP_RW, ISR_1OFMANY, 0 , IPS_IDLE);
00059
00060 fillSwitch(&NoiseReductionS[0], "None", "", ISS_ON);
00061 fillSwitch(&NoiseReductionS[1], "Low", "", ISS_OFF);
00062 fillSwitch(&NoiseReductionS[2], "Medium", "", ISS_OFF);
00063 fillSwitch(&NoiseReductionS[3], "High", "", ISS_OFF);
00064 fillSwitchVector(&NoiseReductionSP, NoiseReductionS, NARRAY(NoiseReductionS), dev, "Noise Reduction", "", IMAGE_CONTROL, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
00065
00066 fillSwitch(&CamSettingS[0], "Save", "", ISS_OFF);
00067 fillSwitch(&CamSettingS[1], "Restore", "", ISS_OFF);
00068 fillSwitch(&CamSettingS[2], "Factory", "", ISS_OFF);
00069 fillSwitchVector(&CamSettingSP, CamSettingS, NARRAY(CamSettingS), dev, "Settings", "", IMAGE_CONTROL, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
00070
00071 fillSwitch(&WhiteBalanceModeS[0], "Auto" , "", ISS_ON);
00072 fillSwitch(&WhiteBalanceModeS[1], "Manual" , "", ISS_OFF);
00073 fillSwitch(&WhiteBalanceModeS[2], "Indoor" , "", ISS_OFF);
00074 fillSwitch(&WhiteBalanceModeS[3], "Outdoor" , "", ISS_OFF);
00075 fillSwitch(&WhiteBalanceModeS[4], "Fluorescent" , "", ISS_OFF);
00076
00077 fillSwitchVector(&WhiteBalanceModeSP, WhiteBalanceModeS, NARRAY(WhiteBalanceModeS), dev, "White Balance Mode", "", IMAGE_CONTROL, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
00078
00079 fillNumber(&WhiteBalanceN[0], "Manual Red", "", "%0.f", 0., 256., 1., 0.);
00080 fillNumber(&WhiteBalanceN[1], "Manual Blue", "", "%0.f", 0., 256., 1., 0.);
00081 fillNumberVector(&WhiteBalanceNP, WhiteBalanceN, NARRAY(WhiteBalanceN), dev, "White Balance", "", IMAGE_CONTROL, IP_RW, 60, IPS_IDLE);
00082
00083 fillNumber(&ShutterSpeedN[0], "Speed", "", "%0.f", 0., 65535., 100., 0.);
00084 fillNumberVector(&ShutterSpeedNP, ShutterSpeedN, NARRAY(ShutterSpeedN), dev, "Shutter Speed", "", COMM_GROUP, IP_RW, 60, IPS_IDLE);
00085
00086 }
00087
00088 void V4L_Philips::ISGetProperties (const char *dev)
00089 {
00090
00091 if (dev && strcmp (device_name, dev))
00092 return;
00093
00094 #ifdef HAVE_LINUX_VIDEODEV2_H
00095 V4L_Driver::ISGetProperties(dev);
00096 return;
00097 #endif
00098
00099
00100 IDDefSwitch(&PowerSP, NULL);
00101 IDDefText(&PortTP, NULL);
00102 IDDefText(&camNameTP, NULL);
00103 IDDefSwitch(&StreamSP, NULL);
00104 IDDefNumber(&FrameRateNP, NULL);
00105 IDDefNumber(&ExposeTimeNP, NULL);
00106 IDDefNumber(&ShutterSpeedNP, NULL);
00107 IDDefBLOB(&imageBP, NULL);
00108
00109
00110 IDDefSwitch(&CompressSP, NULL);
00111 IDDefSwitch(&ImageTypeSP, NULL);
00112 IDDefNumber(&FrameNP, NULL);
00113 IDDefNumber(&ImageAdjustNP, NULL);
00114
00115
00116 IDDefSwitch(&WhiteBalanceModeSP, NULL);
00117 IDDefNumber(&WhiteBalanceNP, NULL);
00118 IDDefSwitch(&BackLightSP, NULL);
00119 IDDefSwitch(&AntiFlickerSP, NULL);
00120 IDDefSwitch(&NoiseReductionSP, NULL);
00121 IDDefSwitch(&CamSettingSP, NULL);
00122
00123 }
00124
00125 void V4L_Philips::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
00126 {
00127 char errmsg[ERRMSG_SIZE];
00128 int index=0;
00129
00130
00131 if (dev && strcmp (device_name, dev))
00132 return;
00133
00134 #ifndef HAVE_LINUX_VIDEODEV2_H
00135
00136 if (!strcmp (AntiFlickerSP.name, name))
00137 {
00138 if (checkPowerS(&AntiFlickerSP))
00139 return;
00140
00141 AntiFlickerSP.s = IPS_IDLE;
00142
00143 IUResetSwitches(&AntiFlickerSP);
00144 IUUpdateSwitches(&AntiFlickerSP, states, names, n);
00145
00146 if (AntiFlickerS[0].s == ISS_ON)
00147 {
00148 if (v4l_pwc->setFlicker(true, errmsg) < 0)
00149 {
00150 AntiFlickerS[0].s = ISS_OFF;
00151 AntiFlickerS[1].s = ISS_ON;
00152 IDSetSwitch(&AntiFlickerSP, "%s", errmsg);
00153 return;
00154 }
00155
00156 AntiFlickerSP.s = IPS_OK;
00157 IDSetSwitch(&AntiFlickerSP, NULL);
00158 }
00159 else
00160 {
00161 if (v4l_pwc->setFlicker(false, errmsg) < 0)
00162 {
00163 AntiFlickerS[0].s = ISS_ON;
00164 AntiFlickerS[1].s = ISS_OFF;
00165 IDSetSwitch(&AntiFlickerSP, "%s", errmsg);
00166 return;
00167 }
00168
00169 IDSetSwitch(&AntiFlickerSP, NULL);
00170 }
00171
00172 return;
00173 }
00174
00175
00176 if (!strcmp (BackLightSP.name, name))
00177 {
00178 if (checkPowerS(&BackLightSP))
00179 return;
00180
00181 BackLightSP.s = IPS_IDLE;
00182
00183 IUResetSwitches(&BackLightSP);
00184 IUUpdateSwitches(&BackLightSP, states, names, n);
00185
00186 if (BackLightS[0].s == ISS_ON)
00187 {
00188 if (v4l_pwc->setBackLight(true, errmsg) < 0)
00189 {
00190 BackLightS[0].s = ISS_OFF;
00191 BackLightS[1].s = ISS_ON;
00192 IDSetSwitch(&BackLightSP, "%s", errmsg);
00193 return;
00194 }
00195
00196 BackLightSP.s = IPS_OK;
00197 IDSetSwitch(&BackLightSP, NULL);
00198 }
00199 else
00200 {
00201 if (v4l_pwc->setBackLight(false, errmsg) < 0)
00202 {
00203 BackLightS[0].s = ISS_ON;
00204 BackLightS[1].s = ISS_OFF;
00205 IDSetSwitch(&BackLightSP, "%s", errmsg);
00206 return;
00207 }
00208
00209 IDSetSwitch(&BackLightSP, NULL);
00210 }
00211
00212 return;
00213 }
00214
00215
00216 if (!strcmp (NoiseReductionSP.name, name))
00217 {
00218 if (checkPowerS(&NoiseReductionSP))
00219 return;
00220
00221 NoiseReductionSP.s = IPS_IDLE;
00222
00223 IUResetSwitches(&NoiseReductionSP);
00224 IUUpdateSwitches(&NoiseReductionSP, states, names, n);
00225
00226 for (int i=0; i < 4; i++)
00227 if (NoiseReductionS[i].s == ISS_ON)
00228 {
00229 index = i;
00230 break;
00231 }
00232
00233 if (v4l_pwc->setNoiseRemoval(index, errmsg) < 0)
00234 {
00235 IUResetSwitches(&NoiseReductionSP);
00236 NoiseReductionS[0].s = ISS_ON;
00237 IDSetSwitch(&NoiseReductionSP, "%s", errmsg);
00238 return;
00239 }
00240
00241 NoiseReductionSP.s = IPS_OK;
00242
00243 IDSetSwitch(&NoiseReductionSP, NULL);
00244 return;
00245 }
00246
00247
00248 if (!strcmp (WhiteBalanceModeSP.name, name))
00249 {
00250 if (checkPowerS(&WhiteBalanceModeSP))
00251 return;
00252
00253 WhiteBalanceModeSP.s = IPS_IDLE;
00254
00255 IUResetSwitches(&WhiteBalanceModeSP);
00256 IUUpdateSwitches(&WhiteBalanceModeSP, states, names, n);
00257
00258 for (int i=0; i < 5; i++)
00259 if (WhiteBalanceModeS[i].s == ISS_ON)
00260 {
00261 index = i;
00262 break;
00263 }
00264
00265 switch (index)
00266 {
00267
00268 case 0:
00269 if (v4l_pwc->setWhiteBalanceMode(PWC_WB_AUTO, errmsg) < 0)
00270 {
00271 IUResetSwitches(&WhiteBalanceModeSP),
00272 WhiteBalanceModeS[0].s = ISS_ON;
00273 IDSetSwitch(&WhiteBalanceModeSP, "%s", errmsg);
00274 return;
00275 }
00276 break;
00277
00278
00279 case 1:
00280 if (v4l_pwc->setWhiteBalanceMode(PWC_WB_MANUAL, errmsg) < 0)
00281 {
00282 IUResetSwitches(&WhiteBalanceModeSP),
00283 WhiteBalanceModeS[0].s = ISS_ON;
00284 IDSetSwitch(&WhiteBalanceModeSP, "%s", errmsg);
00285 return;
00286 }
00287 break;
00288
00289
00290 case 2:
00291 if (v4l_pwc->setWhiteBalanceMode(PWC_WB_INDOOR, errmsg) < 0)
00292 {
00293 IUResetSwitches(&WhiteBalanceModeSP),
00294 WhiteBalanceModeS[0].s = ISS_ON;
00295 IDSetSwitch(&WhiteBalanceModeSP, "%s", errmsg);
00296 return;
00297 }
00298 break;
00299
00300
00301 case 3:
00302 if (v4l_pwc->setWhiteBalanceMode(PWC_WB_OUTDOOR, errmsg) < 0)
00303 {
00304 IUResetSwitches(&WhiteBalanceModeSP),
00305 WhiteBalanceModeS[0].s = ISS_ON;
00306 IDSetSwitch(&WhiteBalanceModeSP, "%s", errmsg);
00307 return;
00308 }
00309 break;
00310
00311
00312 case 4:
00313 if (v4l_pwc->setWhiteBalanceMode(PWC_WB_FL, errmsg) < 0)
00314 {
00315 IUResetSwitches(&WhiteBalanceModeSP),
00316 WhiteBalanceModeS[0].s = ISS_ON;
00317 IDSetSwitch(&WhiteBalanceModeSP, "%s", errmsg);
00318 return;
00319 }
00320 break;
00321
00322 }
00323
00324 WhiteBalanceModeSP.s = IPS_OK;
00325 IDSetSwitch(&WhiteBalanceModeSP, NULL);
00326 return;
00327
00328 }
00329
00330
00331 if (!strcmp (CamSettingSP.name, name))
00332 {
00333
00334 if (checkPowerS(&CamSettingSP))
00335 return;
00336
00337 CamSettingSP.s = IPS_IDLE;
00338
00339 IUResetSwitches(&CamSettingSP);
00340 IUUpdateSwitches(&CamSettingSP, states, names, n);
00341
00342 if (CamSettingS[0].s == ISS_ON)
00343 {
00344 if (v4l_pwc->saveSettings(errmsg) < 0)
00345 {
00346 IUResetSwitches(&CamSettingSP);
00347 IDSetSwitch(&CamSettingSP, "%s", errmsg);
00348 return;
00349 }
00350
00351 CamSettingSP.s = IPS_OK;
00352 IDSetSwitch(&CamSettingSP, "Settings saved.");
00353 return;
00354 }
00355
00356 if (CamSettingS[1].s == ISS_ON)
00357 {
00358 v4l_pwc->restoreSettings();
00359 IUResetSwitches(&CamSettingSP);
00360 CamSettingSP.s = IPS_OK;
00361 IDSetSwitch(&CamSettingSP, "Settings restored.");
00362 updateV4L1Controls();
00363 return;
00364 }
00365
00366 if (CamSettingS[2].s == ISS_ON)
00367 {
00368 v4l_pwc->restoreFactorySettings();
00369 IUResetSwitches(&CamSettingSP);
00370 CamSettingSP.s = IPS_OK;
00371 IDSetSwitch(&CamSettingSP, "Factory settings restored.");
00372 updateV4L1Controls();
00373 return;
00374 }
00375 }
00376 #endif
00377
00378
00379 V4L_Driver::ISNewSwitch(dev, name, states, names, n);
00380
00381
00382
00383 }
00384
00385 void V4L_Philips::ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
00386 {
00387
00388 V4L_Driver::ISNewText(dev, name, texts, names, n);
00389
00390 }
00391
00392 void V4L_Philips::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
00393 {
00394
00395
00396 #ifndef HAVE_LINUX_VIDEODEV2_H
00397 char errmsg[ERRMSGSIZ];
00398
00399
00400 if (!strcmp (FrameRateNP.name, name))
00401 {
00402 if (checkPowerN(&FrameRateNP))
00403 return;
00404
00405 FrameRateNP.s = IPS_IDLE;
00406
00407 int oldFP = (int) FrameRateN[0].value;
00408
00409 if (IUUpdateNumbers(&FrameRateNP, values, names, n) < 0)
00410 return;
00411
00412 if (v4l_pwc->setFrameRate( (int) FrameRateN[0].value, errmsg) < 0)
00413 {
00414 FrameRateN[0].value = oldFP;
00415 IDSetNumber(&FrameRateNP, "%s", errmsg);
00416 return;
00417 }
00418
00419 FrameRateNP.s = IPS_OK;
00420 IDSetNumber(&FrameRateNP, NULL);
00421 return;
00422 }
00423
00424 if (!strcmp (ShutterSpeedNP.name, name))
00425 {
00426 if (checkPowerN(&ShutterSpeedNP))
00427 return;
00428
00429 ShutterSpeedNP.s = IPS_IDLE;
00430
00431 if (v4l_pwc->setExposure( (int) values[0], errmsg) < 0)
00432 {
00433 IDSetNumber(&ShutterSpeedNP, "%s", errmsg);
00434 return;
00435 }
00436
00437 ShutterSpeedN[0].value = values[0];
00438 ShutterSpeedNP.s = IPS_OK;
00439 IDSetNumber(&ShutterSpeedNP, NULL);
00440 return;
00441 }
00442
00443
00444 if (!strcmp (WhiteBalanceNP.name, name))
00445 {
00446 if (checkPowerN(&WhiteBalanceNP))
00447 return;
00448
00449 WhiteBalanceNP.s = IPS_IDLE;
00450
00451 int oldBalance[2];
00452 oldBalance[0] = (int) WhiteBalanceN[0].value;
00453 oldBalance[1] = (int) WhiteBalanceN[1].value;
00454
00455 if (IUUpdateNumbers(&WhiteBalanceNP, values, names, n) < 0)
00456 return;
00457
00458 if (v4l_pwc->setWhiteBalanceRed( (int) WhiteBalanceN[0].value * 256, errmsg))
00459 {
00460 WhiteBalanceN[0].value = oldBalance[0];
00461 WhiteBalanceN[1].value = oldBalance[1];
00462 IDSetNumber(&WhiteBalanceNP, "%s", errmsg);
00463 return;
00464 }
00465 if (v4l_pwc->setWhiteBalanceBlue( (int) WhiteBalanceN[1].value * 256, errmsg))
00466 {
00467 WhiteBalanceN[0].value = oldBalance[0];
00468 WhiteBalanceN[1].value = oldBalance[1];
00469 IDSetNumber(&WhiteBalanceNP, "%s", errmsg);
00470 return;
00471 }
00472
00473 IUResetSwitches(&WhiteBalanceModeSP);
00474 WhiteBalanceModeS[1].s = ISS_ON;
00475 WhiteBalanceModeSP.s = IPS_OK;
00476 WhiteBalanceNP.s = IPS_OK;
00477 IDSetSwitch(&WhiteBalanceModeSP, NULL);
00478 IDSetNumber(&WhiteBalanceNP, NULL);
00479 return;
00480 }
00481
00482 #endif
00483
00484
00485 V4L_Driver::ISNewNumber(dev, name, values, names, n);
00486
00487 }
00488
00489 #ifndef HAVE_LINUX_VIDEODEV2_H
00490
00491 void V4L_Philips::getBasicData()
00492 {
00493
00494 char errmsg[ERRMSGSIZ];
00495 bool result;
00496 int xmax, ymax, xmin, ymin, index;
00497
00498 v4l_pwc->getMaxMinSize(xmax, ymax, xmin, ymin);
00499
00500
00501 FrameN[2].value = v4l_pwc->getWidth();
00502 FrameN[2].min = xmin;
00503 FrameN[2].max = xmax;
00504
00505
00506 FrameN[3].value = v4l_pwc->getHeight();
00507 FrameN[3].min = ymin;
00508 FrameN[3].max = ymax;
00509
00510 IDSetNumber(&FrameNP, NULL);
00511 IUUpdateMinMax(&FrameNP);
00512
00513 IUSaveText(&camNameT[0], v4l_pwc->getDeviceName());
00514 IDSetText(&camNameTP, NULL);
00515
00516 IDLog("Raw values\n Contrast: %d \n Brightness %d \n Color %d \n Sharpness %d \n Gain %d \n Gamma %d \n", v4l_pwc->getContrast(), v4l_pwc->getBrightness(), v4l_pwc->getColor(), v4l_pwc->getSharpness(), v4l_pwc->getGain(), v4l_pwc->getGama());
00517
00518 updateV4L1Controls();
00519
00520 if (v4l_pwc->setFrameRate( (int) FrameRateN[0].value, errmsg) < 0)
00521 {
00522 FrameRateNP.s = IPS_ALERT;
00523 IDSetNumber(&FrameRateNP, "%s", errmsg);
00524 }
00525 else
00526 {
00527 FrameRateNP.s = IPS_OK;
00528 IDSetNumber(&FrameRateNP, NULL);
00529 }
00530
00531 result = v4l_pwc->getBackLight();
00532 if (result)
00533 {
00534 BackLightS[0].s = ISS_ON;
00535 BackLightS[1].s = ISS_OFF;
00536 }
00537 else
00538 {
00539 BackLightS[0].s = ISS_OFF;
00540 BackLightS[1].s = ISS_ON;
00541 }
00542 IDSetSwitch(&BackLightSP, NULL);
00543
00544 result = v4l_pwc->getFlicker();
00545 if (result)
00546 {
00547 AntiFlickerS[0].s = ISS_ON;
00548 AntiFlickerS[1].s = ISS_OFF;
00549 }
00550 else
00551 {
00552 AntiFlickerS[0].s = ISS_OFF;
00553 AntiFlickerS[1].s = ISS_ON;
00554 }
00555 IDSetSwitch(&AntiFlickerSP, NULL);
00556
00557 index = v4l_pwc->getNoiseRemoval();
00558 IUResetSwitches(&NoiseReductionSP);
00559 NoiseReductionS[index].s = ISS_ON;
00560 IDSetSwitch(&NoiseReductionSP, NULL);
00561
00562 index = v4l_pwc->getWhiteBalance();
00563 IUResetSwitches(&WhiteBalanceModeSP);
00564 switch (index)
00565 {
00566 case PWC_WB_AUTO:
00567 WhiteBalanceModeS[0].s = ISS_ON;
00568 break;
00569 case PWC_WB_MANUAL:
00570 WhiteBalanceModeS[1].s = ISS_ON;
00571 break;
00572 case PWC_WB_INDOOR:
00573 WhiteBalanceModeS[2].s = ISS_ON;
00574 break;
00575 case PWC_WB_OUTDOOR:
00576 WhiteBalanceModeS[3].s = ISS_ON;
00577 break;
00578 case PWC_WB_FL:
00579 WhiteBalanceModeS[3].s = ISS_ON;
00580 break;
00581 }
00582 IDSetSwitch(&WhiteBalanceModeSP, NULL);
00583
00584 }
00585 #endif
00586
00587 #ifndef HAVE_LINUX_VIDEODEV2_H
00588 void V4L_Philips::updateV4L1Controls()
00589 {
00590 int index =0;
00591
00592 ImageAdjustN[0].value = v4l_pwc->getContrast() / 256.;
00593 ImageAdjustN[1].value = v4l_pwc->getBrightness() / 256.;
00594 ImageAdjustN[2].value = v4l_pwc->getColor() / 256.;
00595 index = v4l_pwc->getSharpness();
00596 if (index < 0)
00597 ImageAdjustN[3].value = -1;
00598 else
00599 ImageAdjustN[3].value = v4l_pwc->getSharpness() / 256.;
00600
00601 ImageAdjustN[4].value = v4l_pwc->getGain() / 256.;
00602 ImageAdjustN[5].value = v4l_pwc->getGama() / 256.;
00603
00604 ImageAdjustNP.s = IPS_OK;
00605 IDSetNumber(&ImageAdjustNP, NULL);
00606
00607
00608 }
00609 #endif
00610