2017-03-23 18:45:29 +00:00
|
|
|
#ifndef __Stairs
|
|
|
|
#define __Stairs
|
|
|
|
|
2018-01-14 20:31:37 +00:00
|
|
|
#include "./components/PCA9685.h"
|
|
|
|
#include "./config.h"
|
|
|
|
#include "./settings/steps.h"
|
2017-03-27 20:24:05 +00:00
|
|
|
|
2018-01-04 21:53:16 +00:00
|
|
|
struct Step
|
2017-03-27 20:24:05 +00:00
|
|
|
{
|
2018-01-05 15:43:14 +00:00
|
|
|
uint8_t currentValue;
|
|
|
|
uint8_t startValue;
|
|
|
|
uint8_t targetValue;
|
|
|
|
int16_t startTime;
|
|
|
|
uint16_t remainingTime;
|
2017-03-27 20:24:05 +00:00
|
|
|
};
|
|
|
|
|
2017-03-23 18:45:29 +00:00
|
|
|
|
2018-01-04 21:53:16 +00:00
|
|
|
class Stairs
|
2017-03-23 18:45:29 +00:00
|
|
|
{
|
|
|
|
private:
|
2018-01-04 21:53:16 +00:00
|
|
|
PCA9685* mPWMDriver;
|
|
|
|
Step mStep[MaxStepCount];
|
2017-03-23 18:45:29 +00:00
|
|
|
|
2018-01-05 15:43:14 +00:00
|
|
|
uint32_t mLastTransitionTime;
|
2018-01-04 21:53:16 +00:00
|
|
|
bool mTick = false;
|
2017-03-27 20:24:05 +00:00
|
|
|
|
2017-03-24 22:04:58 +00:00
|
|
|
protected:
|
2018-01-05 15:43:14 +00:00
|
|
|
uint8_t ease(uint8_t startValue, uint8_t targetValue, uint16_t transitionTime, uint16_t elapsedTime);
|
|
|
|
inline void updateCurrentValue(Step* stepState);
|
|
|
|
inline void applyCurrentValue(uint8_t step);
|
2018-01-04 21:53:16 +00:00
|
|
|
uint16_t getPWMValue(uint8_t step, uint8_t brightness);
|
2017-03-24 22:04:58 +00:00
|
|
|
|
2017-03-23 18:45:29 +00:00
|
|
|
public:
|
|
|
|
void init(PCA9685* pwmDriver);
|
2018-01-04 21:53:16 +00:00
|
|
|
void tick();
|
2017-03-23 18:45:29 +00:00
|
|
|
|
2018-01-18 22:20:31 +00:00
|
|
|
bool inTransition() { return mTick; }
|
|
|
|
|
2018-01-04 21:53:16 +00:00
|
|
|
uint8_t get(uint8_t step, bool target = true);
|
|
|
|
void set(uint8_t step, uint8_t brightness, uint16_t transitionTime = 0, uint16_t startTime = 0);
|
|
|
|
void setAll(uint8_t brightness, uint16_t transitionTime = 0, uint16_t startTime = 0);
|
2017-03-23 18:45:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|