cette librairie contient les fonctions de base permettant de detecter un objet avec la camera pixy
TPixyInterface.h@0:a1e10abfbd19, 2020-11-18 (annotated)
- Committer:
- michelmoulin
- Date:
- Wed Nov 18 13:12:20 2020 +0000
- Revision:
- 0:a1e10abfbd19
cette version de programme permet d'afficher les coordonnees x et y d'un objet detecte par la camera pixy.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
michelmoulin | 0:a1e10abfbd19 | 1 | // |
michelmoulin | 0:a1e10abfbd19 | 2 | // begin license header |
michelmoulin | 0:a1e10abfbd19 | 3 | // |
michelmoulin | 0:a1e10abfbd19 | 4 | // This file is part of Pixy CMUcam5 or "Pixy" for short |
michelmoulin | 0:a1e10abfbd19 | 5 | // |
michelmoulin | 0:a1e10abfbd19 | 6 | // All Pixy source code is provided under the terms of the |
michelmoulin | 0:a1e10abfbd19 | 7 | // GNU General Public License v2 (http://www.gnu.org/licenses/gpl-2.0.html). |
michelmoulin | 0:a1e10abfbd19 | 8 | // Those wishing to use Pixy source code, software and/or |
michelmoulin | 0:a1e10abfbd19 | 9 | // technologies under different licensing terms should contact us at |
michelmoulin | 0:a1e10abfbd19 | 10 | // cmucam@cs.cmu.edu. Such licensing terms are available for |
michelmoulin | 0:a1e10abfbd19 | 11 | // all portions of the Pixy codebase presented here. |
michelmoulin | 0:a1e10abfbd19 | 12 | // |
michelmoulin | 0:a1e10abfbd19 | 13 | // end license header |
michelmoulin | 0:a1e10abfbd19 | 14 | // |
michelmoulin | 0:a1e10abfbd19 | 15 | // This file is for defining the SPI-related classes. It's called Pixy.h instead |
michelmoulin | 0:a1e10abfbd19 | 16 | // of Pixy_SPI.h because it's the default/recommended communication method |
michelmoulin | 0:a1e10abfbd19 | 17 | // with Arduino. This class assumes you are using the ICSP connector to talk to |
michelmoulin | 0:a1e10abfbd19 | 18 | // Pixy from your Arduino. For more information go to: |
michelmoulin | 0:a1e10abfbd19 | 19 | // |
michelmoulin | 0:a1e10abfbd19 | 20 | //http://cmucam.org/projects/cmucam5/wiki/Hooking_up_Pixy_to_a_Microcontroller_(like_an_Arduino) |
michelmoulin | 0:a1e10abfbd19 | 21 | // |
michelmoulin | 0:a1e10abfbd19 | 22 | |
michelmoulin | 0:a1e10abfbd19 | 23 | #ifndef _TPIXY_INTERFACE_H |
michelmoulin | 0:a1e10abfbd19 | 24 | #define _TPIXY_INTERFACE_H |
michelmoulin | 0:a1e10abfbd19 | 25 | |
michelmoulin | 0:a1e10abfbd19 | 26 | #include "TPixy.h" |
michelmoulin | 0:a1e10abfbd19 | 27 | |
michelmoulin | 0:a1e10abfbd19 | 28 | #define PIXY_SYNC_BYTE 0x5a |
michelmoulin | 0:a1e10abfbd19 | 29 | #define PIXY_SYNC_BYTE_DATA 0x5b |
michelmoulin | 0:a1e10abfbd19 | 30 | #define PIXY_BUF_SIZE 16 |
michelmoulin | 0:a1e10abfbd19 | 31 | |
michelmoulin | 0:a1e10abfbd19 | 32 | class TPixyInterface |
michelmoulin | 0:a1e10abfbd19 | 33 | { |
michelmoulin | 0:a1e10abfbd19 | 34 | public: |
michelmoulin | 0:a1e10abfbd19 | 35 | TPixyInterface() {} |
michelmoulin | 0:a1e10abfbd19 | 36 | virtual int8_t send(uint8_t *data, uint8_t len) = 0; |
michelmoulin | 0:a1e10abfbd19 | 37 | virtual void setArg(uint16_t arg) = 0; |
michelmoulin | 0:a1e10abfbd19 | 38 | virtual uint16_t getWord() = 0; |
michelmoulin | 0:a1e10abfbd19 | 39 | virtual uint8_t getByte() = 0; |
michelmoulin | 0:a1e10abfbd19 | 40 | }; |
michelmoulin | 0:a1e10abfbd19 | 41 | |
michelmoulin | 0:a1e10abfbd19 | 42 | |
michelmoulin | 0:a1e10abfbd19 | 43 | template <class BufType> class CircularQ |
michelmoulin | 0:a1e10abfbd19 | 44 | { |
michelmoulin | 0:a1e10abfbd19 | 45 | public: |
michelmoulin | 0:a1e10abfbd19 | 46 | BufType buf[PIXY_BUF_SIZE]; |
michelmoulin | 0:a1e10abfbd19 | 47 | uint8_t len; |
michelmoulin | 0:a1e10abfbd19 | 48 | uint8_t writeIndex; |
michelmoulin | 0:a1e10abfbd19 | 49 | uint8_t readIndex; |
michelmoulin | 0:a1e10abfbd19 | 50 | |
michelmoulin | 0:a1e10abfbd19 | 51 | CircularQ(); |
michelmoulin | 0:a1e10abfbd19 | 52 | bool read(BufType *c); |
michelmoulin | 0:a1e10abfbd19 | 53 | uint8_t freeLen(); |
michelmoulin | 0:a1e10abfbd19 | 54 | bool write(BufType c); |
michelmoulin | 0:a1e10abfbd19 | 55 | }; |
michelmoulin | 0:a1e10abfbd19 | 56 | |
michelmoulin | 0:a1e10abfbd19 | 57 | class PixyInterfaceSPI : TPixyInterface |
michelmoulin | 0:a1e10abfbd19 | 58 | { |
michelmoulin | 0:a1e10abfbd19 | 59 | public: |
michelmoulin | 0:a1e10abfbd19 | 60 | SPI* spi; |
michelmoulin | 0:a1e10abfbd19 | 61 | PixyInterfaceSPI(SPI* interface); |
michelmoulin | 0:a1e10abfbd19 | 62 | virtual uint16_t getWord(); |
michelmoulin | 0:a1e10abfbd19 | 63 | virtual uint8_t getByte(); |
michelmoulin | 0:a1e10abfbd19 | 64 | virtual int8_t send(uint8_t *data, uint8_t len); |
michelmoulin | 0:a1e10abfbd19 | 65 | virtual void setArg(uint16_t arg); |
michelmoulin | 0:a1e10abfbd19 | 66 | |
michelmoulin | 0:a1e10abfbd19 | 67 | private: |
michelmoulin | 0:a1e10abfbd19 | 68 | // we need a little circular queues for both directions |
michelmoulin | 0:a1e10abfbd19 | 69 | CircularQ<uint8_t> outQ; |
michelmoulin | 0:a1e10abfbd19 | 70 | CircularQ<uint16_t> inQ; |
michelmoulin | 0:a1e10abfbd19 | 71 | |
michelmoulin | 0:a1e10abfbd19 | 72 | uint16_t getWordHw(); |
michelmoulin | 0:a1e10abfbd19 | 73 | void flushSend(); |
michelmoulin | 0:a1e10abfbd19 | 74 | }; |
michelmoulin | 0:a1e10abfbd19 | 75 | |
michelmoulin | 0:a1e10abfbd19 | 76 | #endif |