Proposal for the bind interface
This commit is contained in:
committed by
diegoalonso29
parent
daf849ef45
commit
5f0e3fd0cd
@@ -222,6 +222,11 @@ void OnDeviceInfoChange(const DeviceInfo *info, DeviceEvent type) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnDeviceInfoChangeExtra(int param, const DeviceInfo *info, DeviceEvent type) {
|
||||||
|
// ... Do stuff with the extra param
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Callback function when broadcast message received.
|
/** Callback function when broadcast message received.
|
||||||
* You need to add listening device broadcast code and set the point cloud data callback in this function.
|
* You need to add listening device broadcast code and set the point cloud data callback in this function.
|
||||||
*/
|
*/
|
||||||
@@ -238,6 +243,15 @@ void OnDeviceBroadcast(const BroadcastDeviceInfo *info) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct OptBcast{
|
||||||
|
int a;
|
||||||
|
int b;
|
||||||
|
};
|
||||||
|
|
||||||
|
void OnDeviceBroadcastExtra(OptBcast o, const BroadcastDeviceInfo *info) {
|
||||||
|
// ... Do stuff with the extra param
|
||||||
|
}
|
||||||
|
|
||||||
/** Wait until no new device arriving in 2 second. */
|
/** Wait until no new device arriving in 2 second. */
|
||||||
void WaitForDevicesReady( ) {
|
void WaitForDevicesReady( ) {
|
||||||
bool device_ready = false;
|
bool device_ready = false;
|
||||||
@@ -391,14 +405,19 @@ int main(int argc, const char *argv[]) {
|
|||||||
printf("Livox SDK version %d.%d.%d .\n", _sdkversion.major, _sdkversion.minor, _sdkversion.patch);
|
printf("Livox SDK version %d.%d.%d .\n", _sdkversion.major, _sdkversion.minor, _sdkversion.patch);
|
||||||
|
|
||||||
memset(devices, 0, sizeof(devices));
|
memset(devices, 0, sizeof(devices));
|
||||||
|
using namespace std::placeholders;
|
||||||
|
|
||||||
|
|
||||||
/** Set the callback function receiving broadcast message from Livox LiDAR. */
|
/** Set the callback function receiving broadcast message from Livox LiDAR. */
|
||||||
SetBroadcastCallback(OnDeviceBroadcast);
|
OptBcast bcastopts;
|
||||||
|
std::function<void(const BroadcastDeviceInfo *info)> cb_bcast(std::bind(OnDeviceBroadcastExtra, bcastopts, _1));
|
||||||
|
SetBroadcastCallback(cb_bcast);
|
||||||
|
|
||||||
/** Set the callback function called when device state change,
|
/** Set the callback function called when device state change,
|
||||||
* which means connection/disconnection and changing of LiDAR state.
|
* which means connection/disconnection and changing of LiDAR state.
|
||||||
*/
|
*/
|
||||||
SetDeviceStateUpdateCallback(OnDeviceInfoChange);
|
std::function<void(const DeviceInfo *, DeviceEvent)> cb_device_state(std::bind(OnDeviceInfoChangeExtra, 1, _1, _2));
|
||||||
|
SetDeviceStateUpdateCallback(cb_device_state);
|
||||||
|
|
||||||
/** Start the device discovering routine. */
|
/** Start the device discovering routine. */
|
||||||
if (!Start()) {
|
if (!Start()) {
|
||||||
|
|||||||
@@ -25,7 +25,10 @@
|
|||||||
#ifndef LIVOX_SDK_H_
|
#ifndef LIVOX_SDK_H_
|
||||||
#define LIVOX_SDK_H_
|
#define LIVOX_SDK_H_
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
#include<functional>
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -100,6 +103,8 @@ typedef void (*DeviceStateUpdateCallback)(const DeviceInfo *device, DeviceEvent
|
|||||||
*/
|
*/
|
||||||
void SetDeviceStateUpdateCallback(DeviceStateUpdateCallback cb);
|
void SetDeviceStateUpdateCallback(DeviceStateUpdateCallback cb);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a broadcast code to the connecting list and only devices with broadcast code in this list will be connected. The
|
* Add a broadcast code to the connecting list and only devices with broadcast code in this list will be connected. The
|
||||||
* broadcast code is unique for every device.
|
* broadcast code is unique for every device.
|
||||||
@@ -857,6 +862,11 @@ livox_status LidarSetUtcSyncTime(uint8_t handle,
|
|||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SetDeviceStateUpdateCallback(const std::function<void(const DeviceInfo *, DeviceEvent)> &cb);
|
||||||
|
void SetBroadcastCallback(const std::function<void(const BroadcastDeviceInfo *info)> &cb );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // LIVOX_SDK_H_
|
#endif // LIVOX_SDK_H_
|
||||||
|
|||||||
@@ -42,10 +42,18 @@ void SetDeviceStateUpdateCallback(DeviceStateUpdateCallback cb) {
|
|||||||
device_manager().SetDeviceConnectedCallback(cb);
|
device_manager().SetDeviceConnectedCallback(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetDeviceStateUpdateCallback(const std::function<void(const DeviceInfo *, DeviceEvent)> &cb){
|
||||||
|
device_manager().SetDeviceConnectedCallback(cb);
|
||||||
|
}
|
||||||
|
|
||||||
void SetBroadcastCallback(DeviceBroadcastCallback cb) {
|
void SetBroadcastCallback(DeviceBroadcastCallback cb) {
|
||||||
device_manager().SetDeviceBroadcastCallback(cb);
|
device_manager().SetDeviceBroadcastCallback(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetBroadcastCallback(const std::function<void(const BroadcastDeviceInfo *info)> &cb ){
|
||||||
|
device_manager().SetDeviceBroadcastCallback(cb);
|
||||||
|
}
|
||||||
|
|
||||||
livox_status AddHubToConnect(const char *broadcast_code, uint8_t *handle) {
|
livox_status AddHubToConnect(const char *broadcast_code, uint8_t *handle) {
|
||||||
bool result = device_manager().AddListeningDevice(broadcast_code, kDeviceModeHub, *handle);
|
bool result = device_manager().AddListeningDevice(broadcast_code, kDeviceModeHub, *handle);
|
||||||
if (result) {
|
if (result) {
|
||||||
|
|||||||
Reference in New Issue
Block a user