From a5606fdefe05e0b48990c2100cb35e0d9fc30d5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Fri, 14 Jun 2024 22:57:00 -0400 Subject: [PATCH] [examples] Add a trigger example --- examples/Raw/Trigger.hpp | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 examples/Raw/Trigger.hpp diff --git a/examples/Raw/Trigger.hpp b/examples/Raw/Trigger.hpp new file mode 100644 index 00000000..57177ec1 --- /dev/null +++ b/examples/Raw/Trigger.hpp @@ -0,0 +1,43 @@ +#pragma once +#include + +/* SPDX-License-Identifier: GPL-3.0-or-later */ + +// clang-format off +namespace examples +{ +struct Trigger +{ + static consteval auto name() { return "Trigger"; } + static consteval auto c_name() { return "avnd_trigger"; } + static constexpr auto author() { return "Jean-Michaƫl Celerier"; } + static constexpr auto category() { return "Control/Mappings"; } + static constexpr auto description() { return "Send an impulse upon triggering"; } + static consteval auto uuid() { return "36427eb1-b5f4-4735-a383-6164cb9b2572"; } + + struct + { + struct { static constexpr auto name() { return "Input"; } float value; } input; + struct { static constexpr auto name() { return "Ceil"; } float value; enum widget { hslider }; struct range { float min = 0.f, max = 1.f, init = 0.5f;}; } ceil; + } inputs; + + struct + { + struct { std::optional value; } enter; + struct { std::optional value; } leave; + } outputs; + + bool state{}; + void operator()() { + if(inputs.input.value > inputs.ceil.value && !state) { + outputs.enter.value= true; + state = true; + } + else if(inputs.input.value < inputs.ceil.value && state) { + outputs.leave.value = true; + state = false; + } + } +}; +} +// clang-format on