unleashed-firmware/applications/lfrfid/helpers/state-sequencer.cpp
SG 22e1ecb642
New LF-RFID app (#534)
* Hal lfrfid: add read timer pulse and period config fns
* New debug application for lfrfid subsystem
* New lfrfid: app, fix naming
* App lfrfid: assets
* Container view module
* App ibutton: remove unused header
* App lfrfid scenes
* App notification, add yield to blocking operations, add speaker volume control
* App lfrfid: reading key scene
* Assets: placeholder icon
* App lfrfid: reworked container view module
* App lfrfid: new scenes
* App lfrfid: write scene
* App lfrfid: write hid
* App lfrfid: emulate scene
* App lfrfid: save name scene
* App lfrfid: add missing file
2021-06-28 17:42:30 +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() {
}