Skip to content

Commit

Permalink
[examples] Add a trigger example
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Jun 15, 2024
1 parent 3028a95 commit a5606fd
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions examples/Raw/Trigger.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once
#include <optional>

/* 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<bool> value; } enter;
struct { std::optional<bool> 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

0 comments on commit a5606fd

Please sign in to comment.