A simple WIP that logs data from a Grove sensor, and can send and receive information over USB and SMS.

Dependencies:   DHT DS_1337 SDFileSystem USBDevice mbed

Committer:
Joseph Radford
Date:
Sun Apr 10 15:47:33 2016 +1000
Revision:
0:2df78a4443cd
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Joseph Radford 0:2df78a4443cd 1 #ifndef __CIRC_BUFF_H__
Joseph Radford 0:2df78a4443cd 2 #define __CIRC_BUFF_H__
Joseph Radford 0:2df78a4443cd 3
Joseph Radford 0:2df78a4443cd 4 #include "mbed.h"
Joseph Radford 0:2df78a4443cd 5
Joseph Radford 0:2df78a4443cd 6 /*!
Joseph Radford 0:2df78a4443cd 7 * \brief The CircBuff class writes in and reads out byte arrays into a circular buffer
Joseph Radford 0:2df78a4443cd 8 */
Joseph Radford 0:2df78a4443cd 9 class CircBuff {
Joseph Radford 0:2df78a4443cd 10 public:
Joseph Radford 0:2df78a4443cd 11 CircBuff(uint16_t buffSize = 256);
Joseph Radford 0:2df78a4443cd 12 ~CircBuff();
Joseph Radford 0:2df78a4443cd 13
Joseph Radford 0:2df78a4443cd 14 /*!
Joseph Radford 0:2df78a4443cd 15 * \brief putc adds a single byte, \a c, into the array
Joseph Radford 0:2df78a4443cd 16 * \param c is the byte copied into the circular buffer.
Joseph Radford 0:2df78a4443cd 17 */
Joseph Radford 0:2df78a4443cd 18 void putc(unsigned char c);
Joseph Radford 0:2df78a4443cd 19
Joseph Radford 0:2df78a4443cd 20 /*!
Joseph Radford 0:2df78a4443cd 21 * \brief add adds \a s into the buffer, up until the NULL byte
Joseph Radford 0:2df78a4443cd 22 * \param s is the byte array copied into the buffer
Joseph Radford 0:2df78a4443cd 23 */
Joseph Radford 0:2df78a4443cd 24 void add(unsigned char *s);
Joseph Radford 0:2df78a4443cd 25
Joseph Radford 0:2df78a4443cd 26 /*!
Joseph Radford 0:2df78a4443cd 27 * \brief read puts the current data from the buffer into \a s
Joseph Radford 0:2df78a4443cd 28 * \param s is the reference buffer to copy current data into. Caller's responsibility to make it the correct size
Joseph Radford 0:2df78a4443cd 29 * \param len is the number of bytes to copy into \a s
Joseph Radford 0:2df78a4443cd 30 * \return the number of bytes copied into \a s. Will be less than \a len if there was less data in the buffer.
Joseph Radford 0:2df78a4443cd 31 */
Joseph Radford 0:2df78a4443cd 32 uint16_t read(unsigned char *s, uint16_t len);
Joseph Radford 0:2df78a4443cd 33 bool dataAvailable() { return (m_start != m_end); }
Joseph Radford 0:2df78a4443cd 34
Joseph Radford 0:2df78a4443cd 35
Joseph Radford 0:2df78a4443cd 36 private:
Joseph Radford 0:2df78a4443cd 37 uint16_t m_start; ///< The start index of the circular buffer, where the current data starts
Joseph Radford 0:2df78a4443cd 38 uint16_t m_end; ///< The end index, where the current data goes to
Joseph Radford 0:2df78a4443cd 39 unsigned char *m_buf; ///< the byte array
Joseph Radford 0:2df78a4443cd 40 uint16_t m_buffSize; ///< size of \a m_buf
Joseph Radford 0:2df78a4443cd 41
Joseph Radford 0:2df78a4443cd 42 // helper
Joseph Radford 0:2df78a4443cd 43 uint16_t remainingSize();
Joseph Radford 0:2df78a4443cd 44 };
Joseph Radford 0:2df78a4443cd 45
Joseph Radford 0:2df78a4443cd 46 #endif // __CIRC_BUFF_H__