Possibly fix buffer boundaries not being checked
This commit is contained in:
parent
6e96e5ca86
commit
73bbc2b1ca
2 changed files with 32 additions and 7 deletions
|
@ -3,20 +3,41 @@
|
|||
#include <Arduino.h>
|
||||
#include <EEPROM.h>
|
||||
|
||||
LightController::LightController(const int bjtPins[], int bjtCount)
|
||||
LightController::LightController(const int bjtPins[], __SIZE_TYPE__ bjtCount)
|
||||
{
|
||||
this->bjtCount = bjtCount;
|
||||
this->bjtPins = bjtPins;
|
||||
this->bjtState = new int[bjtCount];
|
||||
initializePins();
|
||||
initializeState();
|
||||
}
|
||||
|
||||
for (int i = 0; i < bjtCount; i++)
|
||||
void LightController::initializeState()
|
||||
{
|
||||
initializeStateDefaultValues();
|
||||
restoreState();
|
||||
}
|
||||
|
||||
void LightController::initializePins()
|
||||
{
|
||||
for (__SIZE_TYPE__ i = 0; i < bjtCount; i++)
|
||||
{
|
||||
pinMode(bjtPins[i], OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void LightController::initializeStateDefaultValues()
|
||||
{
|
||||
for (__SIZE_TYPE__ i = 0; i < bjtCount && i < sizeof(bjtState) / sizeof(bjtState[0]); i++)
|
||||
{
|
||||
bjtState[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < bjtCount; i++)
|
||||
void LightController::restoreState()
|
||||
{
|
||||
for (__SIZE_TYPE__ i = 0; i < bjtCount && i < sizeof(bjtState) / sizeof(bjtState[0]); i++)
|
||||
{
|
||||
pinMode(bjtPins[i], OUTPUT);
|
||||
bjtState[i] = EEPROM.read(i);
|
||||
commitPinState(i);
|
||||
}
|
||||
|
@ -24,7 +45,7 @@ LightController::LightController(const int bjtPins[], int bjtCount)
|
|||
|
||||
void LightController::updateState(const char data[], int steps)
|
||||
{
|
||||
for (int i = 0; i < bjtCount; i++)
|
||||
for (__SIZE_TYPE__ i = 0; i < bjtCount; i++)
|
||||
{
|
||||
parseRelativeState(data, i, steps);
|
||||
setAbsoluteState(data, i);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class LightController
|
||||
{
|
||||
protected:
|
||||
int bjtCount;
|
||||
__SIZE_TYPE__ bjtCount;
|
||||
const int *bjtPins;
|
||||
int *bjtState;
|
||||
|
||||
|
@ -11,9 +11,13 @@ private:
|
|||
int clampState(int stateValue);
|
||||
void commitState(int index);
|
||||
void commitPinState(int index);
|
||||
void initializeStateDefaultValues();
|
||||
void restoreState();
|
||||
void initializeState();
|
||||
void initializePins();
|
||||
|
||||
public:
|
||||
LightController(const int bjtPins[], int bjtCount);
|
||||
LightController(const int bjtPins[], __SIZE_TYPE__ bjtCount);
|
||||
void updateState(const char data[], int steps);
|
||||
int getBjtCount();
|
||||
const int *getBjtPins();
|
||||
|
|
Reference in a new issue