Keisuke Sehara
/
STM32_Whisking
fast-feedback virtual target task code on STM Nucleo
Diff: core/arraylist.h
- Revision:
- 26:b4421d1ee57a
- Parent:
- 3:991c6d5ce19d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/arraylist.h Thu Jul 05 20:15:37 2018 +0000 @@ -0,0 +1,38 @@ +#ifndef ARRAYLIST_H_ +#define ARRAYLIST_H_ + +#include "mbed.h" +#include "IO.h" + +#define ARRAY_BUFFER_SIZE 256 + +template <typename T> +class ArrayList +{ +public: + ArrayList(): offset(0) { } + + void add(const T& item) { + array[offset++] = item; + if (offset == ARRAY_BUFFER_SIZE) { + offset = 0; + } + } + + void clear() { + offset = 0; + } + + void writeToSerial(const T& origin=0) { + IO::write('['); + for (int i=0; i<offset; i++) { + IO::write("%d,",array[i] - origin); + } + IO::write(']'); + } +private: + int offset; + T array[ARRAY_BUFFER_SIZE]; +}; + +#endif \ No newline at end of file