Skip to content

Commit a98a856

Browse files
committed
Add open/close function to SensorCapture (extracted from destructor and
initializer)
1 parent 59d31e3 commit a98a856

File tree

4 files changed

+30
-24
lines changed

4 files changed

+30
-24
lines changed

examples/zed_oc_sync_example.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ uint64_t mcu_sync_ts=0;
5252
int main(int argc, char *argv[])
5353
{
5454
// Set the verbose level
55-
sl_oc::VERBOSITY verbose = sl_oc::VERBOSITY::ERROR;
55+
sl_oc::VERBOSITY verbose = sl_oc::VERBOSITY::INFO;
5656

5757
// ----> Set the video parameters
5858
sl_oc::video::VideoParams params;

include/sensorcapture.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ class SL_OC_EXPORT SensorCapture
148148

149149
/*!
150150
* \brief Get the list of the serial number of all the available devices
151+
* \param refresh if true USB device tree is parsed to search for modifications (new device connected/disconnected)
151152
* \return a vector containing the serial number of all the available devices
152153
*/
153-
std::vector<int> getDeviceList();
154+
std::vector<int> getDeviceList(bool refresh=false);
154155

155156
/*!
156157
* \brief Open a connection to the MCU of a ZED Mini or a ZED2 camera using the specified serial number or searching
@@ -204,14 +205,16 @@ class SL_OC_EXPORT SensorCapture
204205
#ifdef VIDEO_MOD_AVAILABLE
205206
void updateTimestampOffset(uint64_t frame_ts); //!< Called by VideoCapture to update timestamp offset
206207
inline void setStartTimestamp(uint64_t start_ts){mStartSysTs=start_ts;} //!< Called by VideoCapture to sync timestamps reference point
207-
inline void setVideoPtr(video::VideoCapture* videoPtr){mVideoPtr=videoPtr;} //!< Called by VideoCapture to set the pointer to it
208+
inline void setVideoPtr(video::VideoCapture* videoPtr){mVideoPtr=videoPtr;} //!< Called by VideoCapture to set the pointer to it
208209
#endif
209210

210211
private:
211212
void grabThreadFunc(); //!< The sensor data grabbing thread function
212213

213214
bool startCapture(); //!< Start data capture thread
214-
void reset(); //!< Reset connection
215+
216+
bool open(uint16_t pid, int serial_number); //!< Open the USB connection
217+
void close(); //!< Close the USB connection
215218

216219
int enumerateDevices(); //!< Populates the mSlDevPid map with serial number and PID of the available devices
217220

src/sensorcapture.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ SensorCapture::SensorCapture(VERBOSITY verbose_lvl )
5050

5151
SensorCapture::~SensorCapture()
5252
{
53-
reset();
53+
close();
5454
}
5555

5656
int SensorCapture::enumerateDevices()
@@ -85,7 +85,7 @@ int SensorCapture::enumerateDevices()
8585
smsg << " Serial_number: " << sn_str << std::endl;
8686
smsg << " Manufacturer: " << wstr2str(cur_dev->manufacturer_string) << std::endl;
8787
smsg << " Product: " << wstr2str(cur_dev->product_string) << std::endl;
88-
smsg << " Release number: v" << fw_major << "." << fw_minor << std::endl;
88+
smsg << " Release number: v" << std::dec << fw_major << "." << fw_minor << std::endl;
8989
smsg << "***" << std::endl;
9090

9191
INFO_OUT(mVerbose,smsg.str());
@@ -99,9 +99,9 @@ int SensorCapture::enumerateDevices()
9999
return mSlDevPid.size();
100100
}
101101

102-
std::vector<int> SensorCapture::getDeviceList()
102+
std::vector<int> SensorCapture::getDeviceList(bool refresh)
103103
{
104-
if(mSlDevPid.size()==0)
104+
if(mSlDevPid.size()==0 || refresh)
105105
enumerateDevices();
106106

107107
std::vector<int> sn_vec;
@@ -113,6 +113,20 @@ std::vector<int> SensorCapture::getDeviceList()
113113
return sn_vec;
114114
}
115115

116+
bool SensorCapture::open( uint16_t pid, int serial_number)
117+
{
118+
std::string sn_str = std::to_string(serial_number);
119+
std::wstring wide_sn_string = std::wstring(sn_str.begin(), sn_str.end());
120+
121+
const wchar_t* wsn = wide_sn_string.c_str();
122+
123+
mDevHandle = hid_open(SL_USB_VENDOR, pid, wsn );
124+
125+
if(mDevHandle) mDevSerial = serial_number;
126+
127+
return mDevHandle!=0;
128+
}
129+
116130
bool SensorCapture::initializeSensors( int sn )
117131
{
118132
if(mSlDevPid.size()==0)
@@ -122,9 +136,7 @@ bool SensorCapture::initializeSensors( int sn )
122136

123137
std::string sn_str;
124138

125-
if(sn!=-1)
126-
sn_str = std::to_string(sn);
127-
else
139+
if(sn==-1)
128140
{
129141
if(mSlDevPid.size()==0)
130142
{
@@ -138,19 +150,11 @@ bool SensorCapture::initializeSensors( int sn )
138150
}
139151

140152
sn = mSlDevPid.begin()->first;
141-
sn_str = std::to_string(sn);
142153
}
143154

144-
mDevSerial = sn;
145-
146-
std::wstring wide_string = std::wstring(sn_str.begin(), sn_str.end());
147-
const wchar_t* wsn = wide_string.c_str();
148-
149155
uint16_t pid = mSlDevPid[sn];
150156

151-
mDevHandle = hid_open(SL_USB_VENDOR, pid, wsn );
152-
153-
if (!mDevHandle)
157+
if(!open( pid,sn))
154158
{
155159
std::string msg = "Connection to device with sn ";
156160
msg += sn_str;
@@ -269,7 +273,7 @@ bool SensorCapture::startCapture()
269273
return true;
270274
}
271275

272-
void SensorCapture::reset()
276+
void SensorCapture::close()
273277
{
274278
mStopCapture = true;
275279

@@ -343,7 +347,7 @@ void SensorCapture::grabThreadFunc()
343347

344348
// ----> Received data are correct?
345349
int target_struct_id = 0;
346-
if (mDevPid==SL_USB_PROD_MCU_ZED2_REVA)
350+
if (mDevPid==SL_USB_PROD_MCU_ZED2_REVA || mDevPid==SL_USB_PROD_MCU_ZED2i_REVA)
347351
target_struct_id = usb::REP_ID_SENSOR_DATA;
348352

349353
if( usbBuf[0] != target_struct_id)

src/videocapture.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,6 @@ void VideoCapture::ll_activate_sync()
13761376
uint8_t sync_val_right = 0x0;
13771377

13781378
// Activate VSYNC output for both camera sensors
1379-
13801379
if (ll_read_sensor_register(0, 1, 0x3002, &sync_val_left) == 0)
13811380
{
13821381
sync_val_left = sync_val_left | 0x80;
@@ -1388,7 +1387,7 @@ void VideoCapture::ll_activate_sync()
13881387
{
13891388
sync_val_right = sync_val_right | 0x80;
13901389

1391-
ll_write_sensor_register(1, 1, 0x3002, sync_val_left);
1390+
ll_write_sensor_register(1, 1, 0x3002, sync_val_right);
13921391
}
13931392
}
13941393

0 commit comments

Comments
 (0)