2020-01-31 11:22:06 +00:00
|
|
|
#ifndef __control
|
|
|
|
#define __control
|
2020-01-30 14:16:52 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2020-01-31 15:50:19 +00:00
|
|
|
#include "./vl53l0x.h"
|
2020-01-30 14:16:52 +00:00
|
|
|
|
2020-01-31 11:22:06 +00:00
|
|
|
|
2020-01-31 15:50:19 +00:00
|
|
|
enum class ControlUpdateResult
|
|
|
|
{
|
2020-02-01 15:55:33 +00:00
|
|
|
Idle,
|
|
|
|
Stabilizing,
|
|
|
|
Moving,
|
|
|
|
TargetReached,
|
|
|
|
SensorError,
|
|
|
|
Overcurrent
|
2020-01-31 15:50:19 +00:00
|
|
|
};
|
2020-01-30 14:16:52 +00:00
|
|
|
|
|
|
|
|
2020-01-31 15:50:19 +00:00
|
|
|
enum class MoveDirection
|
|
|
|
{
|
2020-02-01 15:55:33 +00:00
|
|
|
None,
|
|
|
|
Up,
|
|
|
|
Down
|
2020-01-31 15:50:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ControlManager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VL53L0XInitResult init();
|
|
|
|
ControlUpdateResult update();
|
|
|
|
|
|
|
|
|
|
|
|
void stabilizeStart();
|
|
|
|
bool stabilized();
|
|
|
|
|
2020-02-01 15:55:33 +00:00
|
|
|
void moveStart(uint16_t height);
|
2020-01-31 15:50:19 +00:00
|
|
|
void moveStop();
|
|
|
|
|
|
|
|
void snapToPreset();
|
|
|
|
|
|
|
|
|
|
|
|
// Formats a height value as "0.00m" (always exactly 5 characters long).
|
|
|
|
// Buffer must be at least 6 bytes long, a null character is added.
|
|
|
|
// The value is the raw height sensor value, the offset is added by this function.
|
|
|
|
void getDisplayHeight(char* buffer, uint16_t value);
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t getCurrentHeight() { return this->currentHeight; }
|
2020-02-01 15:55:33 +00:00
|
|
|
uint16_t getLastMeasurement() { return this->lastMeasurement; }
|
2020-01-31 15:50:19 +00:00
|
|
|
MoveDirection getMoveDirection() { return this->moveDirection; }
|
|
|
|
uint16_t getMoveTarget() { return this->moveTarget; }
|
2020-02-01 15:55:33 +00:00
|
|
|
bool getIsStabilizing() { return this->stabilizationStart != 0; }
|
2020-01-31 15:50:19 +00:00
|
|
|
|
|
|
|
private:
|
2020-02-01 15:55:33 +00:00
|
|
|
bool targetReached();
|
|
|
|
|
2020-01-31 15:50:19 +00:00
|
|
|
VL53L0X heightSensor = VL53L0X();
|
|
|
|
uint16_t currentHeight;
|
2020-02-01 15:55:33 +00:00
|
|
|
uint16_t lastMeasurement = 0;
|
|
|
|
uint32_t lastValidMeasurement = 0;
|
2020-01-31 15:50:19 +00:00
|
|
|
|
|
|
|
MoveDirection moveDirection;
|
|
|
|
uint16_t moveTarget;
|
|
|
|
|
2020-02-01 15:55:33 +00:00
|
|
|
uint32_t stabilizationStart = 0;
|
|
|
|
uint8_t stabilizeCount = 0;
|
|
|
|
uint16_t stabilizeTarget = 0;
|
|
|
|
uint32_t stabilizationLastCheck = 0;
|
2020-01-31 15:50:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
extern ControlManager Control;
|
2020-01-30 14:16:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
#endif
|