1
0
mirror of https://github.com/taigrr/arduinolibs synced 2025-01-18 04:33:12 -08:00

Noise source initialization that is post-RNG.begin()

This commit is contained in:
Rhys Weatherley 2015-04-02 10:18:35 +10:00
parent 1d89097948
commit d50a7fed2d
3 changed files with 20 additions and 1 deletions

View File

@ -82,6 +82,21 @@ NoiseSource::~NoiseSource()
* \sa calibrating(), output() * \sa calibrating(), output()
*/ */
/**
* \brief Called when the noise source is added to RNG with
* \link RNGClass::addNoiseSource() RNG.addNoiseSource()\endlink.
*
* This function is intended for noise source initialization tasks that
* must be performed after \link RNGClass::begin() RNG.begin()\endlink
* has been called to initialize the global random number pool.
* For example, if the noise source has a unique identifier or serial
* number then this function can stir it into the pool at startup time.
*/
void NoiseSource::added()
{
// Nothing to do here.
}
/** /**
* \brief Called from subclasses to output noise to the global random * \brief Called from subclasses to output noise to the global random
* number pool. * number pool.

View File

@ -35,6 +35,8 @@ public:
virtual bool calibrating() const = 0; virtual bool calibrating() const = 0;
virtual void stir() = 0; virtual void stir() = 0;
virtual void added();
protected: protected:
virtual void output(const uint8_t *data, size_t len, unsigned int credit); virtual void output(const uint8_t *data, size_t len, unsigned int credit);
}; };

View File

@ -249,8 +249,10 @@ void RNGClass::begin(const char *tag, int eepromAddress)
void RNGClass::addNoiseSource(NoiseSource &source) void RNGClass::addNoiseSource(NoiseSource &source)
{ {
#define MAX_NOISE_SOURCES (sizeof(noiseSources) / sizeof(noiseSources[0])) #define MAX_NOISE_SOURCES (sizeof(noiseSources) / sizeof(noiseSources[0]))
if (count < MAX_NOISE_SOURCES) if (count < MAX_NOISE_SOURCES) {
noiseSources[count++] = &source; noiseSources[count++] = &source;
source.added();
}
} }
/** /**