AwesomeStudioPedal
A programmable, multi-profile foot controller for DAWs, score readers, and studio automation
Loading...
Searching...
No Matches
delayed_action.cpp
Go to the documentation of this file.
1#include "delayed_action.h"
2
3#ifndef HOST_TEST_BUILD
4#include <Arduino.h>
5#else
6#include "../test/fakes/arduino_shim.h"
7#endif
8
15DelayedAction::DelayedAction(std::unique_ptr<Action> action, uint32_t delayMs)
16 : action(std::move(action)), delayMs(delayMs)
17{
18}
19
28{
29 if (! started)
30 {
31 startTime = static_cast<uint32_t>(millis());
32 started = true;
33 }
34 else
35 {
36 if (millis() - startTime >= delayMs)
37 {
38 action->execute();
39 started = false;
40 }
41 }
42}
43
47bool DelayedAction::update(uint32_t currentTime) const
48{
49 if (! started)
50 {
51 return false;
52 }
53 return (currentTime - startTime >= delayMs);
54}
55
61void DelayedAction::getJsonProperties(JsonObject& json) const
62{
63 json["delayMs"] = delayMs;
64 JsonObject nestedAction = json.createNestedObject("action");
65 action->getJsonProperties(nestedAction);
66 nestedAction["type"] = getTypeName(action->getType());
67}
68
76{
77 switch (type)
78 {
80 return "SendStringAction";
82 return "SendCharAction";
84 return "SendKeyAction";
86 return "SendMediaKeyAction";
88 return "SerialOutputAction";
90 return "DelayedAction";
91 default:
92 return "UnknownAction";
93 }
94}
static const char * getTypeName(Action::Type type)
Converts an Action::Type enum to its string representation.
bool update(uint32_t currentTime) const
Polls whether the delay has elapsed.
void execute() override
Executes the delayed action.
DelayedAction(std::unique_ptr< Action > action, uint32_t delayMs)
Constructs a DelayedAction that wraps an action with a time delay.
void getJsonProperties(JsonObject &json) const override
Serializes the delayed action to JSON.