Doly C++ SDK v1.00
Loading...
Searching...
No Matches
EdgeControl/main.cpp

Demonstrates:

  • Initializing EdgeControl
  • Receiving edge sensor events
  • Handling edge detection callbacks
#include <chrono>
#include <thread>
#include <spdlog/spdlog.h>
#include "EdgeControl.h"
#include "Helper.h"
void onEdgeChange(std::vector<IrSensor> sensors)
{
spdlog::info("Edge Change Detected:");
for (IrSensor sensor : sensors)
{
spdlog::info("Sensor id: {} state: {}", static_cast<uint8_t>(sensor.id), static_cast<uint8_t>(sensor.state));
}
}
int main()
{
// Setup spdlog
spdlog::set_level(spdlog::level::info); // Set as needed
spdlog::flush_on(spdlog::level::trace); // flush everything
// *** IMPORTANT ***
// Stop doly service if running,
// otherwise instance of libraries cause conflict
spdlog::error("Doly service stop failed");
return -1;
}
// Initialize Edge Control
if (EdgeControl::init() < 0)
{
spdlog::error("EdgeControl init failed");
return -2;
}
// get EdgeControl version
spdlog::info("EdgeControl Version:{:.3f}", EdgeControl::getVersion());
// Add event listener for edge changes
// Run for 20 seconds to test edge detection
std::this_thread::sleep_for(std::chrono::seconds(20));
// Cleanup
return 0;
}
Public API for Doly edge/gap detection control (IR sensors).
Shared helper utilities and common types used across the Doly SDK.
float getVersion()
Get current library version.
int8_t init()
Initialize edge sensor control.
int8_t dispose()
Dispose edge sensor control and release resources.
void AddListenerOnChange(void(*onChange)(std::vector< IrSensor > sensors))
Register a function callback for sensor state changes.
void RemoveListenerOnChange(void(*onChange)(std::vector< IrSensor > sensors))
Unregister a function callback for sensor state changes.
int8_t stopDolyService()
Stop the background Doly service (if running).
Simple POD representing the state of an individual IR sensor.
Definition EdgeEventListener.h:66