// File: Moves.h //------------------------------------------------------------------------------ // Author: Giovanni de Sanctis // Email: info@lateral-technologies.com //------------------------------------------------------------------------------ // Date: Dec 2018 // Manages the tail moves and LED patterns //------------------------------------------------------------------------------ #ifndef MOVES_H #define MOVES_H #include #define MAX_MOVES 5u //Max number of positions per cycle #define MAX_PATTERNS 32u //Max steps in a LED pattern #define MAX_CYCLES 1000u //Max number of cycles (only a safety limit, not critical) #define MAX_MOVE_POS 9u //Max number of preset positions of the servos (P0..P8) #define MAX_LEDS_POS 9u //Max number of preset brightness levels for the led strip #define MAX_STEP_VAL 127u //Max value for parameter step (both servos and leds) #define MAX_CMD_LEN 8u //Max number of char in a BT command #define MAX_LEDS_CMDS 13u //Number of LEDs commands #define MAX_MOVE_CMDS 16u //Number of Tail move commands #define MAX_USER_MOVES 4u //Max number of user presets for moves #define MAX_USER_LEDS 4u //Max number of user presets for led patterns #define MAX_GRP_SLOW 3u //Slow wag group #define MAX_GRP_FAST 3u //Fast wag group #define MAX_GRP_TREM 3u //Trembling group #define MAX_GRP_EREC 1u //Erected group #define MAX_GRP_RAND 16u //Max pseudo random moves and intervals #define MAX_GRP_BT 3u //Number of groups #define MAX_MOV_BT 4u //Number of moves in each group #define MASK_GRP_BT1 1u //Bit mask for group 1 #define MASK_GRP_BT2 2u //Bit mask for group 2 #define MASK_GRP_BT3 3u //Bit mask for group 3 #define MAX_LED_GRPA 2u //Leds ON/OFF #define MAX_LED_GRPB 3u //Leds Rect/Tri/Saw #define MAX_LED_GRPC 2u //Leds Beacon/SOS typedef struct MoveType { uint8_t cycles; //Times the pattern is repeated int8_t pos1[MAX_MOVES]; //Positions for servo 1 int8_t pos2[MAX_MOVES]; //Positions for servo 2 int8_t steps[MAX_MOVES]; //Total number of steps from 1 pos to next }MoveType; typedef struct LedsType { uint8_t cycles; //Times the patterns is repeated (0=default duration) int8_t pos[MAX_PATTERNS]; //Brightness points int8_t steps[MAX_PATTERNS]; //Steps in between points }LedsType; typedef struct MoveCmd { char cmdStr[MAX_CMD_LEN+1]; const MoveType* cmd; }MoveCmd; typedef struct LedsCmd { char cmdStr[MAX_CMD_LEN+1]; const LedsType* cmd; }LedsCmd; typedef struct MoveStruct { const MoveType* movePtr; uint8_t moveIter; uint8_t cycIter; int16_t stepIter; int16_t pos1,pos2,steps; int16_t d1,d2; }MoveStruct; typedef struct LedsStruct { const LedsType* ledsPtr; uint8_t moveIter; int16_t stepIter; int16_t cycIter; int16_t steps; int16_t pos; int16_t d; }LedsStruct; typedef struct AutoStruct { uint8_t t1,t2; //Min and max pause time in uint16_t timeout; //timeout in T_SERVO units uint16_t pause; //pause in T_SERVO units uint8_t grps; //Move groups (last 3 lsbs) }AutoStruct; typedef enum { ACK_WAITING=0x00, ACK_END_MOVE=0x01, ACK_END_LEDS=0x02, ACK_RUNNING=0x03, ACK_END_AUTO=0x04 }AckEnum; extern const MoveCmd MOVE_CMDS[MAX_MOVE_CMDS]; extern const LedsCmd LEDS_CMDS[MAX_LEDS_CMDS]; extern const MoveType* const moveGrpSlow[MAX_GRP_SLOW]; extern const MoveType* const moveGrpFast[MAX_GRP_FAST]; extern const MoveType* const moveGrpTrem[MAX_GRP_TREM]; extern const MoveType* const moveGrpErec[MAX_GRP_EREC]; extern const MoveType* const moveRndGrp[MAX_GRP_RAND]; //Random moves extern const uint8_t moveRndGrpT[MAX_GRP_RAND]; //Random set times //Move groups (used in RF mode) extern const LedsType* const ledsGrpA[MAX_LED_GRPA]; extern const LedsType* const ledsGrpB[MAX_LED_GRPB]; extern const LedsType* const ledsGrpC[MAX_LED_GRPC]; //Move groups for 'auto moves' (used in BT mode) extern const MoveType* const moveGrpBT[MAX_GRP_BT][MAX_MOV_BT]; void movesInit(); //Stores user-defined move/led pattern to the specified preset location uint8_t setUserMove(uint8_t preset,uint8_t len,uint8_t cycles,int8_t *pos1,int8_t *pos2,int8_t *steps); uint8_t setUserLeds(uint8_t preset,uint8_t len,uint8_t cycles,int8_t *pos,int8_t *steps); //Sets up automatic mode (random moves for a specified length of time) void setAuto(uint8_t t1, uint8_t t2, uint8_t dur, uint8_t grps); //Cancels an ongoing 'auto move' session - will finish the current move if one is running void abortAuto(); //Sets up move variables for updateMove() void setMove(const MoveType* movePtr); //Updates the position of the servos to the next in the current move description //Returns 1 if the move is complete (and returned home) AckEnum updateMove(); //Sets up led pattern variables for updateLeds() void setLEDs(const LedsType* patt); //Updates the brightness of the LED strip to the next in the current description //Returns 1 if the pattern is complete AckEnum updateLEDs(); #endif /* MOVES_H */