The MGC3130 is the world’s first electrical-field (E-field) based three-dimensional (3D) tracking and gesture controller
Dependents: NucleoMGC3130 i2c_master
GestILibrarMessage/BufferedArray.h@7:eacd776fce29, 2015-10-15 (annotated)
- Committer:
- yangcq88517
- Date:
- Thu Oct 15 16:10:55 2015 +0000
- Revision:
- 7:eacd776fce29
- Parent:
- 6:b511421e7dc8
add sample code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yangcq88517 | 6:b511421e7dc8 | 1 | #ifndef UK_AC_HERTS_SMARTLAB_BufferedArray |
yangcq88517 | 6:b511421e7dc8 | 2 | #define UK_AC_HERTS_SMARTLAB_BufferedArray |
yangcq88517 | 6:b511421e7dc8 | 3 | |
yangcq88517 | 6:b511421e7dc8 | 4 | #include "mbed.h" |
yangcq88517 | 6:b511421e7dc8 | 5 | |
yangcq88517 | 7:eacd776fce29 | 6 | /** |
yangcq88517 | 7:eacd776fce29 | 7 | * Represent a generic, dynamic-length raw binary data buffer. |
yangcq88517 | 7:eacd776fce29 | 8 | */ |
yangcq88517 | 6:b511421e7dc8 | 9 | class BufferedArray |
yangcq88517 | 6:b511421e7dc8 | 10 | { |
yangcq88517 | 6:b511421e7dc8 | 11 | protected : |
yangcq88517 | 6:b511421e7dc8 | 12 | /// initial size and automatically increase length. |
yangcq88517 | 6:b511421e7dc8 | 13 | static const int EXPANDSIZE = 20; |
yangcq88517 | 6:b511421e7dc8 | 14 | |
yangcq88517 | 6:b511421e7dc8 | 15 | /// Raw data |
yangcq88517 | 6:b511421e7dc8 | 16 | char * data; |
yangcq88517 | 6:b511421e7dc8 | 17 | |
yangcq88517 | 6:b511421e7dc8 | 18 | /// Current index of the data, could also used as data lendth. |
yangcq88517 | 6:b511421e7dc8 | 19 | int index; |
yangcq88517 | 6:b511421e7dc8 | 20 | |
yangcq88517 | 6:b511421e7dc8 | 21 | /// Max data size that the raw data can hold. |
yangcq88517 | 6:b511421e7dc8 | 22 | int max; |
yangcq88517 | 6:b511421e7dc8 | 23 | |
yangcq88517 | 6:b511421e7dc8 | 24 | void expandSpace(int length); |
yangcq88517 | 6:b511421e7dc8 | 25 | |
yangcq88517 | 6:b511421e7dc8 | 26 | public: |
yangcq88517 | 6:b511421e7dc8 | 27 | BufferedArray(); |
yangcq88517 | 7:eacd776fce29 | 28 | |
yangcq88517 | 7:eacd776fce29 | 29 | BufferedArray(int size); |
yangcq88517 | 6:b511421e7dc8 | 30 | |
yangcq88517 | 6:b511421e7dc8 | 31 | BufferedArray(BufferedArray * bufferedArray); |
yangcq88517 | 6:b511421e7dc8 | 32 | |
yangcq88517 | 6:b511421e7dc8 | 33 | ~BufferedArray(); |
yangcq88517 | 6:b511421e7dc8 | 34 | |
yangcq88517 | 6:b511421e7dc8 | 35 | /** Get the raw data. |
yangcq88517 | 6:b511421e7dc8 | 36 | * @returns char array. |
yangcq88517 | 6:b511421e7dc8 | 37 | */ |
yangcq88517 | 6:b511421e7dc8 | 38 | char * gets(); |
yangcq88517 | 6:b511421e7dc8 | 39 | |
yangcq88517 | 6:b511421e7dc8 | 40 | /** Get the raw data from a specific location. |
yangcq88517 | 6:b511421e7dc8 | 41 | * |
yangcq88517 | 6:b511421e7dc8 | 42 | * @param position where to retrieve |
yangcq88517 | 6:b511421e7dc8 | 43 | * |
yangcq88517 | 6:b511421e7dc8 | 44 | * @returns char array. |
yangcq88517 | 6:b511421e7dc8 | 45 | */ |
yangcq88517 | 6:b511421e7dc8 | 46 | char * gets(int position); |
yangcq88517 | 6:b511421e7dc8 | 47 | |
yangcq88517 | 6:b511421e7dc8 | 48 | /** Get 1 byte data from a specific location. |
yangcq88517 | 6:b511421e7dc8 | 49 | * |
yangcq88517 | 6:b511421e7dc8 | 50 | * @param position where to retrieve |
yangcq88517 | 6:b511421e7dc8 | 51 | * |
yangcq88517 | 6:b511421e7dc8 | 52 | * @returns char. |
yangcq88517 | 6:b511421e7dc8 | 53 | */ |
yangcq88517 | 6:b511421e7dc8 | 54 | char get(int position); |
yangcq88517 | 6:b511421e7dc8 | 55 | |
yangcq88517 | 6:b511421e7dc8 | 56 | /** Get the current index. |
yangcq88517 | 6:b511421e7dc8 | 57 | * @returns char array. |
yangcq88517 | 6:b511421e7dc8 | 58 | */ |
yangcq88517 | 6:b511421e7dc8 | 59 | int getPosition(); |
yangcq88517 | 6:b511421e7dc8 | 60 | |
yangcq88517 | 6:b511421e7dc8 | 61 | /** Set the index within the max length of raw data. |
yangcq88517 | 6:b511421e7dc8 | 62 | * @param position where to begin read and write |
yangcq88517 | 6:b511421e7dc8 | 63 | */ |
yangcq88517 | 6:b511421e7dc8 | 64 | void setPosition(int position); |
yangcq88517 | 6:b511421e7dc8 | 65 | |
yangcq88517 | 6:b511421e7dc8 | 66 | /** Reset the raw data. |
yangcq88517 | 6:b511421e7dc8 | 67 | * @param length current max size for the raw data |
yangcq88517 | 6:b511421e7dc8 | 68 | */ |
yangcq88517 | 6:b511421e7dc8 | 69 | void allocate(int length); |
yangcq88517 | 6:b511421e7dc8 | 70 | |
yangcq88517 | 6:b511421e7dc8 | 71 | /** Reset the position and does not affect the content of the data. |
yangcq88517 | 6:b511421e7dc8 | 72 | * @param length current max size for the raw data |
yangcq88517 | 6:b511421e7dc8 | 73 | */ |
yangcq88517 | 6:b511421e7dc8 | 74 | void rewind(); |
yangcq88517 | 6:b511421e7dc8 | 75 | |
yangcq88517 | 6:b511421e7dc8 | 76 | /** Write 8-bit data into current posiston and increase by 1. |
yangcq88517 | 6:b511421e7dc8 | 77 | * @param value sigle byte |
yangcq88517 | 6:b511421e7dc8 | 78 | */ |
yangcq88517 | 6:b511421e7dc8 | 79 | void set(char value); |
yangcq88517 | 6:b511421e7dc8 | 80 | |
yangcq88517 | 6:b511421e7dc8 | 81 | /** Write array of data into current posiston, and increase by the lenght. |
yangcq88517 | 6:b511421e7dc8 | 82 | * @param value array of byte |
yangcq88517 | 6:b511421e7dc8 | 83 | * @param offset start point of the data |
yangcq88517 | 6:b511421e7dc8 | 84 | * @param length length to write |
yangcq88517 | 6:b511421e7dc8 | 85 | */ |
yangcq88517 | 7:eacd776fce29 | 86 | void sets(const char * value, int offset, int length); |
yangcq88517 | 6:b511421e7dc8 | 87 | |
yangcq88517 | 6:b511421e7dc8 | 88 | /** Write 8-bit data into specific posiston and deos not affect the current position. |
yangcq88517 | 6:b511421e7dc8 | 89 | * @param position where to write |
yangcq88517 | 6:b511421e7dc8 | 90 | * @param value sigle byte |
yangcq88517 | 6:b511421e7dc8 | 91 | */ |
yangcq88517 | 6:b511421e7dc8 | 92 | void set(int position, char value); |
yangcq88517 | 6:b511421e7dc8 | 93 | |
yangcq88517 | 6:b511421e7dc8 | 94 | /** Write array of data into specific posiston and deos not affect the current position. |
yangcq88517 | 6:b511421e7dc8 | 95 | * @param position where to write |
yangcq88517 | 6:b511421e7dc8 | 96 | * @param value array of byte |
yangcq88517 | 6:b511421e7dc8 | 97 | * @param offset start point of the data |
yangcq88517 | 6:b511421e7dc8 | 98 | * @param length length to write |
yangcq88517 | 6:b511421e7dc8 | 99 | */ |
yangcq88517 | 7:eacd776fce29 | 100 | void sets(int position, const char * value, int offset, int length); |
yangcq88517 | 6:b511421e7dc8 | 101 | }; |
yangcq88517 | 6:b511421e7dc8 | 102 | |
yangcq88517 | 6:b511421e7dc8 | 103 | #endif |