Instrument Neutral Distributed Interface INDI  2.0.2
indi_v4l2driver.cpp
Go to the documentation of this file.
1 #if 0
2 V4L Philips LX INDI Driver
3 INDI Interface for V4L devices (Philips)
4  Copyright (C) 2003 - 2005 Jasem Mutlaq (mutlaqja@ikarustech.com)
5 
6  This library is free software;
7 you can redistribute it and / or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation;
10 either
11 version 2.1 of the License, or (at your option) any later version.
12 
13 This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY;
15 without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library;
21 if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 - 1301 USA
23 
24 #endif
25 
26 #include "v4l2driver.h"
27 
28 static class Loader
29 {
30  std::unique_ptr<V4L2_Driver> MainCam;
31  // Map of Common Name (as detected from query camera capability cap.card) and driver name (used by INDI driver label).
32  // V42L Name : Driver Name
33  std::map<std::string, std::string> driverMap =
34  {
35  {"NexImage 5", "NexImage 5"},
36  {"UVC Camera (046d:0809)", "Logitech Webcam Pro 9000"},
37  {"SVBONY SV105: SVBONY SV105", "SVBONY SV105"},
38  {"SVBONY SV205: SVBONY SV205", "SVBONY SV205"},
39  {"NexImage 10", "NexImage 10"},
40  {"NexImage Burst Color", "NexImage Burst Color"},
41  {"NexImage Burst Mono", "NexImage Burst Mono"},
42  {"Skyris 132C", "Skyris 132C"},
43  {"Skyris 132M", "Skyris 132M"},
44  {"Skyris 236C", "Skyris 236C"},
45  {"Skyris 236M", "Skyris 236M"},
46  {"iOptron iPolar: iOptron iPolar", "iOptron iPolar"},
47  {"iOptron iPolar", "iOptron iPolar"},
48  {"iOptron iGuider: iOptron iGuide", "iOptron iGuider"},
49  {"iOptron iGuider 1", "iOptron iGuider"},
50  {"mmal service 16.1", "Raspberry Pi High Quality Camera"},
51  {"UVC Camera (046d:0825)", "Logitech HD C270"},
52  {"USB 2.0 Camera: USB Camera", "IMX290 Camera"},
53  {"0c45:6366 Microdia", "IMX290 H264 Camera"},
54  {"Microsoft® LifeCam Cinema(TM):", "Microsoft LifeCam Cinema"}
55  };
56  public:
57  Loader()
58  {
59  // We have two structures
60  // driverMap is a map of common_name:driver_label
61  // devices is a map of common_name:device_path as detected by INDI.
62  // Goal is to create a driver with driver_label that opens a device at device_path
63 
64  // Enumerate all video devices, we get a map of common_name:device_path
65  std::map<std::string, std::string> devices = INDI::V4L2_Base::enumerate();
66  // Get environment device name and let's see if this is a generic driver or meant for a specific device.
67  const char *envDevice = getenv("INDIDEV");
68  auto isDefaultCamera = envDevice == nullptr || !strcmp(envDevice, "V4L2 CCD");
69 
70  auto targetDriver = std::make_pair(std::string("V4L2 CCD"), std::string("/dev/video0"));
71  // If we are not using default camera, find if any of enumerated devices matches any device in our known
72  // driver map
73  if (!isDefaultCamera)
74  {
75  // Check if the driver is supported.
76  for (const auto &oneDriver : driverMap)
77  {
78  // Does our desired INDIDEV driver label match this driver label?
79  if (envDevice == oneDriver.second)
80  {
81  // Found the right driver, now lets see if any of the enumerated devices
82  // match the same driver common name.
83  auto match = devices.find(oneDriver.first);
84  if (match != devices.end())
85  {
86  // Driver Label / Device Path
87  targetDriver = std::make_pair(oneDriver.second, (*match).second);
88  break;
89  }
90  }
91  }
92  }
93 
94  if (targetDriver.first == "V42L CCD")
95  MainCam.reset(new V4L2_Driver());
96  else
97  MainCam.reset(new V4L2_Driver(targetDriver.first.c_str(), targetDriver.second.c_str()));
98 
99  MainCam->initCamBase();
100  }
101  } loader;
static std::map< std::string, std::string > enumerate()
Definition: v4l2_base.cpp:2991
Namespace to encapsulate INDI client, drivers, and mediator classes.