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

Demonstrates:

  • Initializing IoControl
  • Controlling digital and analog IO
  • Handling IO-related events
#include <chrono>
#include <thread>
#include <spdlog/spdlog.h>
#include "IoControl.h"
#include "Helper.h"
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 IoControl version
spdlog::info("IoControl Version:{:.3f}", IoControl::getVersion());
// INFORMATION
spdlog::info("Before testing, connect IO port 0 and port 1 (pin_0 <-> pin_1).");
// write pin state => HIGH
uint8_t io_0 = 0; // IO port pin_0
// read IO pin state
uint8_t io_1 = 1; // IO port pin_1
GpioState state = IoControl::readPin(2, io_1);
spdlog::info("Read Pin:{} State:{}", io_1, static_cast<uint8_t>(state));
// write pin state => LOW
// read IO pin state
state = IoControl::readPin(2, io_1);
spdlog::info("Read Pin:{} State:{}", io_1, static_cast<uint8_t>(state));
return 0;
}
Shared helper utilities and common types used across the Doly SDK.
Public API for Doly IO control (IO Port GPIO pin read/write).
GpioState
Represents the digital logic level of a GPIO pin.
Definition GpioPin.h:47
@ LOW
Definition GpioPin.h:49
@ HIGH
Definition GpioPin.h:52
int8_t stopDolyService()
Stop the background Doly service (if running).
int8_t writePin(uint16_t id, uint8_t io_pin, GpioState state)
Write a GPIO state to an IO port pin.
float getVersion()
Get current library version.
GpioState readPin(uint16_t id, uint8_t io_pin)
Read the current GPIO state of an IO port pin.