mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-27 15:00:46 +00:00
389ff92cc1
* 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
50 lines
996 B
C++
50 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() {
|
|
}
|