37 lines
743 B
C++
37 lines
743 B
C++
#pragma once
|
|
|
|
#define DEBUGLOG_DEFAULT_LOG_LEVEL_INFO
|
|
|
|
#include <DebugLog.h>
|
|
#include <Arduino.h>
|
|
|
|
namespace drivers
|
|
{
|
|
|
|
class BusDelay
|
|
{
|
|
public:
|
|
BusDelay(uint32_t &lastAccess, const uint32_t minDelay, const char *title) : m_lastAccess(lastAccess)
|
|
{
|
|
const uint32_t now = millis();
|
|
const uint32_t wait = now - lastAccess;
|
|
if (wait < minDelay)
|
|
{
|
|
LOG_DEBUG(title, "delay", wait);
|
|
delay(wait);
|
|
}
|
|
}
|
|
|
|
BusDelay(BusDelay &) = delete;
|
|
BusDelay operator=(BusDelay &) = delete;
|
|
|
|
~BusDelay()
|
|
{
|
|
m_lastAccess = millis();
|
|
}
|
|
|
|
private:
|
|
uint32_t &m_lastAccess;
|
|
};
|
|
|
|
} |