Instrument Neutral Distributed Interface INDI 2.2.5
v4l2driver.h
Go to the documentation of this file.
1#if 0
2V4L2 INDI Driver
3INDI Interface for V4L2 devices
4Copyright (C) 2003 - 2005 Jasem Mutlaq ([email protected])
5 Copyright (C) 2013 Geehalel ([email protected])
6
7 This library is free software;
8you can redistribute it and / or
9modify it under the terms of the GNU Lesser General Public
10License as published by the Free Software Foundation;
11either
12version 2.1 of the License, or (at your option) any later version.
13
14This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY;
16without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18Lesser General Public License for more details.
19
20You should have received a copy of the GNU Lesser General Public
21License along with this library;
22if not, write to the Free Software
23Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 - 1301 USA
24
25#endif
26
27#pragma once
28
29#include "indiccd.h"
30#include "webcam/v4l2_base.h"
31
32#define IMAGE_CONTROL "Image Control"
33#define IMAGE_GROUP "V4L2 Control"
34#define IMAGE_BOOLEAN "V4L2 Options"
35#define CAPTURE_FORMAT "Capture Options"
36
37#define MAX_PIXELS 4096 /* Max number of pixels in one dimension */
38#define ERRMSGSIZ 1024
39
40#define TEMPFILE_LEN 16
41
42#ifdef __FreeBSD__
43typedef unsigned long ulong;
44#endif
45
46class Lx;
47
48// Pixel size info for different cameras
49typedef struct PixelSizeInfo
50{
51 const char * deviceLabel; // Device label used by INDI
52 const char * deviceName; // device name reported by V4L
53 const char * commonName; // if null, use device name
55 float pixelSizeY; // if negative, use pixelSizeX also for Y
56 uint32_t width; // Default width, if 0 then don't set anything
57 uint32_t height; // Default height, if 0 then don't set anything
58 bool tested; //if False print please report message
60
61class V4L2_Driver : public INDI::CCD
62{
63public:
65 explicit V4L2_Driver(std::string label, std::string path);
66 virtual ~V4L2_Driver() override;
67
68 /* INDI Functions that must be called from indidrivermain */
69 virtual void ISGetProperties(const char *dev) override;
70 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
71 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
72 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
73
74 virtual bool initProperties() override;
75 virtual bool updateProperties() override;
76 virtual void initCamBase();
77
78 static void newFrame(void *p);
79 void stackFrame();
80 void newFrame();
81
82 protected:
83 virtual bool Connect() override;
84 virtual bool Disconnect() override;
85
86 virtual const char *getDefaultName() override;
87 virtual bool StartExposure(float duration) override;
88 virtual bool AbortExposure() override;
89 virtual bool UpdateCCDFrame(int x, int y, int w, int h) override;
90 virtual bool UpdateCCDBin(int hor, int ver) override;
91 virtual bool SetCaptureFormat(uint8_t index) override;
92 virtual bool saveConfigItems(FILE *fp) override;
93
94 virtual bool StartStreaming() override;
95 virtual bool StopStreaming() override;
96
97 bool updateCaptureSize(uint32_t width, uint32_t height);
98
99 /* Structs */
100 typedef struct
101 {
102 int width;
104 int bpp;
105 //int expose;
106 double expose;
107 unsigned char *Y;
108 unsigned char *U;
109 unsigned char *V;
110 unsigned char *RGB24Buffer;
111 unsigned char *compressedFrame;
113 float *darkFrame;
114 } img_t;
115
116 enum
117 {
120 };
121
130
131 /* Switches */
132
135
136 /* Texts */
140
141 /* Numbers */
142 //INumber *ExposeTimeN;
145
146 /* Switch vectors */
147 ISwitchVectorProperty ImageDepthSP; /* 8 bits or 16 bits switch */
148 INDI::PropertySwitch StackModeSP {5}; /* StackMode switch */
149 ISwitchVectorProperty InputsSP; /* Select input switch */
150 ISwitchVectorProperty CaptureFormatsSP; /* Select Capture format switch */
151 ISwitchVectorProperty CaptureSizesSP; /* Select Capture size switch (Discrete)*/
152 ISwitchVectorProperty FrameRatesSP; /* Select Frame rate (Discrete) */
155
156 unsigned int v4loptions;
157 unsigned int v4ladjustments;
159
160 /* Number vectors */
161 //INumberVectorProperty *ExposeTimeNP; /* Exposure */
162 INumberVectorProperty CaptureSizesNP; /* Select Capture size switch (Step/Continuous)*/
163 INumberVectorProperty FrameRateNP; /* Frame rate (Step/Continuous) */
165
166 /* Text vectors */
170
171 /* Pointers to optional properties */
174
175 /* Initialization functions */
176 //virtual void connectCamera();
177 virtual void getBasicData();
178 bool getPixelFormat(uint32_t v4l2format, INDI_PIXEL_FORMAT &pixelFormat, uint8_t &pixelDepth);
179 void allocateBuffers();
180 void releaseBuffers();
181 void updateFrameSize();
182
183 /* Shutter control */
184 bool setShutter(double duration);
185 bool setManualExposure(double duration);
186 bool startlongexposure(double timeinsec);
187 static void lxtimerCallback(void *userpointer);
188 static void stdtimerCallback(void *userpointer);
190
191 /* start/stop functions */
192 bool start_capturing(bool do_stream);
193 bool stop_capturing();
194
195 virtual void updateV4L2Controls();
196
197 bool isIOptron();
198
199 void resetDevice(int bus_num, int dev_num);
200
201 /* Variables */
203
205
206 int subframeCount; /* For stacking */
208 double divider; /* For limits */
209 img_t *V4LFrame; /* Video frame */
210
211 struct timeval capture_start; /* To calculate how long a frame take */
212
213 //struct timeval capture_end;
214
215 struct timeval frame_duration;
216 struct timeval frame_received;
217
218 struct timeval exposure_duration;
219 struct timeval elapsed_exposure;
220
221 struct timeval getElapsedExposure() const;
222 float getRemainingExposure() const;
223
224 unsigned int m_StackMode;
226 unsigned int non_capture_frames;
231
232 //Long Exposure
237
238 short lxstate;
240
241 char defaultVideoPort[256] = {"/dev/video0"};
242 char configPort[256] = {0};
243};
Class to provide general functionality of CCD cameras with a single CCD sensor, or a primary CCD sens...
Definition indiccd.h:108
The Timer class provides repetitive and single-shot timers.
Definition inditimer.h:41
Definition Lx.h:24
bool setManualExposure(double duration)
ITextVectorProperty camNameTP
Definition v4l2driver.h:168
virtual bool StopStreaming() override
StopStreaming Stop live video streaming.
unsigned int v4loptions
Definition v4l2driver.h:156
virtual const char * getDefaultName() override
virtual bool StartStreaming() override
StartStreaming Start live video streaming.
ITextVectorProperty CaptureColorSpaceTP
Definition v4l2driver.h:169
INDI::PropertySwitch StackModeSP
Definition v4l2driver.h:148
INumberVectorProperty FrameRateNP
Definition v4l2driver.h:163
virtual void getBasicData()
PixelSizeInfo * m_Info
Definition v4l2driver.h:239
struct timeval getElapsedExposure() const
struct timeval exposure_duration
Definition v4l2driver.h:218
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
INumberVectorProperty CaptureSizesNP
Definition v4l2driver.h:162
struct timeval frame_received
Definition v4l2driver.h:216
bool setShutter(double duration)
double divider
Definition v4l2driver.h:208
ISwitchVectorProperty FrameRatesSP
Definition v4l2driver.h:152
INumber FrameRateN[1]
Definition v4l2driver.h:144
virtual void updateV4L2Controls()
virtual bool Disconnect() override
Disconnect from device.
void resetDevice(int bus_num, int dev_num)
INumberVectorProperty ImageAdjustNP
Definition v4l2driver.h:164
ISwitchVectorProperty InputsSP
Definition v4l2driver.h:149
unsigned int m_StackMode
Definition v4l2driver.h:224
bool startlongexposure(double timeinsec)
char configPort[256]
Definition v4l2driver.h:242
bool useExtCtrl
Definition v4l2driver.h:158
ISwitchVectorProperty CaptureFormatsSP
Definition v4l2driver.h:150
bool isIOptron()
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool UpdateCCDFrame(int x, int y, int w, int h) override
CCD calls this function when CCD Frame dimension needs to be updated in the hardware....
IText camNameT[1]
Definition v4l2driver.h:138
ITextVectorProperty PortTP
Definition v4l2driver.h:167
void releaseBuffers()
virtual void initCamBase()
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
void allocateBuffers()
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool AbortExposure() override
Abort ongoing exposure.
ISwitchVectorProperty ImageDepthSP
Definition v4l2driver.h:147
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool StartExposure(float duration) override
Start exposing primary CCD chip.
ulong frameBytes
Definition v4l2driver.h:225
char defaultVideoPort[256]
Definition v4l2driver.h:241
bool valid_frame_has_arrived
Definition v4l2driver.h:230
bool stop_capturing()
void stackFrame()
unsigned int non_capture_frames
Definition v4l2driver.h:226
INumber * AbsExposureN
Definition v4l2driver.h:172
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
struct timeval frame_duration
Definition v4l2driver.h:215
bool v4l_capture_started
Definition v4l2driver.h:227
struct timeval capture_start
Definition v4l2driver.h:211
ISwitchVectorProperty CaptureSizesSP
Definition v4l2driver.h:151
img_t * V4LFrame
Definition v4l2driver.h:209
bool updateCaptureSize(uint32_t width, uint32_t height)
struct timeval elapsed_exposure
Definition v4l2driver.h:219
int subframeCount
Definition v4l2driver.h:206
bool is_exposing
Definition v4l2driver.h:229
ISwitchVectorProperty ColorProcessingSP
Definition v4l2driver.h:154
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
ISwitchVectorProperty * ManualExposureSP
Definition v4l2driver.h:173
ISwitch ImageDepthS[2]
Definition v4l2driver.h:133
void iOptronWatchdogCallback()
INumber * FrameN
Definition v4l2driver.h:143
virtual ~V4L2_Driver() override
virtual bool UpdateCCDBin(int hor, int ver) override
CCD calls this function when CCD Binning needs to be updated in the hardware. Derived classes should ...
INDI::Timer ioptron_watchdog_timer
Definition v4l2driver.h:236
IText CaptureColorSpaceT[3]
Definition v4l2driver.h:139
bool start_capturing(bool do_stream)
void updateFrameSize()
IText PortT[1]
Definition v4l2driver.h:137
short lxstate
Definition v4l2driver.h:238
virtual bool SetCaptureFormat(uint8_t index) override
SetCaptureFormat Set Active Capture format.
INDI::V4L2_Base * v4l_base
Definition v4l2driver.h:202
static void stdtimerCallback(void *userpointer)
unsigned int v4ladjustments
Definition v4l2driver.h:157
bool getPixelFormat(uint32_t v4l2format, INDI_PIXEL_FORMAT &pixelFormat, uint8_t &pixelDepth)
float getRemainingExposure() const
static void lxtimerCallback(void *userpointer)
char device_name[MAXINDIDEVICE]
Definition v4l2driver.h:204
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save configuration items in XML file.
ISwitch ColorProcessingS[3]
Definition v4l2driver.h:134
bool is_capturing
Definition v4l2driver.h:228
ISwitchVectorProperty * Options
Definition v4l2driver.h:153
ISState
Switch state.
Definition indiapi.h:148
#define MAXINDIDEVICE
Definition indiapi.h:191
INDI_PIXEL_FORMAT
Namespace to encapsulate INDI client, drivers, and mediator classes.
One number descriptor.
One switch descriptor.
One text descriptor.
uint32_t width
Definition v4l2driver.h:56
uint32_t height
Definition v4l2driver.h:57
const char * deviceName
Definition v4l2driver.h:52
const char * commonName
Definition v4l2driver.h:53
float pixelSizeX
Definition v4l2driver.h:54
const char * deviceLabel
Definition v4l2driver.h:51
float pixelSizeY
Definition v4l2driver.h:55
unsigned char * RGB24Buffer
Definition v4l2driver.h:110
unsigned char * compressedFrame
Definition v4l2driver.h:111
unsigned char * Y
Definition v4l2driver.h:107
unsigned char * U
Definition v4l2driver.h:108
unsigned char * V
Definition v4l2driver.h:109
Number vector property descriptor.
Definition indiapi.h:317
Switch vector property descriptor.
Definition indiapi.h:365
Text vector property descriptor.
Definition indiapi.h:244