Switch Controller
Loading...
Searching...
No Matches
Macro.h
Go to the documentation of this file.
1#pragma once
2
3#include "pch.h"
4
5#include "Action.h"
6
7class Macro {
8public:
9 Macro() {} // TODO? potentially remove default constructor
10 Macro(const std::vector<Action> &actionVector,
11 const std::function<bool()> &activateEvent,
12 const std::function<std::weak_ptr<Macro>()> &decider)
13 : actionVector(actionVector), activateEvent(activateEvent),
14 decider(decider) {}
15
16 Macro(const Macro &other) = delete;
17
18 Macro(Macro &&other) = default;
19 Macro &operator=(Macro &&other) = default;
20
21 std::shared_ptr<Macro> getNextMacro() const {
22 return decider ? decider().lock() : nullptr;
23 }
24
25 std::optional<std::array<uint8_t, 8>> getDataframe(uint64_t time) const {
26 if (actionVector.size() == 0 || time >= actionVector.back().time) {
27 return {};
28 }
29
30 Action searchAction = {time, {}};
31 auto predicate = [](const Action &a, const Action &b) {
32 return a.time < b.time;
33 };
34 // round up
35 auto res = std::upper_bound(actionVector.begin(), actionVector.end(),
36 searchAction, predicate);
37 return res->data;
38 }
39
40 bool active() const { return activateEvent ? activateEvent() : false; }
41
42private:
43 std::vector<Action> actionVector;
44 std::function<bool()> activateEvent;
45 std::function<std::weak_ptr<Macro>()> decider;
46};
Definition: Macro.h:7
std::shared_ptr< Macro > getNextMacro() const
Definition: Macro.h:21
Macro(const Macro &other)=delete
Macro(const std::vector< Action > &actionVector, const std::function< bool()> &activateEvent, const std::function< std::weak_ptr< Macro >()> &decider)
Definition: Macro.h:10
bool active() const
Definition: Macro.h:40
std::optional< std::array< uint8_t, 8 > > getDataframe(uint64_t time) const
Definition: Macro.h:25
Macro()
Definition: Macro.h:9
Macro & operator=(Macro &&other)=default
Macro(Macro &&other)=default
Definition: Action.h:6
uint64_t time
Definition: Action.h:7