Api improvements: ambience-count-[l|g]t-val and Comparator

This commit is contained in:
2026-04-03 23:54:22 -04:00
parent bedcf78b29
commit 7516da6aa8
4 changed files with 111 additions and 19 deletions
@@ -0,0 +1,79 @@
#ifndef _LIVOX_GEN1_PCLOUD_AMBIENCE_QUALE_IFACE_API_H
#define _LIVOX_GEN1_PCLOUD_AMBIENCE_QUALE_IFACE_API_H
#include <cstdint>
#include <memory>
#include <stdexcept>
#include <user/deviceAttachmentSpec.h>
namespace smo {
namespace stim_buff {
enum ParamComparatorOp
{
OP_CMP_GT,
OP_CMP_LT,
};
struct ParamComparator
{
ParamComparatorOp op;
uint32_t value;
bool operator()(float ambienceVal) const
{
switch (op)
{
case OP_CMP_GT:
return ambienceVal > static_cast<float>(value);
case OP_CMP_LT:
return ambienceVal < static_cast<float>(value);
}
throw std::runtime_error("Unsupported ParamComparatorOp");
}
};
inline ParamComparator parsePcloudAmbienceParamComparator(
const std::shared_ptr<device::DeviceAttachmentSpec>& deviceAttachmentSpec)
{
const auto& params = deviceAttachmentSpec->qualeIfaceApiParams;
constexpr int kParamNotSpecified = -1;
const int gtVal = device::DeviceAttachmentSpec::parseOptionalParamAsInt(
params, "ambience-count-gt-val", kParamNotSpecified);
const int ltVal = device::DeviceAttachmentSpec::parseOptionalParamAsInt(
params, "ambience-count-lt-val", kParamNotSpecified);
if (gtVal != kParamNotSpecified && ltVal != kParamNotSpecified)
{
throw std::runtime_error(
"Only one of 'ambience-count-gt-val' or 'ambience-count-lt-val' "
"may be specified for a pcloudAmbience stim buff instance");
}
if (gtVal != kParamNotSpecified)
{
return ParamComparator{
.op = OP_CMP_GT,
.value = static_cast<uint32_t>(gtVal),
};
}
if (ltVal != kParamNotSpecified)
{
return ParamComparator{
.op = OP_CMP_LT,
.value = static_cast<uint32_t>(ltVal),
};
}
return ParamComparator{
.op = OP_CMP_LT,
.value = 8U,
};
}
} // namespace stim_buff
} // namespace smo
#endif // _LIVOX_GEN1_PCLOUD_AMBIENCE_QUALE_IFACE_API_H