Library for googly eyes
Eyes.h@0:06df44729143, 2015-12-15 (annotated)
- Committer:
- electromotivated
- Date:
- Tue Dec 15 00:36:42 2015 +0000
- Revision:
- 0:06df44729143
- Child:
- 1:0791bb5735b4
Upload;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
electromotivated | 0:06df44729143 | 1 | /* |
electromotivated | 0:06df44729143 | 2 | Library for the 4DGL uLCD-144-G2 LCD Display that Makes and |
electromotivated | 0:06df44729143 | 3 | Contols Eyes. |
electromotivated | 0:06df44729143 | 4 | |
electromotivated | 0:06df44729143 | 5 | TODO: Allow user to define eye color, size, etc. |
electromotivated | 0:06df44729143 | 6 | Allow user to adjust serial baudrate, etc. |
electromotivated | 0:06df44729143 | 7 | */ |
electromotivated | 0:06df44729143 | 8 | |
electromotivated | 0:06df44729143 | 9 | #ifndef EYES_H |
electromotivated | 0:06df44729143 | 10 | #define EYES_H |
electromotivated | 0:06df44729143 | 11 | |
electromotivated | 0:06df44729143 | 12 | #include "mbed.h" |
electromotivated | 0:06df44729143 | 13 | #include "uLCD_4DGL.h" |
electromotivated | 0:06df44729143 | 14 | #include "Timeout.h" |
electromotivated | 0:06df44729143 | 15 | |
electromotivated | 0:06df44729143 | 16 | class Eyes{ |
electromotivated | 0:06df44729143 | 17 | public: |
electromotivated | 0:06df44729143 | 18 | enum EXPRESSION{NORMAL, SUPRISED, SCARED, ANGRY}; |
electromotivated | 0:06df44729143 | 19 | enum DIRECTION{U = 270, D = 90, L = 0, R = 180, C, |
electromotivated | 0:06df44729143 | 20 | UL= 315, UR= 225,DL= 45, DR = 135}; |
electromotivated | 0:06df44729143 | 21 | enum GESTURE{BLINK, CLOSE}; |
electromotivated | 0:06df44729143 | 22 | typedef struct{int x; int y;}Coord_t; |
electromotivated | 0:06df44729143 | 23 | |
electromotivated | 0:06df44729143 | 24 | /* |
electromotivated | 0:06df44729143 | 25 | Constructor for Eyes Objects |
electromotivated | 0:06df44729143 | 26 | */ |
electromotivated | 0:06df44729143 | 27 | Eyes(PinName tx, PinName rx, PinName reset); |
electromotivated | 0:06df44729143 | 28 | |
electromotivated | 0:06df44729143 | 29 | /* |
electromotivated | 0:06df44729143 | 30 | Change the active direction eyes look. |
electromotivated | 0:06df44729143 | 31 | @param direction The direction to look |
electromotivated | 0:06df44729143 | 32 | */ |
electromotivated | 0:06df44729143 | 33 | void look(DIRECTION direction); |
electromotivated | 0:06df44729143 | 34 | |
electromotivated | 0:06df44729143 | 35 | /* |
electromotivated | 0:06df44729143 | 36 | Display a gesture. |
electromotivated | 0:06df44729143 | 37 | |
electromotivated | 0:06df44729143 | 38 | BLINK is random ~100 to ~400ms. For user defined blink duration |
electromotivated | 0:06df44729143 | 39 | call CLOSE, then draw() some user defined time later. |
electromotivated | 0:06df44729143 | 40 | |
electromotivated | 0:06df44729143 | 41 | NOTE: Some gestures use a timer interrupt to make a |
electromotivated | 0:06df44729143 | 42 | callback to complete a gesture, such as BLINK. Although this should |
electromotivated | 0:06df44729143 | 43 | be ok, as the draw method is called on the interrupt and simply |
electromotivated | 0:06df44729143 | 44 | redraws eyes with current setting, the user should be aware if they |
electromotivated | 0:06df44729143 | 45 | are getting some weird side effects. |
electromotivated | 0:06df44729143 | 46 | |
electromotivated | 0:06df44729143 | 47 | @param gesture The gesture to display |
electromotivated | 0:06df44729143 | 48 | */ |
electromotivated | 0:06df44729143 | 49 | void gesture(GESTURE gesture); |
electromotivated | 0:06df44729143 | 50 | |
electromotivated | 0:06df44729143 | 51 | /* |
electromotivated | 0:06df44729143 | 52 | Draw eyes conveying given expression (keeps current look direction) |
electromotivated | 0:06df44729143 | 53 | @param expression The expression of the eyes |
electromotivated | 0:06df44729143 | 54 | */ |
electromotivated | 0:06df44729143 | 55 | void express(EXPRESSION expression); |
electromotivated | 0:06df44729143 | 56 | |
electromotivated | 0:06df44729143 | 57 | /* |
electromotivated | 0:06df44729143 | 58 | Draw Eyes. Uses the currently active direction and expression. |
electromotivated | 0:06df44729143 | 59 | Call this after calling express() and or look() methods, this |
electromotivated | 0:06df44729143 | 60 | allows greater flexibility to user and reduces calls to draw |
electromotivated | 0:06df44729143 | 61 | as user can set both expression and direction and make a single |
electromotivated | 0:06df44729143 | 62 | call to draw. |
electromotivated | 0:06df44729143 | 63 | */ |
electromotivated | 0:06df44729143 | 64 | void draw(); |
electromotivated | 0:06df44729143 | 65 | |
electromotivated | 0:06df44729143 | 66 | private: |
electromotivated | 0:06df44729143 | 67 | uLCD_4DGL lcd; // serial tx, serial rx, reset pin; |
electromotivated | 0:06df44729143 | 68 | Timeout callback_timer; |
electromotivated | 0:06df44729143 | 69 | |
electromotivated | 0:06df44729143 | 70 | EXPRESSION active_expression; |
electromotivated | 0:06df44729143 | 71 | DIRECTION active_direction; |
electromotivated | 0:06df44729143 | 72 | /*TODO: Make these user defined*/ |
electromotivated | 0:06df44729143 | 73 | int eye_radius; |
electromotivated | 0:06df44729143 | 74 | int iris_radius; |
electromotivated | 0:06df44729143 | 75 | int pupil_radius; |
electromotivated | 0:06df44729143 | 76 | /******************************/ |
electromotivated | 0:06df44729143 | 77 | Coord_t right_eye_center; |
electromotivated | 0:06df44729143 | 78 | Coord_t left_eye_center; |
electromotivated | 0:06df44729143 | 79 | Coord_t eye_direction_offset; // Updated by look direction |
electromotivated | 0:06df44729143 | 80 | // Used to apply an offset to |
electromotivated | 0:06df44729143 | 81 | // iris and pupils to make |
electromotivated | 0:06df44729143 | 82 | // eyes look in a direction |
electromotivated | 0:06df44729143 | 83 | }; |
electromotivated | 0:06df44729143 | 84 | |
electromotivated | 0:06df44729143 | 85 | #endif |