pwm period is now 200us instead of the default 20ms veml6040 config is now AF_BIT | TRIG_BIT
Dependencies: mbed MMA8451Q USBDevice WakeUp vt100
Fork of afero_node_suntory_2017_06_15 by
util/USQueue.hpp@14:b205267fa5f6, 2017-05-16 (annotated)
- Committer:
- wataloh
- Date:
- Tue May 16 08:58:26 2017 +0000
- Revision:
- 14:b205267fa5f6
+ flow control; + 1 second interval between each transaction
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wataloh | 14:b205267fa5f6 | 1 | #ifndef _ULTRA_SIMPLE_QUEUE_ |
wataloh | 14:b205267fa5f6 | 2 | #define _ULTRA_SIMPLE_QUEUE_ |
wataloh | 14:b205267fa5f6 | 3 | |
wataloh | 14:b205267fa5f6 | 4 | //#include <string.h> |
wataloh | 14:b205267fa5f6 | 5 | |
wataloh | 14:b205267fa5f6 | 6 | template<typename T> class USQueue |
wataloh | 14:b205267fa5f6 | 7 | { |
wataloh | 14:b205267fa5f6 | 8 | public: enum QSIZE |
wataloh | 14:b205267fa5f6 | 9 | { |
wataloh | 14:b205267fa5f6 | 10 | QSIZE_8 = 8, |
wataloh | 14:b205267fa5f6 | 11 | QSIZE_16 = 16, |
wataloh | 14:b205267fa5f6 | 12 | QSIZE_32 = 32, |
wataloh | 14:b205267fa5f6 | 13 | QSIZE_64 = 64 |
wataloh | 14:b205267fa5f6 | 14 | }; |
wataloh | 14:b205267fa5f6 | 15 | private: T *q; |
wataloh | 14:b205267fa5f6 | 16 | private: unsigned char eqi; |
wataloh | 14:b205267fa5f6 | 17 | private: unsigned char dqi; |
wataloh | 14:b205267fa5f6 | 18 | private: T init_val; |
wataloh | 14:b205267fa5f6 | 19 | private: QSIZE _size; |
wataloh | 14:b205267fa5f6 | 20 | public: USQueue(T init_val, QSIZE _size = QSIZE_64) : eqi(0), dqi(0) |
wataloh | 14:b205267fa5f6 | 21 | { |
wataloh | 14:b205267fa5f6 | 22 | q = new T[_size]; |
wataloh | 14:b205267fa5f6 | 23 | for(unsigned int i=0; i<_size; ++i) |
wataloh | 14:b205267fa5f6 | 24 | { |
wataloh | 14:b205267fa5f6 | 25 | q[i] = init_val; |
wataloh | 14:b205267fa5f6 | 26 | }; |
wataloh | 14:b205267fa5f6 | 27 | this->init_val = init_val; |
wataloh | 14:b205267fa5f6 | 28 | this->_size = _size; |
wataloh | 14:b205267fa5f6 | 29 | } |
wataloh | 14:b205267fa5f6 | 30 | public: ~USQueue() |
wataloh | 14:b205267fa5f6 | 31 | { |
wataloh | 14:b205267fa5f6 | 32 | delete[] q; |
wataloh | 14:b205267fa5f6 | 33 | q = NULL; |
wataloh | 14:b205267fa5f6 | 34 | } |
wataloh | 14:b205267fa5f6 | 35 | public: inline void enq(T t) |
wataloh | 14:b205267fa5f6 | 36 | { |
wataloh | 14:b205267fa5f6 | 37 | q[eqi] = t; |
wataloh | 14:b205267fa5f6 | 38 | ++eqi; |
wataloh | 14:b205267fa5f6 | 39 | eqi = eqi&(_size-1); |
wataloh | 14:b205267fa5f6 | 40 | } |
wataloh | 14:b205267fa5f6 | 41 | private: inline T _deq() |
wataloh | 14:b205267fa5f6 | 42 | { |
wataloh | 14:b205267fa5f6 | 43 | T r = q[dqi]; |
wataloh | 14:b205267fa5f6 | 44 | q[dqi] = init_val; |
wataloh | 14:b205267fa5f6 | 45 | ++dqi; |
wataloh | 14:b205267fa5f6 | 46 | dqi = dqi&(_size-1); |
wataloh | 14:b205267fa5f6 | 47 | return r; |
wataloh | 14:b205267fa5f6 | 48 | } |
wataloh | 14:b205267fa5f6 | 49 | public: inline T deq() |
wataloh | 14:b205267fa5f6 | 50 | { |
wataloh | 14:b205267fa5f6 | 51 | T ret = init_val; |
wataloh | 14:b205267fa5f6 | 52 | for(unsigned int i=0; i<_size; ++i) |
wataloh | 14:b205267fa5f6 | 53 | { |
wataloh | 14:b205267fa5f6 | 54 | if( (ret = _deq()) != init_val ) |
wataloh | 14:b205267fa5f6 | 55 | { |
wataloh | 14:b205267fa5f6 | 56 | break; |
wataloh | 14:b205267fa5f6 | 57 | } |
wataloh | 14:b205267fa5f6 | 58 | } |
wataloh | 14:b205267fa5f6 | 59 | return ret; |
wataloh | 14:b205267fa5f6 | 60 | } |
wataloh | 14:b205267fa5f6 | 61 | public: inline T pkq(T unavailable) |
wataloh | 14:b205267fa5f6 | 62 | { |
wataloh | 14:b205267fa5f6 | 63 | T ret = unavailable; |
wataloh | 14:b205267fa5f6 | 64 | unsigned char _dqi = dqi; |
wataloh | 14:b205267fa5f6 | 65 | for(unsigned int i=0; i<_size; ++i) |
wataloh | 14:b205267fa5f6 | 66 | { |
wataloh | 14:b205267fa5f6 | 67 | T tmp = q[_dqi]; |
wataloh | 14:b205267fa5f6 | 68 | if( tmp != init_val ) |
wataloh | 14:b205267fa5f6 | 69 | { |
wataloh | 14:b205267fa5f6 | 70 | ret = tmp; |
wataloh | 14:b205267fa5f6 | 71 | break; |
wataloh | 14:b205267fa5f6 | 72 | } |
wataloh | 14:b205267fa5f6 | 73 | ++_dqi; |
wataloh | 14:b205267fa5f6 | 74 | _dqi = _dqi&(_size-1); |
wataloh | 14:b205267fa5f6 | 75 | } |
wataloh | 14:b205267fa5f6 | 76 | return ret; |
wataloh | 14:b205267fa5f6 | 77 | } |
wataloh | 14:b205267fa5f6 | 78 | public: size_t size() |
wataloh | 14:b205267fa5f6 | 79 | { |
wataloh | 14:b205267fa5f6 | 80 | return _size; |
wataloh | 14:b205267fa5f6 | 81 | } |
wataloh | 14:b205267fa5f6 | 82 | }; |
wataloh | 14:b205267fa5f6 | 83 | |
wataloh | 14:b205267fa5f6 | 84 | #endif //_ULTRA_SIMPLE_QUEUE_ |