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

Demonstrates:

  • Initializing EyeControl
  • Loading and displaying visual content
  • Handling eye-related events
#include <chrono>
#include <thread>
#include <spdlog/spdlog.h>
#include <Helper.h>
#include <EyeControl.h>
#include <EyeEvent.h>
void onEyeStart(uint16_t id)
{
spdlog::info("Eye animation start id:{}", id);
}
void onEyeComplete(uint16_t id)
{
spdlog::info("Eye animation complete id:{}", id);
}
void onEyeAbort(uint16_t id)
{
spdlog::warn("Eye animation abort id:{}", id);
}
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;
}
// Get EyeControl version
spdlog::info("EyeControl Version:{:.3f}", EyeControl::getVersion());
// Register event listeners
// Initialize EyeControl
spdlog::error("EyeControl init failed");
return -2;
}
// Wait for a while before next example
std::this_thread::sleep_for(std::chrono::seconds(3));
// Example: Change iris
// Wait for a while before next example
std::this_thread::sleep_for(std::chrono::seconds(3));
// Example: Set Animation, animation works on different thread
// wait until animation complete
std::this_thread::sleep_for(std::chrono::milliseconds(10));
// Wait for a while before next example
std::this_thread::sleep_for(std::chrono::seconds(3));
// Example: Using custom images for lids, iris or background
// create a visual content and load image
VContent visual = VContent::getImage("/.doly/images/lids/11B.png", true, true);
if (!visual.isReady())
spdlog::error("image load failed!");
else
{
int ret = EyeControl::setLid(&visual, false, EyeSide::BOTH); // load content for bottom eyelid
if (ret < 0)
spdlog::error("Set eye lid failed err:{}", ret);
}
// Set eye position, scale iris, and set bottom lid position
EyeControl::setPosition(EyeSide::BOTH, 120, 120, 1.2, 1.2, 0, 180);
// Read iris position
int16_t x, y;
spdlog::info("Left iris postion: {},{}", x, y);
// Cleanup
return 0;
}
Public API for Doly eye display control and animations.
@ MODERN
Definition EyeControl.h:41
@ BOTH
Definition EyeControl.h:30
@ LEFT
Definition EyeControl.h:31
Event registration API for EyeControl.
Shared helper utilities and common types used across the Doly SDK.
Container class for visual (image/animation) content.
Definition VContent.h:31
bool isReady()
Check whether the visual content is loaded and ready.
static VContent getImage(std::string path, bool isRGBA, bool set12Bit)
Load a PNG image and create a VContent instance.
@ BLUE
Definition Color.h:49
@ WHITE
Definition Color.h:33
@ DARK_GREEN
Definition Color.h:46
int8_t setAnimation(uint16_t id, std::string_view name)
Start a named eye animation (non-blocking).
bool isAnimating()
Check whether an animation is currently running.
int8_t setLid(VContent *lid_image, bool isTop, EyeSide side)
Set eyelid image content for a given side.
float getVersion()
Get current library version.
int8_t setIris(IrisShape shape, ColorCode color, EyeSide side)
Set iris preset for a given side.
int8_t init(ColorCode eye_color, ColorCode bg_color)
Initialize the eye subsystem (LCD + eye assets).
int8_t getIrisPosition(EyeSide side, int16_t &x, int16_t &y)
Get the current iris center position for a given side.
int8_t setPosition(EyeSide side, int16_t centerX, int16_t centerY, float scaleX=1, float scaleY=1, uint8_t lid_top_end=0, uint8_t lid_bot_start=240)
Set iris position/scale and eyelid limits for a given side.
void AddListenerOnComplete(void(*onComplete)(uint16_t))
Register a static callback invoked when an eye action/animation completes.
void AddListenerOnStart(void(*onStart)(uint16_t))
Register a static callback invoked when an eye action/animation starts.
void RemoveListenerOnStart(void(*onStart)(uint16_t))
Unregister a previously added start callback.
void RemoveListenerOnAbort(void(*onAbort)(uint16_t))
Unregister a previously added abort callback.
void AddListenerOnAbort(void(*onAbort)(uint16_t))
Register a static callback invoked when an eye action/animation is aborted.
void RemoveListenerOnComplete(void(*onComplete)(uint16_t))
Unregister a previously added complete callback.
constexpr std::string_view EXCITED
Definition EyeControl.h:278
int8_t stopDolyService()
Stop the background Doly service (if running).