McopyProjector lib for mcopy_projector_firmware rewrite in progress.
This commit is contained in:
parent
86c88c4ac2
commit
141d27599f
|
@ -1,7 +1,6 @@
|
|||
#ifndef IteadDualStepperShield_h
|
||||
#define IteadDualStepperShield_h
|
||||
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
class IteadDualStepperShield {
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/// Mcopy Projector Class
|
||||
|
||||
#include "McopyProjector.h"
|
||||
#include "IteadDualStepperShield.h"
|
||||
|
||||
McopyProjector::McopyProjector () {
|
||||
|
||||
}
|
||||
|
||||
void McopyProjector::begin () {
|
||||
steppers.setup();
|
||||
steppers.setSpeed(0, _speed);
|
||||
steppers.setSpeed(1, _speed);
|
||||
}
|
||||
|
||||
void McopyProjector::setDirection (bool dir) {
|
||||
_dir = dir;
|
||||
if (_dir) {
|
||||
steppers.setDir(0, 1);
|
||||
steppers.setDir(1, 1);
|
||||
} else {
|
||||
steppers.setDir(0, 0);
|
||||
steppers.setDir(1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void McopyProjector::frame (bool dir) {
|
||||
if (dir != _dir) {
|
||||
setDirection(dir);
|
||||
}
|
||||
steppers.stepBoth(_stepsPerFrame);
|
||||
_posTakeup += dir ? _stepsPerFrame : -_stepsPerFrame;
|
||||
_posFeed += dir ? _stepsPerFrame : -_stepsPerFrame;
|
||||
}
|
||||
|
||||
void McopyProjector::adjust(uint8_t motor, int32_t steps) {
|
||||
if (steps < 0) {
|
||||
steppers.setDir(motor, 0);
|
||||
} else {
|
||||
steppers.setDir(motor, 1);
|
||||
}
|
||||
steppers.step(motor, abs(steps));
|
||||
if (motor == 0) {
|
||||
_posTakeup += steps;
|
||||
} else if (motor == 1) {
|
||||
_posFeed += steps;
|
||||
}
|
||||
}
|
||||
|
||||
void McopyProjector::adjustBoth(int32_t steps) {
|
||||
if (steps < 0) {
|
||||
steppers.setDir(0, 0);
|
||||
steppers.setDir(1, 0);
|
||||
} else {
|
||||
steppers.setDir(0, 1);
|
||||
steppers.setDir(1, 1);
|
||||
}
|
||||
steppers.stepBoth(abs(steps));
|
||||
_posTakeup += steps;
|
||||
_posFeed += steps;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
#ifndef MCOPY_PROJECTOR
|
||||
#define MCOPY_PROJECTOR
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "IteadDualStepperShield.h"
|
||||
|
||||
class McopyProjector {
|
||||
|
||||
private:
|
||||
|
||||
IteadDualStepperShield steppers;
|
||||
|
||||
uint8_t _motorSteps = 200;
|
||||
uint8_t _frames = 8;
|
||||
uint8_t _stepsPerFrame = round(_motorSteps / _frames);
|
||||
uint16_t _speed = 500;
|
||||
|
||||
int64_t _posTakeup = 0;
|
||||
int64_t _posFeed = 0;
|
||||
|
||||
bool _dir = true;
|
||||
|
||||
public:
|
||||
|
||||
McopyProjector();
|
||||
void begin();
|
||||
//0 = takeup, 1 = feed
|
||||
void adjust(uint8_t motor, int32_t steps);
|
||||
void adjustBoth(int32_t steps);
|
||||
//true = forward, false = back
|
||||
void frame(bool dir);
|
||||
void frames(bool dir, uint32_t count);
|
||||
void setDirection(bool dir);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -21,10 +21,11 @@
|
|||
Y02A - Blue
|
||||
Y02B - Red
|
||||
*/
|
||||
|
||||
#include "McopyProjector.h"
|
||||
#include "McopySerial.h"
|
||||
#include "IteadDualStepperShield.h"
|
||||
|
||||
|
||||
//CAMERA CONSTANTS
|
||||
const int BUTTON = 7;
|
||||
const int LED_FWD = 8;
|
||||
|
@ -41,17 +42,16 @@ volatile bool direction = true;
|
|||
volatile long start;
|
||||
|
||||
McopySerial mcopy;
|
||||
IteadDualStepperShield steppers;
|
||||
McopyProjector projector;
|
||||
|
||||
void setup () {
|
||||
steppers.setup();
|
||||
steppers.setSpeed(0, 500);
|
||||
steppers.setSpeed(1, 500);
|
||||
|
||||
|
||||
pins();
|
||||
digitalWrite(LED_FWD, HIGH);
|
||||
digitalWrite(LED_BWD, HIGH);
|
||||
mcopy.begin(mcopy.PROJECTOR_IDENTIFIER);
|
||||
projector.begin();
|
||||
delay(42);
|
||||
digitalWrite(LED_FWD, LOW);
|
||||
digitalWrite(LED_BWD, LOW);
|
||||
|
@ -62,7 +62,7 @@ void loop () {
|
|||
cmdChar = mcopy.loop();
|
||||
cmd(cmdChar);
|
||||
if (digitalRead(BUTTON) == LOW) {
|
||||
projector();
|
||||
projector_frame();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,12 +76,12 @@ void pins () {
|
|||
}
|
||||
|
||||
void cmd (char val) {
|
||||
if (val == mcopy.CAMERA_FORWARD) {
|
||||
if (val == mcopy.PROJECTOR_FORWARD) {
|
||||
projector_direction(true);
|
||||
} else if (val == mcopy.CAMERA_BACKWARD) {
|
||||
} else if (val == mcopy.PROJECTOR_BACKWARD) {
|
||||
projector_direction(false);
|
||||
} else if (val == mcopy.PROJECTOR) {
|
||||
projector();
|
||||
projector_frame();
|
||||
} else if (val == mcopy.STATE) {
|
||||
state();
|
||||
}
|
||||
|
@ -92,13 +92,11 @@ void projector_direction (boolean state) {
|
|||
if (state) {
|
||||
mcopy.confirm(mcopy.PROJECTOR_FORWARD);
|
||||
mcopy.log("projector_direction(true)");
|
||||
steppers.setDir(0, 1);
|
||||
steppers.setDir(1, 1);
|
||||
projector.setDirection(true);
|
||||
} else {
|
||||
mcopy.confirm(mcopy.PROJECTOR_BACKWARD);
|
||||
mcopy.log("projector_direction(false)");
|
||||
steppers.setDir(0, 0);
|
||||
steppers.setDir(1, 0);
|
||||
projector.setDirection(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,10 +114,10 @@ void projector_timing_end () {
|
|||
}
|
||||
}
|
||||
|
||||
void projector () {
|
||||
void projector_frame () {
|
||||
int LED = direction ? LED_FWD : LED_BWD;
|
||||
digitalWrite(LED, HIGH);
|
||||
steppers.stepBoth(PROJECTOR_STEPS);
|
||||
projector.frame(direction);
|
||||
mcopy.confirm(mcopy.PROJECTOR);
|
||||
digitalWrite(LED, LOW);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue