Library for googly eyes

Dependents:   Eyes_Demo

Committer:
electromotivated
Date:
Tue Apr 12 02:30:40 2016 +0000
Revision:
2:9dd81fc2623f
Parent:
1:0791bb5735b4
Added new method look_there(theta, dist) allowing finer control of direction and distance to look;

Who changed what in which revision?

UserRevisionLine numberNew 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 1:0791bb5735b4 7 Fix memory leak? LCD stops working and displays
electromotivated 1:0791bb5735b4 8 some weird stuff after running for awhile, this
electromotivated 1:0791bb5735b4 9 needs fixin'
electromotivated 0:06df44729143 10 */
electromotivated 0:06df44729143 11
electromotivated 0:06df44729143 12 #ifndef EYES_H
electromotivated 0:06df44729143 13 #define EYES_H
electromotivated 0:06df44729143 14
electromotivated 0:06df44729143 15 #include "mbed.h"
electromotivated 0:06df44729143 16 #include "uLCD_4DGL.h"
electromotivated 0:06df44729143 17 #include "Timeout.h"
electromotivated 0:06df44729143 18
electromotivated 0:06df44729143 19 class Eyes{
electromotivated 0:06df44729143 20 public:
electromotivated 0:06df44729143 21 enum EXPRESSION{NORMAL, SUPRISED, SCARED, ANGRY};
electromotivated 0:06df44729143 22 enum DIRECTION{U = 270, D = 90, L = 0, R = 180, C,
electromotivated 0:06df44729143 23 UL= 315, UR= 225,DL= 45, DR = 135};
electromotivated 2:9dd81fc2623f 24 enum GESTURE{BLINK, CLOSE, SHAKE};
electromotivated 0:06df44729143 25 typedef struct{int x; int y;}Coord_t;
electromotivated 0:06df44729143 26
electromotivated 0:06df44729143 27 /*
electromotivated 0:06df44729143 28 Constructor for Eyes Objects
electromotivated 0:06df44729143 29 */
electromotivated 0:06df44729143 30 Eyes(PinName tx, PinName rx, PinName reset);
electromotivated 0:06df44729143 31
electromotivated 0:06df44729143 32 /*
electromotivated 0:06df44729143 33 Change the active direction eyes look.
electromotivated 0:06df44729143 34 @param direction The direction to look
electromotivated 0:06df44729143 35 */
electromotivated 0:06df44729143 36 void look(DIRECTION direction);
electromotivated 0:06df44729143 37
electromotivated 0:06df44729143 38 /*
electromotivated 2:9dd81fc2623f 39 Change the distance and direction the eyes look.
electromotivated 2:9dd81fc2623f 40 @param theta The angle to look in degrees
electromotivated 2:9dd81fc2623f 41 @param dist The normalized distance to look in given theta, i.e
electromotivated 2:9dd81fc2623f 42 0 keeps eyes centered and 1 looks fully in given theta
electromotivated 2:9dd81fc2623f 43 in between values give make eyes look more or less in
electromotivated 2:9dd81fc2623f 44 theta.
electromotivated 2:9dd81fc2623f 45 */
electromotivated 2:9dd81fc2623f 46 void look_there(int theta, float dist);
electromotivated 2:9dd81fc2623f 47
electromotivated 2:9dd81fc2623f 48 /*
electromotivated 0:06df44729143 49 Display a gesture.
electromotivated 0:06df44729143 50
electromotivated 0:06df44729143 51 BLINK is random ~100 to ~400ms. For user defined blink duration
electromotivated 0:06df44729143 52 call CLOSE, then draw() some user defined time later.
electromotivated 0:06df44729143 53
electromotivated 0:06df44729143 54 NOTE: Some gestures use a timer interrupt to make a
electromotivated 0:06df44729143 55 callback to complete a gesture, such as BLINK. Although this should
electromotivated 0:06df44729143 56 be ok, as the draw method is called on the interrupt and simply
electromotivated 0:06df44729143 57 redraws eyes with current setting, the user should be aware if they
electromotivated 0:06df44729143 58 are getting some weird side effects.
electromotivated 0:06df44729143 59
electromotivated 0:06df44729143 60 @param gesture The gesture to display
electromotivated 0:06df44729143 61 */
electromotivated 0:06df44729143 62 void gesture(GESTURE gesture);
electromotivated 0:06df44729143 63
electromotivated 0:06df44729143 64 /*
electromotivated 0:06df44729143 65 Draw eyes conveying given expression (keeps current look direction)
electromotivated 0:06df44729143 66 @param expression The expression of the eyes
electromotivated 0:06df44729143 67 */
electromotivated 0:06df44729143 68 void express(EXPRESSION expression);
electromotivated 0:06df44729143 69
electromotivated 0:06df44729143 70 /*
electromotivated 0:06df44729143 71 Draw Eyes. Uses the currently active direction and expression.
electromotivated 0:06df44729143 72 Call this after calling express() and or look() methods, this
electromotivated 0:06df44729143 73 allows greater flexibility to user and reduces calls to draw
electromotivated 0:06df44729143 74 as user can set both expression and direction and make a single
electromotivated 0:06df44729143 75 call to draw.
electromotivated 0:06df44729143 76 */
electromotivated 0:06df44729143 77 void draw();
electromotivated 0:06df44729143 78
electromotivated 0:06df44729143 79 private:
electromotivated 0:06df44729143 80 uLCD_4DGL lcd; // serial tx, serial rx, reset pin;
electromotivated 0:06df44729143 81 Timeout callback_timer;
electromotivated 0:06df44729143 82
electromotivated 0:06df44729143 83 EXPRESSION active_expression;
electromotivated 0:06df44729143 84 DIRECTION active_direction;
electromotivated 0:06df44729143 85 /*TODO: Make these user defined*/
electromotivated 0:06df44729143 86 int eye_radius;
electromotivated 0:06df44729143 87 int iris_radius;
electromotivated 0:06df44729143 88 int pupil_radius;
electromotivated 0:06df44729143 89 /******************************/
electromotivated 0:06df44729143 90 Coord_t right_eye_center;
electromotivated 0:06df44729143 91 Coord_t left_eye_center;
electromotivated 0:06df44729143 92 Coord_t eye_direction_offset; // Updated by look direction
electromotivated 0:06df44729143 93 // Used to apply an offset to
electromotivated 0:06df44729143 94 // iris and pupils to make
electromotivated 0:06df44729143 95 // eyes look in a direction
electromotivated 0:06df44729143 96 };
electromotivated 0:06df44729143 97
electromotivated 0:06df44729143 98 #endif