Speeduino
Loading...
Searching...
No Matches
table3d_axes.h
Go to the documentation of this file.
1
10#pragma once
11
12#include "table3d_typedefs.h"
13
17enum class AxisDomain : uint8_t {
19 Rpm,
21 Load,
22};
23
25{
26 return domain==AxisDomain::Rpm ? 100U : 2U;
27}
28
31{
32public:
33
36 : _stride(pEnd>pStart ? stride_inc : stride_dec)
37 , _pStart(pStart)
38 , _pEnd(pEnd + _stride)
39 {
40 }
41
46 {
47 _pStart = _pStart + ((int16_t)_stride * steps);
48 return *this;
49 }
50
53 {
54 return advance(1);
55 }
56
58 bool at_end(void) const
59 {
60 return _pStart == _pEnd;
61 }
62
63 // LCOV_EXCL_START
66 {
67 return *_pStart;
68 }
70 const table3d_axis_t& operator*(void) const
71 {
72 return *_pStart;
73 }
74 // LCOV_EXCL_STOP
75
76private:
77
78 static constexpr int8_t stride_inc = 1;
79 static constexpr int8_t stride_dec = -1;
80 int8_t _stride;
81 table3d_axis_t *_pStart;
82 const table3d_axis_t *_pEnd;
83};
84
85#define TABLE3D_TYPENAME_AXIS(size) table3d ## size ## _axis
86
87#define TABLE3D_GEN_AXIS(size) \
88 \
89 struct TABLE3D_TYPENAME_AXIS(size) { \
90 \
91 static constexpr table3d_dim_t length = (size); \
92 \
95 table3d_axis_t axis[(size)]; \
96 \
97 \
98 table_axis_iterator begin(void) \
99 { \
100 return table_axis_iterator(axis+(size)-1, axis); \
101 } \
102 \
103 table_axis_iterator rbegin(void) \
104 { \
105 return table_axis_iterator(axis, axis+(size)-1); \
106 } \
107 };
108
109// This generates the axis types for the following sizes & domains:
110// LCOV_EXCL_START
111TABLE3D_GEN_AXIS(4)
112TABLE3D_GEN_AXIS(6)
113TABLE3D_GEN_AXIS(8)
114TABLE3D_GEN_AXIS(16)
115// LCOV_EXCL_STOP
116
Iterate over table axis elements.
Definition table3d_axes.h:31
bool at_end(void) const
Test for end of iteration.
Definition table3d_axes.h:58
table3d_axis_t & operator*(void)
Dereference the iterator.
Definition table3d_axes.h:65
table_axis_iterator(table3d_axis_t *pStart, const table3d_axis_t *pEnd)
Construct.
Definition table3d_axes.h:35
table_axis_iterator & operator++(void)
Increment the iterator by one element.
Definition table3d_axes.h:52
table_axis_iterator & advance(int8_t steps)
Advance the iterator.
Definition table3d_axes.h:45
const table3d_axis_t & operator*(void) const
Dereference the iterator.
Definition table3d_axes.h:70
static TIntegral readSerialIntegralTimeout(void)
Reads an integral type, timing out if necessary.
Definition comms.cpp:175
AxisDomain
Encodes the real world measurement that a table axis captures.
Definition table3d_axes.h:17
uint8_t table3d_axis_t
The type of each axis value.
Definition table3d_typedefs.h:28
static constexpr uint16_t getConversionFactor(AxisDomain domain)
Definition table3d_axes.h:24
Typedefs for primitive 3D table elements.