c85fd9f33c
Fixes #17. Stage 2 is fairly minimal, stage 3 builds/installs OpenCV and WPILib et al, and stage 4 builds/installs the FRCVision webdash and adds the vision examples. Other changes: - OpenCV compiled with ffmpeg, OpenBLAS, and libgtk (fixes #79, fixes #80) - OpenBLAS added to image (fixes #65) - C++ Makefile is more easily extensible (fixes #71) - Sources for everything are bundled into image into /usr/src - README updated (fixes #16) - pkg-config files for wpilibc et al are now installed and C++ Makefile uses them (if compiled local to Pi) - Both dynamic and static libs are included in image The only downside of all these changes (particularly the ffmpeg, OpenBLAS, and libgtk inclusion) is the image size is now over 3GB (800MB compressed). The previous image didn't quite fit on a 2GB card however.
57 lines
1.7 KiB
C++
57 lines
1.7 KiB
C++
/*----------------------------------------------------------------------------*/
|
|
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
/* the project. */
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
#ifndef RPICONFIGSERVER_DATAHISTORY_H_
|
|
#define RPICONFIGSERVER_DATAHISTORY_H_
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <algorithm>
|
|
#include <numeric>
|
|
|
|
template <typename T, size_t Size>
|
|
class DataHistory {
|
|
public:
|
|
void Add(T val) {
|
|
if (m_qty >= Size) {
|
|
std::copy(&m_data[1], &m_data[Size], &m_data[0]);
|
|
m_data[Size - 1] = val;
|
|
} else {
|
|
m_data[m_qty++] = val;
|
|
}
|
|
}
|
|
|
|
/* first is "least recent", last is "most recent" */
|
|
bool GetFirstLast(T* first, T* last, size_t* qty) const {
|
|
if (m_qty == 0) return false;
|
|
if (first) *first = m_data[0];
|
|
if (last) *last = m_data[m_qty - 1];
|
|
if (qty) *qty = m_qty;
|
|
return true;
|
|
}
|
|
|
|
/* only look at most recent "count" samples */
|
|
bool GetFirstLast(T* first, T* last, size_t* qty, size_t count) const {
|
|
if (count == 0 || m_qty < count) return false;
|
|
if (first) *first = m_data[m_qty - count];
|
|
if (last) *last = m_data[m_qty - 1];
|
|
if (qty) *qty = m_qty;
|
|
return true;
|
|
}
|
|
|
|
T GetTotal(size_t* qty = nullptr) const {
|
|
if (qty) *qty = m_qty;
|
|
return std::accumulate(&m_data[0], &m_data[m_qty], 0);
|
|
}
|
|
|
|
private:
|
|
T m_data[Size];
|
|
size_t m_qty = 0;
|
|
};
|
|
|
|
#endif // RPICONFIGSERVER_DATAHISTORY_H_
|