Callback

samples/callback.cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
 * Sample code for callback usage.
 */
#include <cepton_sdk_api.hpp>

// Sample global callback.
void on_image_frame(cepton_sdk::SensorHandle handle, std::size_t n_points,
                    const cepton_sdk::SensorImagePoint *c_image_points) {
  // Handle frame...
}

// Sample member callback.
class FramesListener {
 public:
  void on_image_frame(cepton_sdk::SensorHandle handle, std::size_t n_points,
                      const cepton_sdk::SensorImagePoint *c_image_points) {
    // Handle frame...
  }
};

int main(int argc, char **argv) {
  // Initialize
  CEPTON_CHECK_ERROR(cepton_sdk::api::initialize());
  cepton_sdk::api::SensorImageFrameCallback callback;
  CEPTON_CHECK_ERROR(callback.initialize());

  // Listen lambda
  CEPTON_CHECK_ERROR(
      callback.listen([](cepton_sdk::SensorHandle handle, std::size_t n_points,
                         const cepton_sdk::SensorImagePoint *c_image_points) {
        //  Handle frame...
      }));

  // Listen global function
  CEPTON_CHECK_ERROR(callback.listen(on_image_frame));

  // Listen member function
  FramesListener frames_listener;
  CEPTON_CHECK_ERROR(
      callback.listen(&frames_listener, &FramesListener::on_image_frame));

  // Deinitialize
  cepton_sdk::deinitialize().ignore();
}