mirror of
https://github.com/EyeTrackVR/OpenIris.git
synced 2025-11-04 15:39:42 +08:00
update
- update LEDManager blink method to use the ledStateMap - update handleLED method to turn the LED off on an incorrect state-match
This commit is contained in:
parent
40ca34c382
commit
803eea15c2
@ -39,13 +39,11 @@ LEDManager::ledStateMap_t LEDManager::ledStateMap = {
|
||||
{LEDStates_e::_Camera_Error, {1, 500}},
|
||||
};
|
||||
|
||||
//!TODO: Change the parameters for each LED state to be unique.
|
||||
//! TODO: Change the parameters for each LED state to be unique.
|
||||
|
||||
LEDManager::LEDManager(byte pin,
|
||||
StateManager<LEDStates_e> *stateManager) : _ledPin(pin),
|
||||
stateManager(stateManager),
|
||||
_previousMillis(0),
|
||||
_ledState(false) {}
|
||||
LEDManager::LEDManager(byte pin) : _ledPin(pin),
|
||||
_previousMillis(0),
|
||||
_ledState(false) {}
|
||||
|
||||
LEDManager::~LEDManager() {}
|
||||
|
||||
@ -60,7 +58,7 @@ void LEDManager::begin()
|
||||
* @details This function must be called in the main loop
|
||||
*
|
||||
*/
|
||||
void LEDManager::handleLED()
|
||||
void LEDManager::handleLED(StateManager<LEDStates_e> *stateManager)
|
||||
{
|
||||
if (ledStateMap.find(stateManager->getCurrentState()) != ledStateMap.end())
|
||||
{
|
||||
@ -81,6 +79,8 @@ void LEDManager::handleLED()
|
||||
}
|
||||
|
||||
log_e("LED State not found");
|
||||
stateManager->setState(LEDStates_e::_LEDOff); // Set the state to off
|
||||
onOff(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -99,13 +99,25 @@ void LEDManager::onOff(bool state) const
|
||||
* @param times number of times to blink
|
||||
* @param delayTime delay between each blink
|
||||
*/
|
||||
void LEDManager::blink(int times, int delayTime)
|
||||
void LEDManager::blink(StateManager<LEDStates_e> *stateManager)
|
||||
{
|
||||
for (int i = 0; i < times; i++)
|
||||
|
||||
if (ledStateMap.find(stateManager->getCurrentState()) != ledStateMap.end())
|
||||
{
|
||||
onOff(true);
|
||||
delay(delayTime);
|
||||
onOff(false);
|
||||
delay(delayTime);
|
||||
blinkPatterns = ledStateMap[stateManager->getCurrentState()]; // Get the blink pattern for the current state
|
||||
for (int i = 0; i < blinkPatterns.times; i++)
|
||||
{
|
||||
onOff(true);
|
||||
delay(blinkPatterns.delayTime);
|
||||
onOff(false);
|
||||
delay(blinkPatterns.delayTime);
|
||||
}
|
||||
stateManager->setState(LEDStates_e::_LEDOff); // Set the state to off
|
||||
onOff(false); // Turn the LED off
|
||||
return;
|
||||
}
|
||||
|
||||
log_e("LED State not found");
|
||||
stateManager->setState(LEDStates_e::_LEDOff); // Set the state to off
|
||||
onOff(false);
|
||||
}
|
||||
|
||||
@ -7,18 +7,16 @@
|
||||
class LEDManager
|
||||
{
|
||||
public:
|
||||
LEDManager(byte pin,
|
||||
StateManager<LEDStates_e> *stateManager);
|
||||
LEDManager(byte pin);
|
||||
virtual ~LEDManager();
|
||||
|
||||
void begin();
|
||||
void handleLED();
|
||||
void handleLED(StateManager<LEDStates_e> *stateManager);
|
||||
void onOff(bool state) const;
|
||||
void blink(int times, int delayTime);
|
||||
void blink(StateManager<LEDStates_e> *stateManager);
|
||||
|
||||
private:
|
||||
byte _ledPin;
|
||||
StateManager<LEDStates_e> *stateManager;
|
||||
unsigned long _previousMillis;
|
||||
bool _ledState;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user