flipperzero-firmware/applications/lfrfid/helpers/state_sequencer.cpp
あく 389ff92cc1
Naming and coding style convention, new linter tool. (#945)
* Makefile, Scripts: new linter
* About: remove ID from IC
* Firmware: remove double define for DIVC/DIVR
* Scripts: check folder names too. Docker: replace syntax check with make lint.
* Reformat Sources and Migrate to new file naming convention
* Docker: symlink clang-format-12 to clang-format
* Add coding style guide
2022-01-05 19:10:18 +03:00

51 lines
996 B
C++

#include "state_sequencer.h"
#include "stdio.h"
TickSequencer::TickSequencer() {
}
TickSequencer::~TickSequencer() {
}
void TickSequencer::tick() {
if(tick_count == list_it->first) {
tick_count = 0;
list_it++;
if(list_it == list.end()) {
list_it = list.begin();
}
}
list_it->second();
tick_count++;
}
void TickSequencer::reset() {
list_it = list.begin();
tick_count = 0;
}
void TickSequencer::clear() {
list.clear();
reset();
}
void TickSequencer::do_every_tick(uint32_t tick_count, std::function<void(void)> fn) {
list.push_back(std::make_pair(tick_count, fn));
reset();
}
void TickSequencer::do_after_tick(uint32_t tick_count, std::function<void(void)> fn) {
if(tick_count > 1) {
list.push_back(
std::make_pair(tick_count - 1, std::bind(&TickSequencer::do_nothing, this)));
}
list.push_back(std::make_pair(1, fn));
reset();
}
void TickSequencer::do_nothing() {
}