Library for googly eyes

Dependents:   Eyes_Demo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Eyes.h Source File

Eyes.h

00001 /*
00002     Library for the 4DGL uLCD-144-G2 LCD Display that Makes and 
00003     Contols Eyes. 
00004     
00005     TODO: Allow user to define eye color, size, etc.
00006           Allow user to adjust serial baudrate, etc.
00007           Fix memory leak? LCD stops working and displays
00008           some weird stuff after running for awhile, this 
00009           needs fixin'
00010 */
00011 
00012 #ifndef EYES_H
00013 #define EYES_H
00014 
00015 #include "mbed.h"
00016 #include "uLCD_4DGL.h"
00017 #include "Timeout.h"
00018 
00019 class Eyes{
00020     public: 
00021     enum EXPRESSION{NORMAL, SUPRISED, SCARED, ANGRY}; 
00022     enum DIRECTION{U = 270, D = 90, L = 0, R = 180, C, 
00023                    UL= 315, UR= 225,DL= 45, DR = 135};
00024     enum GESTURE{BLINK, CLOSE, SHAKE};
00025     typedef struct{int x; int y;}Coord_t;
00026     
00027     /*
00028         Constructor for Eyes Objects
00029     */
00030     Eyes(PinName tx, PinName rx, PinName reset);
00031     
00032     /* 
00033         Change the active direction eyes look. 
00034         @param direction     The direction to look
00035     */
00036     void look(DIRECTION direction);
00037     
00038     /*
00039         Change the distance and direction the eyes look.
00040         @param theta    The angle to look in degrees
00041         @param dist     The normalized distance to look in given theta, i.e
00042                         0 keeps eyes centered and 1 looks fully in given theta
00043                         in between values give make eyes look more or less in 
00044                         theta.
00045     */
00046     void look_there(int theta, float dist);
00047     
00048     /*
00049         Display a gesture. 
00050         
00051         BLINK is random ~100 to ~400ms. For user defined blink duration
00052         call CLOSE, then draw() some user defined time later.
00053         
00054         NOTE: Some gestures use a timer interrupt to make a 
00055         callback to complete a gesture, such as BLINK. Although this should
00056         be ok, as the draw method is called on the interrupt and simply
00057         redraws eyes with current setting, the user should be aware if they
00058         are getting some weird side effects.
00059         
00060         @param gesture  The gesture to display
00061     */
00062     void gesture(GESTURE gesture);
00063     
00064     /* 
00065         Draw eyes conveying given expression (keeps current look direction)
00066         @param expression    The expression of the eyes
00067     */  
00068     void express(EXPRESSION expression);
00069     
00070     /*
00071         Draw Eyes. Uses the currently active direction and expression.
00072         Call this after calling express() and or look() methods, this
00073         allows greater flexibility to user and reduces calls to draw
00074         as user can set both expression and direction and make a single
00075         call to draw.
00076     */
00077     void draw();  
00078     
00079     private:
00080     uLCD_4DGL lcd; // serial tx, serial rx, reset pin;
00081     Timeout callback_timer;
00082     
00083     EXPRESSION active_expression;
00084     DIRECTION  active_direction;
00085     /*TODO: Make these user defined*/
00086     int eye_radius;
00087     int iris_radius;
00088     int pupil_radius;
00089     /******************************/
00090     Coord_t right_eye_center;  
00091     Coord_t left_eye_center;
00092     Coord_t eye_direction_offset; // Updated by look direction
00093                                   // Used to apply an offset to 
00094                                   // iris and pupils to make
00095                                   // eyes look in a direction
00096 };
00097 
00098 #endif