pixy2 smart camera library www.pixycam.com
Pixy2 Library project (using UART interface)
pixy2.h
- Committer:
- haarkon
- Date:
- 2019-02-28
- Revision:
- 0:dde1b9d6c9d6
- Child:
- 1:dd81f4065b6b
File content as of revision 0:dde1b9d6c9d6:
/** * @author Hugues Angelis * * @section LICENSE * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * @section DESCRIPTION * * CMUCAM 5 - Pixy2 * * Datasheet, FAQ and PC drivers : * * http://www.pixycam.com/ */ #ifndef _PIXY2_ #define _PIXY2_ /** * Include : Mbed Library */ #include "mbed.h" /** * Defines */ #define PIXY2_NCSHEADERSIZE 4 #define PIXY2_CSHEADERSIZE 4 #define PIXY2_SYNC 0xC1AE #define PIXY2_CSSYNC 0xC1AF #define PIXY2_ACK 1 #define PIXY2_ASK_RESOL 12 #define PIXY2_REP_RESOL 13 #define PIXY2_ASK_VERS 14 #define PIXY2_REP_VERS 15 #define PIXY2_SET_BRIGHT 16 #define PIXY2_SET_SERVOS 18 #define PIXY2_SET_LED 20 #define PIXY2_SET_LAMP 22 #define PIXY2_ASK_FPS 24 #define PIXY2_ASK_BLOC 32 #define PIXY2_REP_BLOC 33 #define PIXY2_ASK_LINE 48 #define PIXY2_REP_LINE 49 #define PIXY2_SET_MODE 54 #define PIXY2_SET_TURN 58 #define PIXY2_SET_VECTOR 56 #define PIXY2_SET_DEFTURN 60 #define PIXY2_SET_REVERSE 62 #define PIXY2_ASK_VIDEO 112 /** * \struct Byte -> Short hand for unsigned char * \struct Word -> Short hand for unsigned short * \struct lWord -> Short hand for unsigned long */ typedef unsigned char Byte; typedef unsigned short Word; typedef unsigned long lWord; typedef enum {idle, messageSent, receivingHeader, headerReceived, receivingData, dataReceived} T_Pixy2State; typedef union { Word mot; Byte octet[2]; }T_Word; typedef union { lWord motLong; Word mot[2]; Byte octet[4]; }T_lWord; typedef struct { Word pixSync; Byte pixType; Byte pixLength; }T_pixy2Header; typedef struct { T_pixy2Header header; Byte data[5]; }T_pixy2sendFrame; typedef union { T_pixy2sendFrame frame; Byte data[9]; }T_pixy2sendBuffer; typedef struct { Word pixSync; Byte pixType; Byte pixLength; Word pixChecksum; }T_pixy2RcvHeader; typedef struct { lWord pixAck; }T_pixy2AckCode; typedef struct { Word pixHWVersion; Byte pixFWVersionMaj; Byte pixFWVersionMin; Word pixFWBuild; char pixHFString[10]; }T_Pixy2Version; typedef struct { Word pixFrameWidth; Word pixFrameHeigth; }T_Pixy2Resolution; typedef struct { lWord pixFps; }T_pixy2Framerate; typedef struct { Word pixSignature; Word pixX; Word pixY; Word pixWidth; Word pixHeight; Word pixAngle; Byte pixIndex; Byte pixAge; }T_pixy2Bloc; typedef struct { Byte pixX0; Byte pixY0; Byte pixX1; Byte pixY1; Byte pixIndex; Byte pixFlags; }T_Pixy2Vector; typedef struct { Byte pixIndex; Byte pixReserved; Word pixAngle; }T_Pixy2InterLine; typedef struct { Byte pixX; Byte pixY; Byte pixN; Byte pixReserved; }T_pixy2Intersection; typedef struct { Byte pixX; Byte pixY; Byte pixFlag; Byte pixCode; }T_pixy2BarCode; typedef struct { Byte pixType; Byte pixLength; }T_pixy2LineFeature; typedef struct { Byte pixBlue; Byte pixGreen; Byte pixRed; }T_pixy2Pixel; /** * Pixy2 : CMU CAM 5 - Smart camera * More informations at http://www.pixycam.com/ */ class PIXY2 { protected : Serial* _Pixy2; public : /** * Constructor of pixy2 object. * * @param tx : the Mbed pin used as TX * @param rx : the Mbed pin used as RX * @param debit : the bitrate of the serial (max value is 230400 b/s) */ PIXY2(PinName tx, PinName rx, int debit = 230400); // Fonctions publiques int pixy2_getVersion (T_Pixy2Version *version); int pixy2_getResolution (T_Pixy2Resolution *resolution); int pixy2_setCameraBrightness (Byte brightness); int pixy2_setServos (Word s0, Word s1); int pixy2_setLED (Byte red, Byte green, Byte blue); int pixy2_setLamp (Byte upper, Byte lower); int pixy2_getFPS (T_pixy2Framerate framerate); int pixy2_getBlocks (Byte sigmap, Byte maxBloc); int pixy2_getMainFeature (Byte type, Byte features); int pixy2_getAllFeature (Byte features); int pixy2_setMode (Byte mode); int pixy2_setNexTurn (Word angle); int pixy2_setDefaultTurn (Word angle); int pixy2_setVector (Byte vectorIndex); int pixy2_ReverseVector (void); int pixy2_getRGB (Word x, Word y, Byte saturate, T_pixy2Pixel *pixel); // Variables globales Publiques Byte Pixy2_numBlocks; T_pixy2Bloc Pixy2_blocks[]; Byte Pixy2_numVectors; T_Pixy2Vector Pixy2_vectors[]; Byte Pixy2_numIntersections; T_pixy2Intersection Pixy2_intersections[]; T_Pixy2InterLine Pixy2_intLines[]; Byte Pixy2_numBarcodes; T_pixy2BarCode Pixy2_barcodes[]; private : // Variables globales Privées T_Pixy2State etat; Byte* Pixy2_buffer; Byte wPointer, rPointer, dataSize; Byte frameContainChecksum; // Fonctions privées int pixy2_sndGetVersion (void); int pixy2_sndGetResolution (void); int pixy2_sndSetCameraBrightness (Byte brightness); int pixy2_sndSetServo (Word s0, Word s1); int pixy2_sndSetLED (Byte red, Byte green, Byte blue); int pixy2_sndSetLamp (Byte upper, Byte lower); int pixy2_sndGetFPS (void); int pixy2_sndGetBlocks (Byte sigmap, Byte maxBloc); int pixy2_sndGetMainFeature (Byte type, Byte feature); int pixy2_sndSetMode (Byte mode); int pixy2_sndSetNexTurn (Word angle); int pixy2_sndSetDefaultTurn (Word angle); int pixy2_sndSetVector (Byte vectorIndex); int pixy2_sndReverseVector (void); int pixy2_sndGetRGB (Word x, Word y, Byte saturate); void pixy2_getByte (); int pixy2_validateChecksum (Byte* tab); }; #endif