6#include "dawn/prog/toggle.hxx"
11#include "dawn/debug.hxx"
12#include "dawn/io/common.hxx"
13#include "dawn/io/ddata.hxx"
27CProgToggle::~CProgToggle()
36 bind =
new (std::nothrow) SToggleBind();
43 bind->sourceId = sourceId;
44 bind->outputId = outputId;
45 bind->source =
nullptr;
46 bind->output =
nullptr;
47 bind->sourceData =
nullptr;
50 binds.push_back(bind);
56int CProgToggle::configureDesc(
const CDescObject &desc)
63 for (
size_t i = 0; i < desc.
getSize(); i++)
67 if (item->
cfgid.
s.
cls != CProgCommon::PROG_CLASS_TOGGLE)
69 DAWNERR(
"toggle: unsupported cfg class 0x%" PRIx32
"\n", item->
cfgid.
v);
75 case PROG_TOGGLE_CFG_IOBIND:
77 size_t nitems =
static_cast<size_t>(item->
cfgid.
s.
size);
78 if (nitems == 0 || nitems % 2 != 0)
80 DAWNERR(
"toggle: invalid IOBIND size %zu\n", nitems);
85 for (
size_t b = 0; b < nitems / 2; b++)
87 int ret = allocBind(ids[b * 2].v, ids[b * 2 + 1].v);
96 case PROG_TOGGLE_CFG_VALUES:
100 DAWNERR(
"toggle: VALUES config must have exactly 2 entries\n");
112 DAWNERR(
"toggle: unsupported cfg id %u\n", item->
cfgid.
s.
id);
120 DAWNERR(
"toggle: at least one IOBIND entry required\n");
130 return configureDesc(
getDesc());
137 for (
auto bind : binds)
139 bind->source =
getIO(bind->sourceId);
140 bind->output =
getIO(bind->outputId);
141 if (!bind->source || !bind->output)
146 if (!bind->source->isRead())
148 DAWNERR(
"toggle: source 0x%" PRIx32
" is not readable\n", bind->sourceId);
152 ret = prepareWritableTarget(bind->output, 1,
true);
160 DAWNERR(
"toggle: output 0x%" PRIx32
" must be writable scalar uint32\n", bind->outputId);
164 bind->sourceData = bind->source->ddata_alloc(1);
165 if (!bind->sourceData)
178 for (
auto bind : binds)
180 delete bind->sourceData;
188uint32_t CProgToggle::readInput(SToggleBind *bind,
io_ddata_t *data)
195 bind->sourceData->getDataPtr(), data->
getDataPtr(), bind->sourceData->getDataSize());
197 else if (bind->source->getData(*bind->sourceData, 1) != OK)
203 bind->sourceData->getDataPtr(),
204 bind->sourceData->getDataSize() <
sizeof(input) ? bind->sourceData->getDataSize()
209void CProgToggle::writeValue(SToggleBind *bind)
211 bind->outputData(0) = curVal;
212 int ret = bind->output->setData(bind->outputData);
215 DAWNERR(
"toggle: setData failed %d\n", ret);
219void CProgToggle::refresh(SToggleBind *bind,
io_ddata_t *data)
221 uint32_t input = readInput(bind, data);
223 if (bind->prevInput == 0 && input != 0)
225 curVal = curVal == offVal ? onVal : offVal;
229 bind->prevInput = input;
232int CProgToggle::ioNotifierCb(
void *priv,
io_ddata_t *data)
234 SToggleBind *bind =
static_cast<SToggleBind *
>(priv);
236 if (bind && bind->owner && bind->owner->active)
238 bind->owner->refresh(bind, data);
250 for (
auto bind : binds)
252 if (!bind->source->isNotify())
257 ret = bind->source->setNotifier(ioNotifierCb, 0, bind);
269 for (
auto bind : binds)
271 bind->prevInput = readInput(bind,
nullptr);
282 for (
auto bind : binds)
284 if (bind->source && bind->source->isNotify())
286 bind->source->setNotifier(
nullptr, 0,
nullptr);
307 for (
auto bind : binds)
CIOCommon * getIO(SObjectId::ObjectId id)
Get an I/O object by ID.
void setObjectMapItem(SObjectId::ObjectId id, CObject *obj)
Set an item in the object map.
Descriptor wrapper for individual object configuration.
size_t getSize() const
Get number of configuration items for this object.
SObjectCfg::SObjectCfgItem * objectCfgItemNext(size_t &offset) const
Get config item at current offset and advance past it.
CDescObject & getDesc()
Get descriptor object for this object.
@ CMD_RESET
Reset object internal state.
Base class for all PROG (processing) objects.
int deinit()
De-initialize object.
int doStart()
Start implementation hook.
int trigger(uint8_t cmd)
Execute a trigger command.
bool hasThread() const
Check if a background thread is active.
int configure()
Configure object from descriptor data.
int init()
One-time initialize object after bindings are resolved.
int doStop()
Stop implementation hook.
uint32_t ObjectCfgData_t
Configuration data element - single 32-bit word.
static uint32_t cfgToU32(ObjectCfgData_t x)
Convert ObjectCfgData_t to uint32_t.
Out-of-tree user-extension hooks for Dawn.
Single configuration item within object.
ObjectCfgData_t data[]
Configuration data array (flexible, size from cfgid.s.size).
UObjectCfgId cfgid
Configuration ID header (type, class, id, size, rw, dtype).
@ DTYPE_UINT32
Unsigned 32-bit integer (0 to 4294967295).
uint32_t ObjectId
ObjectID type - single 32-bit value.
Heap-allocated dynamic I/O data buffer.
void * getDataPtr(size_t batch=0)
Get pointer to data only (skips timestamp if present).
size_t getItems()
Get number of items per batch.
ObjectCfgId v
Raw 32-bit ConfigID value (for storage, comparison).
uint32_t cls
Object class (bits 21-29, max 511).
uint32_t id
Configuration identifier (bits 0-4, max 31).
uint32_t size
Configuration data size in 32-bit words (bits 5-14, max 1023).
struct dawn::SObjectCfg::UObjectCfgId::@10 s
Bit-field structure for named member access.
32-bit encoded object identifier (union with bit field).