| 1 | /*
 | 
|---|
| 2 |     Phlips webcam INDI driver
 | 
|---|
| 3 |     Copyright (C) 2003-2005 by Jasem Mutlaq
 | 
|---|
| 4 | 
 | 
|---|
| 5 |     This library is free software; you can redistribute it and/or
 | 
|---|
| 6 |     modify it under the terms of the GNU Lesser General Public
 | 
|---|
| 7 |     License as published by the Free Software Foundation; either
 | 
|---|
| 8 |     version 2.1 of the License, or (at your option) any later version.
 | 
|---|
| 9 | 
 | 
|---|
| 10 |     This library is distributed in the hope that it will be useful,
 | 
|---|
| 11 |     but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
| 12 |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
|---|
| 13 |     Lesser General Public License for more details.
 | 
|---|
| 14 | 
 | 
|---|
| 15 |     You should have received a copy of the GNU Lesser General Public
 | 
|---|
| 16 |     License along with this library; if not, write to the Free Software
 | 
|---|
| 17 |     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 | 
|---|
| 18 | 
 | 
|---|
| 19 |     2005.04.29  JM: There is no need for this file for Video 4 Linux 2. It is kept for V4L 1 compatibility.
 | 
|---|
| 20 | 
 | 
|---|
| 21 | */
 | 
|---|
| 22 | 
 | 
|---|
| 23 | #include "v4lphilips.h"
 | 
|---|
| 24 | #include "webcam/pwc-ioctl.h"
 | 
|---|
| 25 | 
 | 
|---|
| 26 | V4L_Philips::V4L_Philips() : V4L_Driver()
 | 
|---|
| 27 | {
 | 
|---|
| 28 | 
 | 
|---|
| 29 | }
 | 
|---|
| 30 | 
 | 
|---|
| 31 | V4L_Philips::~V4L_Philips()
 | 
|---|
| 32 | {
 | 
|---|
| 33 | 
 | 
|---|
| 34 | }
 | 
|---|
| 35 | 
 | 
|---|
| 36 | void V4L_Philips::initCamBase()
 | 
|---|
| 37 | {
 | 
|---|
| 38 |    #ifdef HAVE_LINUX_VIDEODEV2_H
 | 
|---|
| 39 |     v4l_base = new V4L2_Base();
 | 
|---|
| 40 |    #else
 | 
|---|
| 41 |     v4l_pwc = new V4L1_PWC();
 | 
|---|
| 42 |     v4l_base = (V4L1_Base *) v4l_pwc;
 | 
|---|
| 43 |    #endif
 | 
|---|
| 44 | }
 | 
|---|
| 45 | 
 | 
|---|
| 46 | void V4L_Philips::initProperties(const char *dev)
 | 
