root/RF_BT_Tail/Moves.h

Revision 244, 5.2 kB (checked in by phil, 4 years ago)

added initial Tail Source Package

Line 
1 // File: Moves.h
2 //------------------------------------------------------------------------------
3 // Author: Giovanni de Sanctis
4 // Email: info@lateral-technologies.com
5 //------------------------------------------------------------------------------
6 // Date: Dec 2018
7 // Manages the tail moves and LED patterns
8 //------------------------------------------------------------------------------
9
10
11 #ifndef MOVES_H
12 #define MOVES_H
13
14 #include <stdint.h>
15
16 #define MAX_MOVES       5u              //Max number of positions per cycle
17 #define MAX_PATTERNS    32u             //Max steps in a LED pattern
18 #define MAX_CYCLES      1000u   //Max number of cycles (only a safety limit, not critical)
19 #define MAX_MOVE_POS    9u      //Max number of preset positions of the servos (P0..P8)
20 #define MAX_LEDS_POS    9u      //Max number of preset brightness levels for the led strip
21 #define MAX_STEP_VAL    127u    //Max value for parameter step (both servos and leds)
22 #define MAX_CMD_LEN     8u              //Max number of char in a BT command
23 #define MAX_LEDS_CMDS   13u     //Number of LEDs commands
24 #define MAX_MOVE_CMDS   16u     //Number of Tail move commands
25
26 #define MAX_USER_MOVES  4u      //Max number of user presets for moves
27 #define MAX_USER_LEDS   4u      //Max number of user presets for led patterns
28
29 #define MAX_GRP_SLOW    3u      //Slow wag group
30 #define MAX_GRP_FAST    3u      //Fast wag group
31 #define MAX_GRP_TREM    3u      //Trembling group
32 #define MAX_GRP_EREC    1u      //Erected group
33 #define MAX_GRP_RAND    16u     //Max pseudo random moves and intervals
34
35 #define MAX_GRP_BT      3u      //Number of groups
36 #define MAX_MOV_BT      4u      //Number of moves in each group
37
38 #define MASK_GRP_BT1    1u      //Bit mask for group 1
39 #define MASK_GRP_BT2    2u      //Bit mask for group 2
40 #define MASK_GRP_BT3    3u      //Bit mask for group 3
41
42 #define MAX_LED_GRPA    2u      //Leds ON/OFF
43 #define MAX_LED_GRPB    3u      //Leds Rect/Tri/Saw
44 #define MAX_LED_GRPC    2u      //Leds Beacon/SOS
45
46 typedef struct MoveType
47 {
48   uint8_t cycles;                               //Times the pattern is repeated
49   int8_t pos1[MAX_MOVES];       //Positions for servo 1
50   int8_t pos2[MAX_MOVES];       //Positions for servo 2
51   int8_t steps[MAX_MOVES];    //Total number of steps from 1 pos to next
52 }MoveType;
53
54 typedef struct LedsType
55 {
56   uint8_t cycles;                               //Times the patterns is repeated (0=default duration)
57   int8_t pos[MAX_PATTERNS];     //Brightness points
58   int8_t steps[MAX_PATTERNS]; //Steps in between points
59 }LedsType;
60
61 typedef struct MoveCmd
62 {
63   char cmdStr[MAX_CMD_LEN+1];
64   const MoveType* cmd;
65 }MoveCmd;
66
67 typedef struct LedsCmd
68 {
69   char cmdStr[MAX_CMD_LEN+1];
70   const LedsType* cmd;
71 }LedsCmd;
72
73 typedef struct MoveStruct
74 {
75   const MoveType* movePtr;
76   uint8_t   moveIter;
77   uint8_t   cycIter;
78   int16_t   stepIter;
79   int16_t   pos1,pos2,steps;
80   int16_t   d1,d2;
81 }MoveStruct;
82
83 typedef struct LedsStruct
84 {
85   const LedsType* ledsPtr;
86   uint8_t   moveIter;
87   int16_t   stepIter;
88   int16_t   cycIter;
89   int16_t   steps;
90   int16_t   pos;
91   int16_t   d;
92 }LedsStruct;
93
94 typedef struct AutoStruct
95 {
96   uint8_t  t1,t2;           //Min and max pause time in
97   uint16_t timeout;         //timeout in T_SERVO units
98   uint16_t pause;           //pause in T_SERVO units
99   uint8_t  grps;            //Move groups (last 3 lsbs)
100 }AutoStruct;
101
102 typedef enum
103 {
104   ACK_WAITING=0x00,
105   ACK_END_MOVE=0x01,
106   ACK_END_LEDS=0x02,
107   ACK_RUNNING=0x03,
108   ACK_END_AUTO=0x04
109 }AckEnum;
110
111 extern const MoveCmd MOVE_CMDS[MAX_MOVE_CMDS];
112 extern const LedsCmd LEDS_CMDS[MAX_LEDS_CMDS];
113
114 extern const MoveType* const moveGrpSlow[MAX_GRP_SLOW];
115 extern const MoveType* const moveGrpFast[MAX_GRP_FAST];
116 extern const MoveType* const moveGrpTrem[MAX_GRP_TREM];
117 extern const MoveType* const moveGrpErec[MAX_GRP_EREC];
118
119 extern const MoveType* const moveRndGrp[MAX_GRP_RAND];    //Random moves
120 extern const uint8_t   moveRndGrpT[MAX_GRP_RAND];         //Random set times
121
122 //Move groups (used in RF mode)
123 extern const LedsType* const ledsGrpA[MAX_LED_GRPA];
124 extern const LedsType* const ledsGrpB[MAX_LED_GRPB];
125 extern const LedsType* const ledsGrpC[MAX_LED_GRPC];
126
127 //Move groups for 'auto moves' (used in BT mode)
128 extern const MoveType* const moveGrpBT[MAX_GRP_BT][MAX_MOV_BT];
129
130 void movesInit();
131
132 //Stores user-defined move/led pattern to the specified preset location
133 uint8_t setUserMove(uint8_t preset,uint8_t len,uint8_t cycles,int8_t *pos1,int8_t *pos2,int8_t *steps);
134 uint8_t setUserLeds(uint8_t preset,uint8_t len,uint8_t cycles,int8_t *pos,int8_t *steps);
135
136 //Sets up automatic mode (random moves for a specified length of time)
137 void setAuto(uint8_t t1, uint8_t t2, uint8_t dur, uint8_t grps);
138
139 //Cancels an ongoing 'auto move' session - will finish the current move if one is running
140 void abortAuto();
141
142 //Sets up move variables for updateMove()
143 void setMove(const MoveType* movePtr);
144
145 //Updates the position of the servos to the next in the current move description
146 //Returns 1 if the move is complete (and returned home)
147 AckEnum updateMove();
148
149 //Sets up led pattern variables for updateLeds()
150 void setLEDs(const LedsType* patt);
151
152 //Updates the brightness of the LED strip to the next in the current description
153 //Returns 1 if the pattern is complete
154 AckEnum updateLEDs();
155
156 #endif  /* MOVES_H */
157
Note: See TracBrowser for help on using the browser.