#ifndef __FLIPFLAT_H__ #define __FLIPFLAT_H__ #include #include #include #include #include #include #define DEBUG 0 //#define UNIPOLAR #define PWM_FREQUENCY 1000 #ifdef ESP32 #define BRIGHT_PLUS GPIO_NUM_34 #define BRIGHT_MIN GPIO_NUM_35 #define PWM GPIO_NUM_25 #define COER_FF GPIO_NUM_39 #define FF_SERIAL Serial2 #define LOG_SERIAL Serial #endif #ifdef __AVR_ATmega32U4__ #define BRIGHT_PLUS 19 #define BRIGHT_MIN 20 #define PWM 9 #define COVER_FF 18 #define FF_SERIAL Serial #define LOG_SERIAL Serial1 #endif #ifdef UNIPOLAR #define STEP_PIN1 5 #define STEP_PIN2 6 #define STEP_PIN3 7 #define STEP_PIN4 8 #define STEPS 2038 // steps per revolution for the motor 28BYJ-48 #define REDUCTION 15 #else #define STEP_PIN 7 #define DIR_PIN 8 #define STEPS 200 // steps per revolution for the motor NEMA17 #define REDUCTION 1 #define R_SENSE 0.11f #define CS_PIN 6 #define EN_PIN 5 #endif #define MAX_SPEED 200 #define MICROSTEPS 2 #define COVER_ANGLE 180.0 enum devices { FLAT_MAN_L = 10, FLAT_MAN_XL = 15, FLAT_MAN = 19, FLIP_FLAT = 99 }; enum motorStatuses { STOPPED = 0, RUNNING }; enum lightStatuses { OFF = 0, ON }; enum shutterStatuses { NEITHER_OPENED_NOR_CLOSED = 0, // ie not open or closed...could be moving CLOSED, OPENED, TIMED_OUT }; enum motorDirections { CLOSING = -1, IDLE, OPENING }; enum commands { NONE, PING, OPEN, CLOSE, LIGHT_ON, LIGHT_OFF, SET_BRIGHTNESS, GET_BRIGHTNESS, STATUS, VERSION }; void initializeStepper(); void setupSerial(); void handleSerial(); void handleCoverButton(); void handleIncreaseButton(); void handleDecreaseButton(); void increaseBrightness(); void decreaseBrightness(); void setBrightness(int newBrightness); void openFlipFlat(); void closeFlipFlat(); void rotateMotor(int direction); void processCommand(const char* cmd, const char *data); void parseCommand(); void sendCommandResponse(); #if DEBUG #ifndef LOG #define LOG(A) LOG_SERIAL << F(A) << endl #define LOG1(A, B) LOG_SERIAL << F(A) << B << endl; #endif #else #define LOG(A) #define LOG1(A, B) #endif //DEBUG #endif //__FLIPFLAT_H__