|---|
| 47 | {
 | 
|---|
| 48 | 
 | 
|---|
| 49 |   // Call parent
 | 
|---|
| 50 |   V4L_Driver::initProperties(dev);
 | 
|---|
| 51 | 
 | 
|---|
| 52 |   IUFillSwitch(&BackLightS[0], "ON", "", ISS_OFF);
 | 
|---|
| 53 |   IUFillSwitch(&BackLightS[1], "OFF", "", ISS_ON);
 | 
|---|
| 54 |   IUFillSwitchVector(&BackLightSP, BackLightS, NARRAY(BackLightS), dev, "Back Light", "", IMAGE_CONTROL, IP_RW, ISR_1OFMANY, 0 , IPS_IDLE);
 | 
|---|
| 55 | 
 | 
|---|
| 56 |   IUFillSwitch(&AntiFlickerS[0], "ON", "", ISS_OFF);
 | 
|---|
| 57 |   IUFillSwitch(&AntiFlickerS[1], "OFF", "", ISS_ON);
 | 
|---|
| 58 |   IUFillSwitchVector(&AntiFlickerSP, AntiFlickerS, NARRAY(AntiFlickerS), dev, "Anti Flicker", "", IMAGE_CONTROL, IP_RW, ISR_1OFMANY, 0 , IPS_IDLE);
 | 
|---|
| 59 | 
 | 
|---|
| 60 |   IUFillSwitch(&NoiseReductionS[0], "None", "", ISS_ON);
 | 
|---|
| 61 |   IUFillSwitch(&NoiseReductionS[1], "Low", "", ISS_OFF);
 | 
|---|
| 62 |   IUFillSwitch(&NoiseReductionS[2], "Medium", "", ISS_OFF);
 | 
|---|
| 63 |   IUFillSwitch(&NoiseReductionS[3], "High", "", ISS_OFF);
 | 
|---|
| 64 |   IUFillSwitchVector(&NoiseReductionSP, NoiseReductionS, NARRAY(NoiseReductionS), dev, "Noise Reduction", "", IMAGE_CONTROL, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
 | 
|---|
| 65 | 
 | 
|---|
| 66 |   IUFillSwitch(&CamSettingS[0], "Save", "", ISS_OFF);
 | 
|---|
| 67 |   IUFillSwitch(&CamSettingS[1], "Restore", "", ISS_OFF);
 | 
|---|
| 68 |   IUFillSwitch(&CamSettingS[2], "Factory", "", ISS_OFF);
 | 
|---|
| 69 |   IUFillSwitchVector(&CamSettingSP, CamSettingS, NARRAY(CamSettingS), dev, "Settings", "", IMAGE_CONTROL, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
 | 
|---|
| 70 | 
 | 
|---|
| 71 |   IUFillSwitch(&WhiteBalanceModeS[0], "Auto" , "", ISS_ON);
 | 
|---|
| 72 |   IUFillSwitch(&WhiteBalanceModeS[1], "Manual" , "", ISS_OFF);
 | 
|---|
| 73 |   IUFillSwitch(&WhiteBalanceModeS[2], "Indoor" , "", ISS_OFF);
 | 
|---|
| 74 |   IUFillSwitch(&WhiteBalanceModeS[3], "Outdoor" , "", ISS_OFF);
 | 
|---|
| 75 |   IUFillSwitch(&WhiteBalanceModeS[4], "Fluorescent" , "", ISS_OFF);
 | 
|---|
| 76 |   
 | 
|---|
| 77 |   IUFillSwitchVector(&WhiteBalanceModeSP, WhiteBalanceModeS, NARRAY(WhiteBalanceModeS), dev, "White Balance Mode", "", IMAGE_CONTROL, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
 | 
|---|
| 78 | 
 | 
|---|
| 79 |   IUFillNumber(&WhiteBalanceN[0], "Manual Red", "", "%0.f", 0., 256., 1., 0.);
 | 
|---|
| 80 |   IUFillNumber(&WhiteBalanceN[1], "Manual Blue", "", "%0.f", 0., 256., 1., 0.);
 | 
|---|
| 81 |   IUFillNumberVector(&WhiteBalanceNP, WhiteBalanceN, NARRAY(WhiteBalanceN), dev, "White Balance", "", IMAGE_CONTROL, IP_RW, 60, IPS_IDLE);
 | 
|---|
| 82 | 
 | 
|---|
| 83 |   IUFillNumber(&ShutterSpeedN[0], "Speed", "", "%0.f", 0., 65535., 100., 0.);
 | 
|---|
| 84 |   IUFillNumberVector(&ShutterSpeedNP, ShutterSpeedN, NARRAY(ShutterSpeedN), dev, "Shutter Speed", "", COMM_GROUP, IP_RW, 60, IPS_IDLE);
 | 
|---|
| 85 | 
 | 
|---|
| 86 | }
 | 
|---|
| 87 | 
 | 
|---|
| 88 | void V4L_Philips::ISGetProperties (const char *dev)
 | 
|---|
| 89 | {
 | 
|---|
| 90 | 
 | 
|---|
| 91 |   if (dev && strcmp (device_name, dev))
 | 
|---|
| 92 |     return;
 | 
|---|
| 93 |     
 | 
|---|
| 94 |    #ifdef HAVE_LINUX_VIDEODEV2_H
 | 
|---|
| 95 |     V4L_Driver::ISGetProperties(dev);
 | 
|---|
| 96 |     return;
 | 
|---|
| 97 |    #endif
 | 
|---|
| 98 | 
 | 
|---|
| 99 |   /* COMM_GROUP */
 | 
|---|
| 100 |   IDDefSwitch(&PowerSP, NULL);
 | 
|---|
| 101 |   IDDefText(&PortTP, NULL);
 | 
|---|
| 102 |   IDDefText(&camNameTP, NULL);
 | 
|---|
| 103 |   IDDefSwitch(&StreamSP, NULL);
 | 
|---|
| 104 |   IDDefNumber(&FrameRateNP, NULL);
 | 
|---|
| 105 |   IDDefNumber(&ExposeTimeNP, NULL);
 | 
|---|
| 106 |   IDDefNumber(&ShutterSpeedNP, NULL);
 | 
|---|
| 107 |   IDDefBLOB(&imageBP, NULL);
 | 
|---|
| 108 |   
 | 
|---|
| 109 |   /* Image Groups */
 | 
|---|
| 110 |   IDDefSwitch(&CompressSP, NULL);
 | 
|---|
| 111 |   IDDefSwitch(&ImageTypeSP, NULL);
 | 
|---|
| 112 |   IDDefNumber(&FrameNP, NULL);
 | 
|---|
| 113 |   IDDefNumber(&ImageAdjustNP, NULL);
 | 
|---|
| 114 |   
 | 
|---|
| 115 |   /* Image Control */
 | 
|---|
| 116 |   IDDefSwitch(&WhiteBalanceModeSP, NULL);
 | 
|---|
| 117 |   IDDefNumber(&WhiteBalanceNP, NULL);
 | 
|---|
| 118 |   IDDefSwitch(&BackLightSP, NULL);
 | 
|---|
| 119 |   IDDefSwitch(&AntiFlickerSP, NULL);
 | 
|---|
| 120 |   IDDefSwitch(&NoiseReductionSP, NULL);
 | 
|---|
| 121 |   IDDefSwitch(&CamSettingSP, NULL);
 | 
|---|
| 122 | 
 | 
|---|
| 123 | }
 | 
|---|
| 124 | 
 | 
|---|
| 125 | void V4L_Philips::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
 | 
|---|
| 126 | {
 | 
|---|
| 127 |         /* ignore if not ours */
 | 
|---|
| 128 |      if (dev && strcmp (device_name, dev))
 | 
|---|
| 129 |          return;
 | 
|---|
| 130 | 
 | 
|---|
| 131 |      /* Connection */
 | 
|---|
| 132 |      if (!strcmp (name, PowerSP.name))
 | 
|---|
| 133 |      {
 | 
|---|
| 134 |           IUResetSwitch(&PowerSP);
 | 
|---|
| 135 |           IUUpdateSwitch(&PowerSP, states, names, n);
 | 
|---|
| 136 |           connectCamera();
 | 
|---|
| 137 |           return;
 | 
|---|
| 138 |      }
 | 
|---|
| 139 |     
 | 
|---|
| 140 | 
 | 
|---|
| 141 |      #ifndef HAVE_LINUX_VIDEODEV2_H
 | 
|---|
| 142 |     /* Anti Flicker control */
 | 
|---|
| 143 |     if (!strcmp (AntiFlickerSP.name, name))
 | 
|---|
| 144 |     {
 | 
|---|
| 145 |        if (checkPowerS(&AntiFlickerSP))
 | 
|---|
| 146 |          return;
 | 
|---|
| 147 |          
 | 
|---|
| 148 |        AntiFlickerSP.s = IPS_IDLE;
 | 
|---|
| 149 |        
 | 
|---|
| 150 |        IUResetSwitch(&AntiFlickerSP);
 | 
|---|
| 151 |        IUUpdateSwitch(&AntiFlickerSP, states, names, n);
 | 
|---|
| 152 |        
 | 
|---|
| 153 |        if (AntiFlickerS[0].s == ISS_ON)
 | 
|---|
| 154 |        {
 | 
|---|
| 155 |          if (v4l_pwc->setFlicker(true, errmsg) < 0)
 | 
|---|
| 156 |          {
 | 
|---|
| 157 |            AntiFlickerS[0].s = ISS_OFF;
 | 
|---|
| 158 |            AntiFlickerS[1].s = ISS_ON;
 | 
|---|
| 159 |            IDSetSwitch(&AntiFlickerSP, "%s", errmsg);
 | 
|---|
| 160 |            return;
 | 
|---|
| 161 |          }
 | 
|---|
| 162 |          
 | 
|---|
| 163 |          AntiFlickerSP.s = IPS_OK;
 | 
|---|
| 164 |          IDSetSwitch(&AntiFlickerSP, NULL);
 | 
|---|
| 165 |        }
 | 
|---|
| 166 |        else
 | 
|---|
| 167 |        {
 | 
|---|
| 168 |          if (v4l_pwc->setFlicker(false, errmsg) < 0)
 | 
|---|
| 169 |          {
 | 
|---|
| 170 |            AntiFlickerS[0].s = ISS_ON;
 | 
|---|
| 171 |            AntiFlickerS[1].s = ISS_OFF;
 | 
|---|
| 172 |            IDSetSwitch(&AntiFlickerSP, "%s", errmsg);
 | 
|---|
| 173 |            return;
 | 
|---|
| 174 |          }
 | 
|---|
| 175 |          
 | 
|---|
| 176 |          IDSetSwitch(&AntiFlickerSP, NULL);
 | 
|---|
| 177 |        }
 | 
|---|
| 178 |        
 | 
|---|
| 179 |        return;
 | 
|---|
| 180 |     }
 | 
|---|
| 181 |     
 | 
|---|
| 182 |     /* Back light compensation */
 | 
|---|
| 183 |     if (!strcmp (BackLightSP.name, name))
 | 
|---|
| 184 |     {
 | 
|---|
| 185 |        if (checkPowerS(&BackLightSP))
 | 
|---|
| 186 |          return;
 | 
|---|
| 187 |          
 | 
|---|
| 188 |        BackLightSP.s = IPS_IDLE;
 | 
|---|
| 189 |        
 | 
|---|
| 190 |        IUResetSwitch(&BackLightSP);
 | 
|---|
| 191 |        IUUpdateSwitch(&BackLightSP, states, names, n);
 | 
|---|
| 192 |        
 | 
|---|
| 193 |        if (BackLightS[0].s == ISS_ON)
 | 
|---|
| 194 |        {
 | 
|---|
| 195 |          if (v4l_pwc->setBackLight(true, errmsg) < 0)
 | 
|---|
| 196 |          {
 | 
|---|
| 197 |            BackLightS[0].s = ISS_OFF;
 | 
|---|
| 198 |            BackLightS[1].s = ISS_ON;
 | 
|---|
| 199 |            IDSetSwitch(&BackLightSP, "%s", errmsg);
 | 
|---|
| 200 |            return;
 | 
|---|
| 201 |          }
 | 
|---|
| 202 |          
 | 
|---|
| 203 |          BackLightSP.s = IPS_OK;
 | 
|---|
| 204 |          IDSetSwitch(&BackLightSP, NULL);
 | 
|---|
| 205 |        }
 | 
|---|
| 206 |        else
 | 
|---|
| 207 |        {
 | 
|---|
| 208 |          if (v4l_pwc->setBackLight(false, errmsg) < 0)
 | 
|---|
| 209 |          {
 | 
|---|
| 210 |            BackLightS[0].s = ISS_ON;
 | 
|---|
| 211 |            BackLightS[1].s = ISS_OFF;
 | 
|---|
| 212 |            IDSetSwitch(&BackLightSP, "%s", errmsg);
 | 
|---|
| 213 |            return;
 | 
|---|
| 214 |          }
 | 
|---|
| 215 |          
 | 
|---|
| 216 |          IDSetSwitch(&BackLightSP, NULL);
 | 
|---|
| 217 |        }
 | 
|---|
| 218 |        
 | 
|---|
| 219 |        return;
 | 
|---|
| 220 |     }
 | 
|---|
| 221 |          
 | 
|---|
| 222 |     /* Noise reduction control */
 | 
|---|
| 223 |     if (!strcmp (NoiseReductionSP.name, name))
 | 
|---|
| 224 |     {
 | 
|---|
| 225 |        if (checkPowerS(&NoiseReductionSP))
 | 
|---|
| 226 |          return;
 | 
|---|
| 227 |          
 | 
|---|
| 228 |        NoiseReductionSP.s = IPS_IDLE;
 | 
|---|
| 229 |        
 | 
|---|
| 230 |        IUResetSwitch(&NoiseReductionSP);
 | 
|---|
| 231 |        IUUpdateSwitch(&NoiseReductionSP, states, names, n);
 | 
|---|
| 232 |        
 | 
|---|
| 233 |        for (int i=0; i < 4; i++)
 | 
|---|
| 234 |         if (NoiseReductionS[i].s == ISS_ON)
 | 
|---|
| 235 |         {
 | 
|---|
| 236 |            index = i;
 | 
|---|
| 237 |            break;
 | 
|---|
| 238 |         }
 | 
|---|
| 239 |         
 | 
|---|
| 240 |        if (v4l_pwc->setNoiseRemoval(index, errmsg) < 0)
 | 
|---|
| 241 |        {
 | 
|---|
| 242 |          IUResetSwitch(&NoiseReductionSP);
 | 
|---|
| 243 |          NoiseReductionS[0].s = ISS_ON;
 | 
|---|
| 244 |          IDSetSwitch(&NoiseReductionSP, "%s", errmsg);
 | 
|---|
| 245 |          return;
 | 
|---|
| 246 |        }
 | 
|---|
| 247 |        
 | 
|---|
| 248 |        NoiseReductionSP.s = IPS_OK;
 | 
|---|
| 249 |        
 | 
|---|
| 250 |        IDSetSwitch(&NoiseReductionSP, NULL);
 | 
|---|
| 251 |        return;
 | 
|---|
| 252 |     }
 | 
|---|
| 253 |     
 | 
|---|
| 254 |     /* White balace mode */
 | 
|---|
| 255 |     if (!strcmp (WhiteBalanceModeSP.name, name))
 | 
|---|
| 256 |     {
 | 
|---|
| 257 |        if (checkPowerS(&WhiteBalanceModeSP))
 | 
|---|
| 258 |          return;
 | 
|---|
| 259 |          
 | 
|---|
| 260 |        WhiteBalanceModeSP.s = IPS_IDLE;
 | 
|---|
| 261 |        
 | 
|---|
| 262 |        IUResetSwitch(&WhiteBalanceModeSP);
 | 
|---|
| 263 |        IUUpdateSwitch(&WhiteBalanceModeSP, states, names, n);
 | 
|---|
| 264 |        
 | 
|---|
| 265 |        for (int i=0; i < 5; i++)
 | 
|---|
| 266 |         if (WhiteBalanceModeS[i].s == ISS_ON)
 | 
|---|
| 267 |         {
 | 
|---|
| 268 |            index = i;
 | 
|---|
| 269 |            break;
 | 
|---|
| 270 |         }
 | 
|---|
| 271 |         
 | 
|---|
| 272 |         switch (index)
 | 
|---|
| 273 |         {
 | 
|---|
| 274 |           // Auto
 | 
|---|
| 275 |           case 0:
 | 
|---|
| 276 |            if (v4l_pwc->setWhiteBalanceMode(PWC_WB_AUTO, errmsg) < 0)
 | 
|---|
| 277 |            {
 | 
|---|
| 278 |              IUResetSwitch(&WhiteBalanceModeSP),
 | 
|---|
| 279 |              WhiteBalanceModeS[0].s = ISS_ON;
 | 
|---|
| 280 |              IDSetSwitch(&WhiteBalanceModeSP, "%s", errmsg);
 | 
|---|
| 281 |              return;
 | 
|---|
| 282 |            }
 | 
|---|
| 283 |            break;
 | 
|---|
| 284 |            
 | 
|---|
| 285 |          // Manual
 | 
|---|
| 286 |          case 1:
 | 
|---|
| 287 |           if (v4l_pwc->setWhiteBalanceMode(PWC_WB_MANUAL, errmsg) < 0)
 | 
|---|
| 288 |            {
 | 
|---|
| 289 |              IUResetSwitch(&WhiteBalanceModeSP),
 | 
|---|
| 290 |              WhiteBalanceModeS[0].s = ISS_ON;
 | 
|---|
| 291 |              IDSetSwitch(&WhiteBalanceModeSP, "%s", errmsg);
 | 
|---|
| 292 |              return;
 | 
|---|
| 293 |            }
 | 
|---|
| 294 |            break;
 | 
|---|
| 295 |            
 | 
|---|
| 296 |          // Indoor
 | 
|---|
| 297 |          case 2:
 | 
|---|
| 298 |           if (v4l_pwc->setWhiteBalanceMode(PWC_WB_INDOOR, errmsg) < 0)
 | 
|---|
| 299 |            {
 | 
|---|
| 300 |              IUResetSwitch(&WhiteBalanceModeSP),
 | 
|---|
| 301 |              WhiteBalanceModeS[0].s = ISS_ON;
 | 
|---|
| 302 |              IDSetSwitch(&WhiteBalanceModeSP, "%s", errmsg);
 | 
|---|
| 303 |              return;
 | 
|---|
| 304 |            }
 | 
|---|
| 305 |            break;
 | 
|---|
| 306 |            
 | 
|---|
| 307 |          // Outdoor
 | 
|---|
| 308 |          case 3:
 | 
|---|
| 309 |           if (v4l_pwc->setWhiteBalanceMode(PWC_WB_OUTDOOR, errmsg) < 0)
 | 
|---|
| 310 |            {
 | 
|---|
| 311 |              IUResetSwitch(&WhiteBalanceModeSP),
 | 
|---|
| 312 |              WhiteBalanceModeS[0].s = ISS_ON;
 | 
|---|
| 313 |              IDSetSwitch(&WhiteBalanceModeSP, "%s", errmsg);
 | 
|---|
| 314 |              return;
 | 
|---|
| 315 |            }
 | 
|---|
| 316 |            break;
 | 
|---|
| 317 |            
 | 
|---|
| 318 |          // Flurescent
 | 
|---|
| 319 |          case 4:
 | 
|---|
| 320 |           if (v4l_pwc->setWhiteBalanceMode(PWC_WB_FL, errmsg) < 0)
 | 
|---|
| 321 |            {
 | 
|---|
| 322 |              IUResetSwitch(&WhiteBalanceModeSP),
 | 
|---|
| 323 |              WhiteBalanceModeS[0].s = ISS_ON;
 | 
|---|
| 324 |              IDSetSwitch(&WhiteBalanceModeSP, "%s", errmsg);
 | 
|---|
| 325 |              return;
 | 
|---|
| 326 |            }
 | 
|---|
| 327 |            break;
 | 
|---|
| 328 |            
 | 
|---|
| 329 |         }
 | 
|---|
| 330 |              
 | 
|---|
| 331 |         WhiteBalanceModeSP.s = IPS_OK;
 | 
|---|
| 332 |         IDSetSwitch(&WhiteBalanceModeSP, NULL);
 | 
|---|
| 333 |         return;
 | 
|---|
| 334 |         
 | 
|---|
| 335 |      }
 | 
|---|
| 336 |         
 | 
|---|
| 337 |     /* Camera setttings */
 | 
|---|
| 338 |     if (!strcmp (CamSettingSP.name, name))
 | 
|---|
| 339 |     {
 | 
|---|
| 340 |        
 | 
|---|
| 341 |        if (checkPowerS(&CamSettingSP))
 | 
|---|
| 342 |          return;
 | 
|---|
| 343 |     
 | 
|---|
| 344 |         CamSettingSP.s = IPS_IDLE;
 | 
|---|
| 345 |         
 | 
|---|
| 346 |         IUResetSwitch(&CamSettingSP);
 | 
|---|
| 347 |         IUUpdateSwitch(&CamSettingSP, states, names, n);
 | 
|---|
| 348 |         
 | 
|---|
| 349 |         if (CamSettingS[0].s == ISS_ON)
 | 
|---|
| 350 |         {
 | 
|---|
| 351 |           if (v4l_pwc->saveSettings(errmsg) < 0)
 | 
|---|
| 352 |           {
 | 
|---|
| 353 |             IUResetSwitch(&CamSettingSP);
 | 
|---|
| 354 |             IDSetSwitch(&CamSettingSP, "%s", errmsg);
 | 
|---|
| 355 |             return;
 | 
|---|
| 356 |           }
 | 
|---|
| 357 |           
 | 
|---|
| 358 |           CamSettingSP.s = IPS_OK;
 | 
|---|
| 359 |           IDSetSwitch(&CamSettingSP, "Settings saved.");
 | 
|---|
| 360 |           return;
 | 
|---|
| 361 |         }
 | 
|---|
| 362 |         
 | 
|---|
| 363 |         if (CamSettingS[1].s == ISS_ON)
 | 
|---|
| 364 |         {
 | 
|---|
| 365 |            v4l_pwc->restoreSettings();
 | 
|---|
| 366 |            IUResetSwitch(&CamSettingSP);
 | 
|---|
| 367 |            CamSettingSP.s = IPS_OK;
 | 
|---|
| 368 |            IDSetSwitch(&CamSettingSP, "Settings restored.");
 | 
|---|
| 369 |            updateV4L1Controls();
 | 
|---|
| 370 |            return;
 | 
|---|
| 371 |         }
 | 
|---|
| 372 |         
 | 
|---|
| 373 |         if (CamSettingS[2].s == ISS_ON)
 | 
|---|
| 374 |         {
 | 
|---|
| 375 |           v4l_pwc->restoreFactorySettings();
 | 
|---|
| 376 |           IUResetSwitch(&CamSettingSP);
 | 
|---|
| 377 |           CamSettingSP.s = IPS_OK;
 | 
|---|
| 378 |           IDSetSwitch(&CamSettingSP, "Factory settings restored.");
 | 
|---|
| 379 |           updateV4L1Controls();
 | 
|---|
| 380 |           return;
 | 
|---|
| 381 |         }
 | 
|---|
| 382 |      }
 | 
|---|
| 383 |      #endif
 | 
|---|
| 384 | 
 | 
|---|
| 385 |      // Call parent
 | 
|---|
| 386 |      V4L_Driver::ISNewSwitch(dev, name, states, names, n);
 | 
|---|
| 387 |         
 | 
|---|
| 388 |      
 | 
|---|
| 389 | 
 | 
|---|
| 390 | }
 | 
|---|
| 391 | 
 | 
|---|
| 392 | void V4L_Philips::ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
 | 
|---|
| 393 | {
 | 
|---|
| 394 |    
 | 
|---|
| 395 |      V4L_Driver::ISNewText(dev, name, texts, names, n);
 | 
|---|
| 396 | 
 | 
|---|
| 397 | }
 | 
|---|
| 398 | 
 | 
|---|
| 399 | void V4L_Philips::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
 | 
|---|
| 400 | {
 | 
|---|
| 401 | 
 | 
|---|
| 402 |     // Nothing for V4L 2 to do here
 | 
|---|
| 403 |     #ifndef HAVE_LINUX_VIDEODEV2_H
 | 
|---|
| 404 |     char errmsg[ERRMSGSIZ];
 | 
|---|
| 405 | 
 | 
|---|
| 406 |     /* Frame rate */
 | 
|---|
| 407 |    if (!strcmp (FrameRateNP.name, name))
 | 
|---|
| 408 |    {
 | 
|---|
| 409 |      if (checkPowerN(&FrameRateNP))
 | 
|---|
| 410 |       return;
 | 
|---|
| 411 |       
 | 
|---|
| 412 |      FrameRateNP.s = IPS_IDLE;
 | 
|---|
| 413 |      
 | 
|---|
| 414 |      int oldFP = (int) FrameRateN[0].value; 
 | 
|---|
| 415 |      
 | 
|---|
| 416 |      if (IUUpdateNumber(&FrameRateNP, values, names, n) < 0)
 | 
|---|
| 417 |        return;
 | 
|---|
| 418 |        
 | 
|---|
| 419 |      if (v4l_pwc->setFrameRate( (int) FrameRateN[0].value, errmsg) < 0)
 | 
|---|
| 420 |      {
 | 
|---|
| 421 |        FrameRateN[0].value = oldFP;
 | 
|---|
| 422 |        IDSetNumber(&FrameRateNP, "%s", errmsg);
 | 
|---|
| 423 |        return;
 | 
|---|
| 424 |      }
 | 
|---|
| 425 |        
 | 
|---|
| 426 |      FrameRateNP.s = IPS_OK;
 | 
|---|
| 427 |      IDSetNumber(&FrameRateNP, NULL);
 | 
|---|
| 428 |      return;
 | 
|---|
| 429 |    }
 | 
|---|
| 430 |   
 | 
|---|
| 431 |    if (!strcmp (ShutterSpeedNP.name, name))
 | 
|---|
| 432 |    {
 | 
|---|
| 433 |      if (checkPowerN(&ShutterSpeedNP))
 | 
|---|
| 434 |        return;
 | 
|---|
| 435 |        
 | 
|---|
| 436 |      ShutterSpeedNP.s = IPS_IDLE;
 | 
|---|
| 437 |      
 | 
|---|
| 438 |      if (v4l_pwc->setExposure( (int) values[0], errmsg) < 0)
 | 
|---|
| 439 |      {
 | 
|---|
| 440 |        IDSetNumber(&ShutterSpeedNP, "%s", errmsg);
 | 
|---|
| 441 |        return;
 | 
|---|
| 442 |      }
 | 
|---|
| 443 |      
 | 
|---|
| 444 |      ShutterSpeedN[0].value = values[0];
 | 
|---|
| 445 |      ShutterSpeedNP.s = IPS_OK;
 | 
|---|
| 446 |      IDSetNumber(&ShutterSpeedNP, NULL);
 | 
|---|
| 447 |      return;
 | 
|---|
| 448 |   }
 | 
|---|
| 449 |   
 | 
|---|
| 450 |    /* White balance */
 | 
|---|
| 451 |    if (!strcmp (WhiteBalanceNP.name, name))
 | 
|---|
| 452 |    {
 | 
|---|
| 453 |      if (checkPowerN(&WhiteBalanceNP))
 | 
|---|
| 454 |        return;
 | 
|---|
| 455 |        
 | 
|---|
| 456 |      WhiteBalanceNP.s = IPS_IDLE;
 | 
|---|
| 457 |      
 | 
|---|
| 458 |      int oldBalance[2];
 | 
|---|
| 459 |      oldBalance[0] = (int) WhiteBalanceN[0].value;
 | 
|---|
| 460 |      oldBalance[1] = (int) WhiteBalanceN[1].value;
 | 
|---|
| 461 |      
 | 
|---|
| 462 |      if (IUUpdateNumber(&WhiteBalanceNP, values, names, n) < 0)
 | 
|---|
| 463 |        return;
 | 
|---|
| 464 |      
 | 
|---|
| 465 |      if (v4l_pwc->setWhiteBalanceRed( (int) WhiteBalanceN[0].value * 256, errmsg))
 | 
|---|
| 466 |      {
 | 
|---|
| 467 |        WhiteBalanceN[0].value = oldBalance[0];
 | 
|---|
| 468 |        WhiteBalanceN[1].value = oldBalance[1];
 | 
|---|
| 469 |        IDSetNumber(&WhiteBalanceNP, "%s", errmsg);
 | 
|---|
| 470 |        return;
 | 
|---|
| 471 |      }
 | 
|---|
| 472 |      if (v4l_pwc->setWhiteBalanceBlue( (int) WhiteBalanceN[1].value * 256, errmsg))
 | 
|---|
| 473 |      {
 | 
|---|
| 474 |        WhiteBalanceN[0].value = oldBalance[0];
 | 
|---|
| 475 |        WhiteBalanceN[1].value = oldBalance[1];
 | 
|---|
| 476 |        IDSetNumber(&WhiteBalanceNP, "%s", errmsg);
 | 
|---|
| 477 |        return;
 | 
|---|
| 478 |      }
 | 
|---|
| 479 |      
 | 
|---|
| 480 |      IUResetSwitch(&WhiteBalanceModeSP);
 | 
|---|
| 481 |      WhiteBalanceModeS[1].s = ISS_ON;
 | 
|---|
| 482 |      WhiteBalanceModeSP.s   = IPS_OK;
 | 
|---|
| 483 |      WhiteBalanceNP.s = IPS_OK;
 | 
|---|
| 484 |      IDSetSwitch(&WhiteBalanceModeSP, NULL);
 | 
|---|
| 485 |      IDSetNumber(&WhiteBalanceNP, NULL);
 | 
|---|
| 486 |      return;
 | 
|---|
| 487 |    }
 | 
|---|
| 488 | 
 | 
|---|
| 489 |    #endif
 | 
|---|
| 490 | 
 | 
|---|
| 491 |    // Call parent 
 | 
|---|
| 492 |    V4L_Driver::ISNewNumber(dev, name, values, names, n);
 | 
|---|
| 493 | 
 | 
|---|
| 494 | }
 | 
|---|
| 495 | 
 | 
|---|
| 496 | void V4L_Philips::connectCamera()
 | 
|---|
| 497 | {
 | 
|---|
| 498 |   char errmsg[ERRMSGSIZ];
 | 
|---|
| 499 |   
 | 
|---|
| 500 |     
 | 
|---|
| 501 |   switch (PowerS[0].s)
 | 
|---|
| 502 |   {
 | 
|---|
| 503 |      case ISS_ON:
 | 
|---|
| 504 |       #ifdef HAVE_LINUX_VIDEODEV2_H
 | 
|---|
| 505 |       if (v4l_base->connectCam(PortT[0].text, errmsg, V4L2_PIX_FMT_YUV420) < 0)
 | 
|---|
| 506 |       #else
 | 
|---|
| 507 |       if (v4l_base->connectCam(PortT[0].text, errmsg) < 0)
 | 
|---|
| 508 |       #endif
 | 
|---|
| 509 |       {
 | 
|---|
| 510 |           PowerSP.s = IPS_IDLE;
 | 
|---|
| 511 |           PowerS[0].s = ISS_OFF;
 | 
|---|
| 512 |           PowerS[1].s = ISS_ON;
 | 
|---|
| 513 |           IDSetSwitch(&PowerSP, "Error: unable to open device");
 | 
|---|
| 514 |           IDLog("Error: %s\n", errmsg);
 | 
|---|
| 515 |           return;
 | 
|---|
| 516 |       }
 | 
|---|
| 517 |       
 | 
|---|
| 518 |       /* Sucess! */
 | 
|---|
| 519 |       PowerS[0].s = ISS_ON;
 | 
|---|
| 520 |       PowerS[1].s = ISS_OFF;
 | 
|---|
| 521 |       PowerSP.s = IPS_OK;
 | 
|---|
| 522 |       IDSetSwitch(&PowerSP, "Philips Webcam is online. Retrieving basic data.");
 | 
|---|
| 523 | 
 | 
|---|
| 524 |       v4l_base->registerCallback(newFrame, this);
 | 
|---|
| 525 |       
 | 
|---|
| 526 |       IDLog("Philips Webcam is online. Retrieving basic data.\n");
 | 
|---|
| 527 |       getBasicData();
 | 
|---|
| 528 |       
 | 
|---|
| 529 |       break;
 | 
|---|
| 530 |       
 | 
|---|
| 531 |     case ISS_OFF:
 | 
|---|
| 532 |       PowerS[0].s = ISS_OFF;
 | 
|---|
| 533 |       PowerS[1].s = ISS_ON;
 | 
|---|
| 534 |       PowerSP.s = IPS_IDLE;
 | 
|---|
| 535 |       
 | 
|---|
| 536 |       v4l_base->disconnectCam();
 | 
|---|
| 537 |       
 | 
|---|
| 538 |       IDSetSwitch(&PowerSP, "Philips Webcam is offline.");
 | 
|---|
| 539 |       
 | 
|---|
| 540 |       break;
 | 
|---|
| 541 |      }
 | 
|---|
| 542 | }
 | 
|---|
| 543 | 
 | 
|---|
| 544 | #ifndef HAVE_LINUX_VIDEODEV2_H
 | 
|---|
| 545 | /* Retrieves basic data from the device upon connection.*/
 | 
|---|
| 546 | void V4L_Philips::getBasicData()
 | 
|---|
| 547 | {
 | 
|---|
| 548 | 
 | 
|---|
| 549 |   char errmsg[ERRMSGSIZ];
 | 
|---|
| 550 |   bool result;
 | 
|---|
| 551 |   int xmax, ymax, xmin, ymin, index;
 | 
|---|
| 552 |   
 | 
|---|
| 553 |   v4l_pwc->getMaxMinSize(xmax, ymax, xmin, ymin);
 | 
|---|
| 554 |   
 | 
|---|
| 555 |   IDLog("X (%d,%d), Y (%d,%d)\n", xmin, xmax, ymin, ymax);
 | 
|---|
| 556 | 
 | 
|---|
| 557 |   /* Width */
 | 
|---|
| 558 |   FrameN[2].value = v4l_pwc->getWidth();
 | 
|---|
| 559 |   FrameN[2].min = xmin;
 | 
|---|
| 560 |   FrameN[2].max = xmax;
 | 
|---|
| 561 |   
 | 
|---|
| 562 |   /* Height */
 | 
|---|
| 563 |   FrameN[3].value = v4l_pwc->getHeight();
 | 
|---|
| 564 |   FrameN[3].min = ymin;
 | 
|---|
| 565 |   FrameN[3].max = ymax;
 | 
|---|
| 566 | 
 | 
|---|
| 567 |   IDSetNumber(&FrameNP, NULL);
 | 
|---|
| 568 |   IUUpdateMinMax(&FrameNP);
 | 
|---|
| 569 |   
 | 
|---|
| 570 |   IUSaveText(&camNameT[0], v4l_pwc->getDeviceName());
 | 
|---|
| 571 |   IDSetText(&camNameTP, NULL);
 | 
|---|
| 572 |   
 | 
|---|
| 573 |   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());
 | 
|---|
| 574 |   
 | 
|---|
| 575 |   updateV4L1Controls();
 | 
|---|
| 576 |   
 | 
|---|
| 577 |   if (v4l_pwc->setFrameRate( (int) FrameRateN[0].value, errmsg) < 0)
 | 
|---|
| 578 |   {
 | 
|---|
| 579 |     FrameRateNP.s = IPS_ALERT;
 | 
|---|
| 580 |     IDSetNumber(&FrameRateNP, "%s", errmsg);
 | 
|---|
| 581 |   }
 | 
|---|
| 582 |   else
 | 
|---|
| 583 |   {
 | 
|---|
| 584 |     FrameRateNP.s = IPS_OK;
 | 
|---|
| 585 |     IDSetNumber(&FrameRateNP, NULL);
 | 
|---|
| 586 |   }
 | 
|---|
| 587 |   
 | 
|---|
| 588 |   result = v4l_pwc->getBackLight();
 | 
|---|
| 589 |   if (result)
 | 
|---|
| 590 |   {
 | 
|---|
| 591 |    BackLightS[0].s = ISS_ON;
 | 
|---|
| 592 |    BackLightS[1].s = ISS_OFF;
 | 
|---|
| 593 |   }
 | 
|---|
| 594 |   else
 | 
|---|
| 595 |   {
 | 
|---|
| 596 |    BackLightS[0].s = ISS_OFF;
 | 
|---|
| 597 |    BackLightS[1].s = ISS_ON;
 | 
|---|
| 598 |   }
 | 
|---|
| 599 |   IDSetSwitch(&BackLightSP, NULL);
 | 
|---|
| 600 |   
 | 
|---|
| 601 |   result = v4l_pwc->getFlicker();
 | 
|---|
| 602 |   if (result)
 | 
|---|
| 603 |   {
 | 
|---|
| 604 |     AntiFlickerS[0].s = ISS_ON;
 | 
|---|
| 605 |     AntiFlickerS[1].s = ISS_OFF;
 | 
|---|
| 606 |   }
 | 
|---|
| 607 |   else
 | 
|---|
| 608 |   {
 | 
|---|
| 609 |     AntiFlickerS[0].s = ISS_OFF;
 | 
|---|
| 610 |     AntiFlickerS[1].s = ISS_ON;
 | 
|---|
| 611 |   }
 | 
|---|
| 612 |   IDSetSwitch(&AntiFlickerSP, NULL);
 | 
|---|
| 613 |   
 | 
|---|
| 614 |   index = v4l_pwc->getNoiseRemoval();
 | 
|---|
| 615 |   IUResetSwitch(&NoiseReductionSP);
 | 
|---|
| 616 |   NoiseReductionS[index].s = ISS_ON;
 | 
|---|
| 617 |   IDSetSwitch(&NoiseReductionSP, NULL);
 | 
|---|
| 618 |   
 | 
|---|
| 619 |   index = v4l_pwc->getWhiteBalance();
 | 
|---|
| 620 |   IUResetSwitch(&WhiteBalanceModeSP);
 | 
|---|
| 621 |   switch (index)
 | 
|---|
| 622 |   {
 | 
|---|
| 623 |     case PWC_WB_AUTO:
 | 
|---|
| 624 |      WhiteBalanceModeS[0].s = ISS_ON;
 | 
|---|
| 625 |      break;
 | 
|---|
| 626 |     case PWC_WB_MANUAL:
 | 
|---|
| 627 |      WhiteBalanceModeS[1].s = ISS_ON;
 | 
|---|
| 628 |      break;
 | 
|---|
| 629 |     case PWC_WB_INDOOR:
 | 
|---|
| 630 |      WhiteBalanceModeS[2].s = ISS_ON;
 | 
|---|
| 631 |      break;
 | 
|---|
| 632 |     case PWC_WB_OUTDOOR:
 | 
|---|
| 633 |      WhiteBalanceModeS[3].s = ISS_ON;
 | 
|---|
| 634 |      break;
 | 
|---|
| 635 |     case PWC_WB_FL:
 | 
|---|
| 636 |      WhiteBalanceModeS[3].s = ISS_ON;
 | 
|---|
| 637 |      break;
 | 
|---|
| 638 |   }
 | 
|---|
| 639 |   IDSetSwitch(&WhiteBalanceModeSP, NULL);    
 | 
|---|
| 640 |   
 | 
|---|
| 641 | }
 | 
|---|
| 642 | #endif
 | 
|---|
| 643 | 
 | 
|---|
| 644 | #ifndef HAVE_LINUX_VIDEODEV2_H
 | 
|---|
| 645 | void V4L_Philips::updateV4L1Controls()
 | 
|---|
| 646 | {
 | 
|---|
| 647 |   int index =0;
 | 
|---|
| 648 | 
 | 
|---|
| 649 |   ImageAdjustN[0].value = v4l_pwc->getContrast() / 256.;
 | 
|---|
| 650 |   ImageAdjustN[1].value = v4l_pwc->getBrightness() / 256.;
 | 
|---|
| 651 |   ImageAdjustN[2].value = v4l_pwc->getColor() / 256.;
 | 
|---|
| 652 |   index = v4l_pwc->getSharpness();
 | 
|---|
| 653 |   if (index < 0)
 | 
|---|
| 654 |         ImageAdjustN[3].value = -1;
 | 
|---|
| 655 |   else
 | 
|---|
| 656 |     ImageAdjustN[3].value = v4l_pwc->getSharpness() / 256.;
 | 
|---|
| 657 |     
 | 
|---|
| 658 |   ImageAdjustN[4].value = v4l_pwc->getGain() / 256.;
 | 
|---|
| 659 |   ImageAdjustN[5].value = v4l_pwc->getGama() / 256.;
 | 
|---|
| 660 |        
 | 
|---|
| 661 |   ImageAdjustNP.s = IPS_OK;
 | 
|---|
| 662 |   IDSetNumber(&ImageAdjustNP, NULL);
 | 
|---|
| 663 | 
 | 
|---|
| 664 | 
 | 
|---|
| 665 | }
 | 
|---|
| 666 | #endif
 | 
|---|
| 667 | 
 | 
|---|