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