|
@@ -1,7 +1,7 @@
|
|
|
// FlipFlat based on the Altinak Flip-Flat commands. Makes it possible to use it with ASCOM and INDI drivers
|
|
|
|
|
|
// Enable DEBUG in FlipFlat.h to see logging.
|
|
|
-// Due to driver imitations in de indi driver, when using ESP32 Serial can't be used for FlipFlat communication.
|
|
|
+// Due to driver imitations in de indi driver, when using ESP32 Serial can't be used for FlipFlat communication.
|
|
|
// Use Serial 2 (pins 16 and 17) instead. Standard Serial is used for debug messages
|
|
|
|
|
|
#include <FlipFlat.h>
|
|
@@ -19,7 +19,11 @@ EasyButton brightness_plus(BRIGHT_PLUS);
|
|
|
EasyButton brightness_min(BRIGHT_MIN);
|
|
|
EasyButton cover_control(COVER_FF);
|
|
|
|
|
|
+#ifdef UNIPOLAR
|
|
|
+AccelStepper stepper(AccelStepper::FULL4WIRE, STEP_PIN1, STEP_PIN3, STEP_PIN2, STEP_PIN4);
|
|
|
+#else
|
|
|
AccelStepper stepper(AccelStepper::DRIVER, STEP_PIN, DIR_PIN);
|
|
|
+#endif
|
|
|
|
|
|
void setup()
|
|
|
{
|
|
@@ -27,28 +31,25 @@ void setup()
|
|
|
|
|
|
LOG("Debug mode");
|
|
|
LOG("Starting FlipFlat");
|
|
|
- LOG("Setup PWM pin");
|
|
|
|
|
|
+ LOG("Setup PWM pin");
|
|
|
pinMode(PWM, OUTPUT);
|
|
|
|
|
|
LOG("Setup brightness buttons");
|
|
|
-
|
|
|
brightness_plus.begin();
|
|
|
brightness_plus.onPressed(increaseBrightness);
|
|
|
brightness_min.begin();
|
|
|
brightness_min.onPressed(decreaseBrightness);
|
|
|
|
|
|
LOG("Setup open-close button");
|
|
|
-
|
|
|
cover_control.begin();
|
|
|
cover_control.onPressed(handleCoverSwitch);
|
|
|
|
|
|
LOG("Initializing stepper");
|
|
|
-
|
|
|
stepper.setMaxSpeed(1000);
|
|
|
stepper.setAcceleration(50);
|
|
|
- stepper.setSpeed(200);
|
|
|
- stepper.moveTo(STEPS);
|
|
|
+ stepper.setSpeed(400);
|
|
|
+ //stepper.moveTo(STEPS);
|
|
|
}
|
|
|
|
|
|
void loop()
|
|
@@ -62,6 +63,8 @@ void loop()
|
|
|
LOG("Command received");
|
|
|
parseCommand();
|
|
|
}
|
|
|
+
|
|
|
+ stepper.run();
|
|
|
}
|
|
|
|
|
|
void increaseBrightness()
|
|
@@ -118,12 +121,12 @@ void processCommand(const char *cmd, const char *data)
|
|
|
{
|
|
|
switch (*cmd)
|
|
|
{
|
|
|
- /*
|
|
|
- Ping device
|
|
|
- Request: >POOO\r
|
|
|
- Return : *PiiOOO\n
|
|
|
- ii = DEVICE_ID
|
|
|
- */
|
|
|
+ /*
|
|
|
+ Ping device
|
|
|
+ Request: >POOO\r
|
|
|
+ Return : *PiiOOO\n
|
|
|
+ ii = DEVICE_ID
|
|
|
+ */
|
|
|
case 'P':
|
|
|
LOG("Ping received");
|
|
|
FF_SERIAL << F("*P") << deviceId << F("OOO\n");
|
|
@@ -160,7 +163,7 @@ void processCommand(const char *cmd, const char *data)
|
|
|
Request: >LOOO\r
|
|
|
Return : *LiiOOO\n
|
|
|
ii = deviceId
|
|
|
- */
|
|
|
+ */
|
|
|
case 'L':
|
|
|
LOG("Turn on received");
|
|
|
FF_SERIAL << F("*L") << deviceId << F("OOO\n");
|
|
@@ -168,12 +171,12 @@ void processCommand(const char *cmd, const char *data)
|
|
|
setBrightness(brightness);
|
|
|
break;
|
|
|
|
|
|
- /*
|
|
|
- Turn light off
|
|
|
- Request: >DOOO\r
|
|
|
- Return : *DiiOOO\n
|
|
|
- id = deviceId
|
|
|
- */
|
|
|
+ /*
|
|
|
+ Turn light off
|
|
|
+ Request: >DOOO\r
|
|
|
+ Return : *DiiOOO\n
|
|
|
+ id = deviceId
|
|
|
+ */
|
|
|
case 'D':
|
|
|
LOG("Turn off received");
|
|
|
FF_SERIAL << F("*D") << deviceId << F("OOO\n");
|
|
@@ -181,14 +184,14 @@ void processCommand(const char *cmd, const char *data)
|
|
|
setBrightness(0);
|
|
|
break;
|
|
|
|
|
|
- /*
|
|
|
- Set brightness
|
|
|
- Request: >Bxxx\r
|
|
|
- xxx = brightness value from 000-255
|
|
|
- Return : *Bidyyy\n
|
|
|
- id = deviceId
|
|
|
- yyy = value that brightness was set from 000-255
|
|
|
- */
|
|
|
+ /*
|
|
|
+ Set brightness
|
|
|
+ Request: >Bxxx\r
|
|
|
+ xxx = brightness value from 000-255
|
|
|
+ Return : *Bidyyy\n
|
|
|
+ id = deviceId
|
|
|
+ yyy = value that brightness was set from 000-255
|
|
|
+ */
|
|
|
case 'B':
|
|
|
LOG("Set brightness received");
|
|
|
FF_SERIAL << F("*B") << deviceId << _WIDTHZ(brightness, 3) << F("\n");
|
|
@@ -200,38 +203,38 @@ void processCommand(const char *cmd, const char *data)
|
|
|
|
|
|
break;
|
|
|
|
|
|
- /*
|
|
|
- Get brightness
|
|
|
- Request: >J000\r
|
|
|
- Return : *Jiiyyy\n
|
|
|
- id = deviceId
|
|
|
- yyy = current brightness value from 000-255
|
|
|
- */
|
|
|
+ /*
|
|
|
+ Get brightness
|
|
|
+ Request: >J000\r
|
|
|
+ Return : *Jiiyyy\n
|
|
|
+ id = deviceId
|
|
|
+ yyy = current brightness value from 000-255
|
|
|
+ */
|
|
|
case 'J':
|
|
|
LOG("Get brightness received");
|
|
|
FF_SERIAL << F("*J") << deviceId << _WIDTHZ(brightness, 3) << F("\n");
|
|
|
break;
|
|
|
|
|
|
- /*
|
|
|
- Get device status:
|
|
|
- Request: >S000\r
|
|
|
- Return : *SiiMLC\n
|
|
|
- ii = deviceId
|
|
|
- M = motor status( 0 stopped, 1 running)
|
|
|
- L = light status( 0 off, 1 on)
|
|
|
- C = Cover Status( 0 moving, 1 closed, 2 open)
|
|
|
- */
|
|
|
+ /*
|
|
|
+ Get device status:
|
|
|
+ Request: >S000\r
|
|
|
+ Return : *SiiMLC\n
|
|
|
+ ii = deviceId
|
|
|
+ M = motor status( 0 stopped, 1 running)
|
|
|
+ L = light status( 0 off, 1 on)
|
|
|
+ C = Cover Status( 0 moving, 1 closed, 2 open)
|
|
|
+ */
|
|
|
case 'S':
|
|
|
LOG("Get status recived");
|
|
|
FF_SERIAL << F("*S") << deviceId << motorStatus << lightStatus << coverStatus << F("\n");
|
|
|
break;
|
|
|
|
|
|
- /*
|
|
|
- Get firmware version
|
|
|
- Request: >V000\r
|
|
|
- Return : *Vii001\n
|
|
|
- ii = deviceId
|
|
|
- */
|
|
|
+ /*
|
|
|
+ Get firmware version
|
|
|
+ Request: >V000\r
|
|
|
+ Return : *Vii001\n
|
|
|
+ ii = deviceId
|
|
|
+ */
|
|
|
case 'V': // get firmware version
|
|
|
LOG("Get firmware version received");
|
|
|
FF_SERIAL << F("*V") << deviceId << F("001") << F("\n");
|
|
@@ -265,15 +268,14 @@ void closeFlipFlat()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void rotateMotor(float newAngle)
|
|
|
+void rotateMotor(float angle)
|
|
|
{
|
|
|
if (motorDirection == OPENING)
|
|
|
{
|
|
|
motorStatus = RUNNING;
|
|
|
coverStatus = NEITHER_OPEN_NOR_CLOSED;
|
|
|
|
|
|
- stepper.move(STEPS * newAngle / 360.0);
|
|
|
- stepper.runToPosition();
|
|
|
+ stepper.move(STEPS * angle / 360.0);
|
|
|
|
|
|
coverStatus = OPEN;
|
|
|
}
|
|
@@ -284,8 +286,7 @@ void rotateMotor(float newAngle)
|
|
|
motorStatus = RUNNING;
|
|
|
coverStatus = NEITHER_OPEN_NOR_CLOSED;
|
|
|
|
|
|
- stepper.move(-STEPS * newAngle / 360.0);
|
|
|
- stepper.runToPosition();
|
|
|
+ stepper.move(-STEPS * angle / 360.0);
|
|
|
|
|
|
coverStatus = CLOSED;
|
|
|
}
|
|
@@ -302,19 +303,20 @@ void setupSerial()
|
|
|
LOG_SERIAL.begin(9600);
|
|
|
#endif
|
|
|
|
|
|
-#ifdef ARDUINO_AVR_LEONARDO
|
|
|
+#ifdef __AVR_ATmega32U4__
|
|
|
FF_SERIAL.begin(9600);
|
|
|
LOG_SERIAL.begin(9600);
|
|
|
#endif
|
|
|
|
|
|
LOG("Logging serial up and running");
|
|
|
LOG("FlipFlat Serial up and running");
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-void handleCoverSwitch(){
|
|
|
- switch (coverStatus){
|
|
|
- case CLOSED:
|
|
|
+void handleCoverSwitch()
|
|
|
+{
|
|
|
+ switch (coverStatus)
|
|
|
+ {
|
|
|
+ case CLOSED:
|
|
|
LOG("Opening cover");
|
|
|
openFlipFlat();
|
|
|
break;
|