2024-06-23 02:57:20 +00:00
|
|
|
#ifndef EndstopCameraShield_h
|
|
|
|
#define EndstopCameraShield_h
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
2024-06-30 15:50:02 +00:00
|
|
|
#include "TB6600MotorDriver.h"
|
2024-06-23 02:57:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default pins
|
|
|
|
* 2 Close Receiver Pin
|
|
|
|
* 3 Open Receiver Pin
|
|
|
|
* 4 Open Emitter Pin
|
|
|
|
* 5 Close Emitter Pin
|
|
|
|
**/
|
|
|
|
|
|
|
|
class EndstopCameraShield {
|
|
|
|
private:
|
2024-07-06 03:56:45 +00:00
|
|
|
const uint8_t _receiverClosePin = 2;
|
|
|
|
const uint8_t _receiverOpenPin = 3;
|
|
|
|
const uint8_t _emitterOpenPin = 4;
|
|
|
|
const uint8_t _emitterClosePin = 5;
|
|
|
|
|
|
|
|
const uint8_t _motorEnablePin = 6;
|
|
|
|
const uint8_t _motorDirectionPin = 7;
|
|
|
|
const uint8_t _motorPulsePin = 8;
|
|
|
|
|
|
|
|
const double _ledAngle = 7.0;
|
2024-07-31 00:00:09 +00:00
|
|
|
const uint32_t _motorSteps = 200;
|
2024-06-30 15:50:02 +00:00
|
|
|
|
2024-07-06 03:56:45 +00:00
|
|
|
volatile uint32_t _motorUsPulse = 300;
|
|
|
|
volatile uint8_t _motorMicrosteps = 2; //half stepping
|
2024-07-31 00:00:09 +00:00
|
|
|
volatile double _stepAngle = (double) 360 / ((double) _motorMicrosteps * (double) _motorSteps);
|
|
|
|
volatile uint32_t _minSteps = 31;
|
2024-07-06 03:56:45 +00:00
|
|
|
|
|
|
|
TB6600MotorDriver _motor;
|
|
|
|
|
|
|
|
static volatile bool _direction; //true = forward, false = backward
|
|
|
|
static volatile bool _enabled;
|
|
|
|
static volatile bool _isClosed;
|
|
|
|
static volatile bool _isOpened;
|
|
|
|
|
|
|
|
void _checkState();
|
|
|
|
void _enableCloseInterrupt();
|
|
|
|
void _enableOpenInterrupt();
|
|
|
|
void _enableCloseEmitter();
|
|
|
|
void _enableOpenEmitter();
|
|
|
|
void _enableMotor();
|
|
|
|
void _disableCloseInterrupt();
|
|
|
|
void _disableOpenInterrupt();
|
|
|
|
void _disableCloseEmitter();
|
|
|
|
void _disableOpenEmitter();
|
|
|
|
void _disableMotor();
|
2024-07-31 00:00:09 +00:00
|
|
|
void _checkClose();
|
|
|
|
void _checkOpen();
|
2024-06-30 15:50:02 +00:00
|
|
|
|
2024-07-06 03:56:45 +00:00
|
|
|
static void _handleCloseInterrupt();
|
|
|
|
static void _handleOpenInterrupt();
|
2024-06-30 15:50:02 +00:00
|
|
|
|
2024-06-23 02:57:20 +00:00
|
|
|
public:
|
|
|
|
|
2024-06-30 16:10:30 +00:00
|
|
|
EndstopCameraShield(uint32_t usPulse, uint8_t microsteps);
|
2024-06-23 02:57:20 +00:00
|
|
|
|
|
|
|
void setup();
|
|
|
|
void loop();
|
2024-07-06 03:56:45 +00:00
|
|
|
uint32_t frame();
|
|
|
|
uint32_t toOpen();
|
2024-07-08 02:17:48 +00:00
|
|
|
uint32_t toClose();
|
2024-07-06 03:56:45 +00:00
|
|
|
void setDirection(bool direction);
|
|
|
|
bool isOpened();
|
|
|
|
bool isClosed();
|
2024-07-31 00:00:09 +00:00
|
|
|
void test();
|
2024-06-23 02:57:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|