File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66
77namespace Pinetime {
88 namespace Controllers {
9- // A simple circular buffer that can be used to average
10- // out the sensor values
9+ /* * A simple circular buffer that can be used to average
10+ out the sensor values. The total capacity of the CircBuffer
11+ is given as the template parameter N.
12+ */
1113 template <int N>
1214 class CircBuffer {
1315 public:
14- CircBuffer () : arr{}, sz{}, cap{N}, loc{} {}
16+ CircBuffer () : arr{}, sz{}, cap{N}, head{} {}
17+ /* *
18+ insert member function overwrites the next data to the current
19+ HEAD and moves the HEAD to the newly inserted value.
20+ */
1521 void insert (const int num) {
16- loc %= cap;
17- arr[loc ++] = num;
22+ head %= cap;
23+ arr[head ++] = num;
1824 if (sz != cap) {
1925 sz++;
2026 }
@@ -26,10 +32,10 @@ namespace Pinetime {
2632 }
2733
2834 private:
29- std::array<int , N> arr;
30- uint8_t sz;
31- uint8_t cap;
32- uint8_t loc;
35+ std::array<int , N> arr; /* *< internal array used to store the values */
36+ uint8_t sz; /* *< The current size of the array. */
37+ uint8_t cap; /* *< Total capacity of the CircBuffer. */
38+ uint8_t head; /* *< The current head of the CircBuffer */
3339 };
3440
3541 class Battery {
You can’t perform that action at this time.
0 commit comments