Adding NVS to project
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* @file countDown.hpp
|
||||
* @author Gustice
|
||||
* @brief Classes for typical index manipulation
|
||||
*
|
||||
* @copyright Copyright (c) 2020
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
class CountDown {
|
||||
public:
|
||||
CountDown(unsigned max) : Max(max) {}
|
||||
|
||||
void Tick() {
|
||||
_cnt++;
|
||||
if (_cnt >= Max) {
|
||||
_cnt = 0;
|
||||
_pFlag = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool GetVolatileFlag() {
|
||||
if (!_pFlag)
|
||||
return false;
|
||||
|
||||
// Reset _pFlag in any case, so it only be consumed once
|
||||
// hence volatile
|
||||
_pFlag = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
const unsigned Max;
|
||||
unsigned _cnt;
|
||||
bool _pFlag;
|
||||
};
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* @file rotatingIndex.hpp
|
||||
* @author Gustice
|
||||
* @brief Classes for typical index manipulation
|
||||
*
|
||||
* @copyright Copyright (c) 2020
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* @brief Index with automatic revolution back to start position
|
||||
* @details Useful for Buffer-Pointer, or similar tasks
|
||||
*/
|
||||
class RotatingIndex {
|
||||
public:
|
||||
/// @brief Value at witch the index rotates back to beginning
|
||||
const uint16_t MaxIndex;
|
||||
|
||||
/// @brief Constructor for rotating index
|
||||
/// @brief output index will be set to 0 if incremented value reaches Maximum
|
||||
/// @param max Maximum index for overflow-condition
|
||||
RotatingIndex(uint16_t max) : MaxIndex(max) { _index = 0; }
|
||||
|
||||
/// @brief Get the current index and inkrement index afterwards
|
||||
/// @return uint16_t current index
|
||||
uint16_t getIndexAndIncrement(void) {
|
||||
auto retVal = _index;
|
||||
_index++;
|
||||
if (_index >= MaxIndex) {
|
||||
_index = 0;
|
||||
}
|
||||
return retVal;
|
||||
};
|
||||
|
||||
/// @brief Get the current index without incrementing the index
|
||||
/// @return uint16_t current index
|
||||
uint16_t getIndex(void) { return _index; }
|
||||
|
||||
/// @brief Check if next get will lead to overflow condition
|
||||
bool peekRevolution(void) {
|
||||
if (MaxIndex == 0)
|
||||
return true;
|
||||
|
||||
if (_index >= MaxIndex - 1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// @brief Reset Index to 0
|
||||
void resetIndex(void) { _index = 0; }
|
||||
|
||||
private:
|
||||
/// Current Index
|
||||
uint16_t _index;
|
||||
};
|
||||
Reference in New Issue
Block a user