9 const int RECORDING_BUTTON_COOLDOWN = 1000;
11 std::function<bool()> playEvent;
13 std::vector<Action> currentRecording;
14 std::shared_ptr<Macro> lastRecordedMacro;
15 std::function<bool()> recordEvent;
17 std::chrono::steady_clock::time_point activationTime =
18 std::chrono::steady_clock::now();
19 bool recording =
false;
23 const std::function<
bool()> &playEvent)
24 : playEvent(playEvent),
25 lastRecordedMacro(std::make_shared<
Macro>(
Macro{{}, playEvent, {}})),
26 recordEvent(recordEvent) {}
28 void update(
const std::array<uint8_t, 8> &data) {
29 auto now = std::chrono::steady_clock::now();
30 auto timeDiff = std::chrono::duration_cast<std::chrono::milliseconds>(
34 if (recordEvent() && timeDiff > RECORDING_BUTTON_COOLDOWN) {
40 std::to_string(now.time_since_epoch().count()) +
".hex";
41 spdlog::info(
"Saving recording to \"{}\"", str);
43 *lastRecordedMacro =
Macro(currentRecording, playEvent, {});
44 currentRecording = {};
46 recording = !recording;
49 currentRecording.push_back({
static_cast<uint64_t
>(timeDiff), data});
54 return lastRecordedMacro;
void saveActionVector(const std::string &filename, const std::vector< Action > &record)
Definition: Action.h:11
Definition: MacroRecorder.h:7
MacroRecorder(const std::function< bool()> &recordEvent, const std::function< bool()> &playEvent)
Definition: MacroRecorder.h:22
const std::shared_ptr< Macro > getLastRecordedMacro() const
Definition: MacroRecorder.h:53
void update(const std::array< uint8_t, 8 > &data)
Definition: MacroRecorder.h:28