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

Demonstrates:

  • Initializing LedControl
  • Controlling LED states and colors
  • Receiving LED-related events
#include <chrono>
#include <thread>
#include <spdlog/spdlog.h>
#include "LedControl.h"
#include "Color.h"
#include "Helper.h"
void onLedComplete(uint16_t id, LedSide side)
{
spdlog::info("Led Complete: ID:{} Side:{}", id, static_cast<uint8_t>(side));
}
void onLedError(uint16_t id, LedSide side, LedErrorType type)
{
spdlog::error("Led Error: ID:{} Side:{} Type:{}", id, static_cast<uint8_t>(side), static_cast<uint8_t>(type));
}
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 LED Control
if (LedControl::init() < 0)
{
spdlog::error("LedControl init failed");
return -2;
}
// get LedControl version
spdlog::info("LedControl Version:{:.3f}", LedControl::getVersion());
// Add event listeners
// Fade example
LedActivity activity1;
activity1.fade_time = 2000; // 2 seconds
// Let the activity run for a while on another thread
std::this_thread::sleep_for(std::chrono::milliseconds(2500));
// Change to solid color instantly
LedActivity activity2;
activity2.fade_time = 0; //
// Cleanup
return 0;
}
Color utilities and predefined color codes used across the Doly SDK.
Shared helper utilities and common types used across the Doly SDK.
Public API for Doly LED control.
LedErrorType
Error type reported by the LED subsystem.
Definition LedEventListener.h:54
LedSide
Which LED(s) to address.
Definition LedEventListener.h:28
@ RIGHT
Definition LedEventListener.h:34
@ BOTH
Definition LedEventListener.h:30
@ BLUE
Definition Color.h:49
@ ORANGE
Definition Color.h:39
@ RED
Definition Color.h:36
int8_t stopDolyService()
Stop the background Doly service (if running).
float getVersion()
Get current library version.
int8_t dispose()
Stop the worker thread and release resources.
void processActivity(uint16_t id, LedSide side, LedActivity activity)
Set a LED activity to be processed asynchronously.
int8_t init()
Initialize the LED subsystem.
void RemoveListenerOnComplete(void(*onEvent)(uint16_t id, LedSide side))
Unregister a previously registered completion callback.
void RemoveListenerOnError(void(*onError)(uint16_t id, LedSide side, LedErrorType type))
Unregister a previously registered error callback.
void AddListenerOnComplete(void(*onEvent)(uint16_t id, LedSide side))
Register a static/free function to receive completion events.
void AddListenerOnError(void(*onError)(uint16_t id, LedSide side, LedErrorType type))
Register a static/free function to receive error events.
static Color getColor(uint8_t r, uint8_t g, uint8_t b)
Construct a Color from explicit RGB values.
Describes a single LED activity (color and fade parameters).
Definition LedEventListener.h:66
uint16_t fade_time
Definition LedEventListener.h:72
Color fadeColor
Definition LedEventListener.h:70
Color mainColor
Definition LedEventListener.h:68