ValueHistory.h 999 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef VALUEHISTORY_H
  2. #define VALUEHISTORY_H
  3. class ValueHistory
  4. {
  5. static const int MAX_HISTORY = 256;
  6. float m_samples[MAX_HISTORY];
  7. int m_hsamples;
  8. public:
  9. ValueHistory();
  10. inline void addSample(const float val)
  11. {
  12. m_hsamples = (m_hsamples+MAX_HISTORY-1) % MAX_HISTORY;
  13. m_samples[m_hsamples] = val;
  14. }
  15. inline int getSampleCount() const
  16. {
  17. return MAX_HISTORY;
  18. }
  19. inline float getSample(const int i) const
  20. {
  21. return m_samples[(m_hsamples+i) % MAX_HISTORY];
  22. }
  23. float getSampleMin() const;
  24. float getSampleMax() const;
  25. float getAverage() const;
  26. };
  27. struct GraphParams
  28. {
  29. void setRect(int ix, int iy, int iw, int ih, int ipad);
  30. void setValueRange(float ivmin, float ivmax, int indiv, const char* iunits);
  31. int x, y, w, h, pad;
  32. float vmin, vmax;
  33. int ndiv;
  34. char units[16];
  35. };
  36. void drawGraphBackground(const GraphParams* p);
  37. void drawGraph(const GraphParams* p, const ValueHistory* graph,
  38. int idx, const char* label, const unsigned int col);
  39. #endif // VALUEHISTORY_H