Speeduino
Loading...
Searching...
No Matches
pages.h
Go to the documentation of this file.
1#pragma once
2#include <Arduino.h>
3#include "table3d.h"
4#include "config_pages.h"
5
10
11// These are the page numbers that the Tuner Studio serial protocol uses to transverse the different map and config pages.
12constexpr uint8_t veSetPage = 1; //Note that this and the veMapPage were swapped in Feb 2019 as the 'algorithm' field must be declared in the ini before it's used in the fuel table
13constexpr uint8_t veMapPage = 2;
14constexpr uint8_t ignMapPage = 3;
15constexpr uint8_t ignSetPage = 4;
16constexpr uint8_t afrMapPage = 5;
17constexpr uint8_t afrSetPage = 6;
18constexpr uint8_t boostvvtPage = 7;
19constexpr uint8_t seqFuelPage = 8;
20constexpr uint8_t canbusPage = 9;
21constexpr uint8_t warmupPage = 10;
22constexpr uint8_t fuelMap2Page = 11;
23constexpr uint8_t wmiMapPage = 12;
24constexpr uint8_t progOutsPage = 13;
25constexpr uint8_t ignMap2Page = 14;
26constexpr uint8_t boostvvtPage2 = 15;
29
35
42
44
46void setTuneToEmpty(void);
47
48// ============================== Per-byte page access ==========================
49
53 );
54
62 byte value
63 );
64
65
66// ============================== Page Iteration ==========================
67
68// A logical TS page is actually multiple in memory entities. Allow iteration
69// over those entities.
70
71// Type of entity
72enum class EntityType : uint8_t {
73 Raw, // A block of memory
74 Table, // A 3D table
75 NoEntity, // No entity, but a valid offset
76 End // The offset was past any known entity for the page
77};
78
81 uint8_t page; // The index of the page the entity belongs to
82 uint8_t index; // The sub-index of the item within the page
83
84 constexpr entity_page_location_t(void)
85 : page(0U)
86 , index(0U)
87 {
88 }
94
95 constexpr entity_page_location_t next(void) const
96 {
98 }
99
101 {
102 return lhs.page==rhs.page
103 && lhs.index==rhs.index;
104 }
105
107 {
108 return !(lhs==rhs);
109 }
110};
111
113{
115 union
116 {
119 };
122
123 constexpr entity_t(void)
125 , pRaw(nullptr)
126 {
127 }
129 : type(theType)
130 , pRaw(nullptr)
131 , size(theSize)
132 {
133 }
136 , pTable(table)
137 , table_key(key)
138 , size(theSize)
139 {
140 }
141 explicit constexpr entity_t(config_page_t *entity, uint16_t theSize)
143 , pRaw(entity)
144 , size(theSize)
145 {
146 }
147
149 {
150 return entityAddress<size;
151 }
152};
153
154// An entity within a page - needs to include the entity start position
156{
157 uint16_t start; // The start position of the entity, in bytes, from the start of the page
158
159 constexpr page_entity_t(void)
160 : start(0U)
161 {
162 }
163 explicit constexpr page_entity_t(const entity_t &entity, uint16_t base)
164 : entity_t(entity)
165 , start(base)
166 {
167 }
168
176 {
177 return pageAddress >= start && pageAddress < start+size;
178 }
179};
180
181// A entity on a logical page.
193
194// ============================== Per-byte entity access ==========================
195
197byte getEntityValue(const entity_t &entity,
199 );
200
205bool setEntityValue(entity_t &entity,
207 byte value
208 );
209
215
220
225
230
235
Iterate over table axis elements.
Definition table3d_axes.h:31
Iterate through a tables values, row by row.
Definition table3d_values.h:87
The tune page structs and related defines.
TableType
Table type identifiers. Limited compile time RTTI.
Definition table3d.h:69
table_axis_iterator y_begin(const page_iterator_t &it)
Definition pages.cpp:561
constexpr uint8_t afrSetPage
Definition pages.h:17
bool setEntityValue(entity_t &entity, uint16_t offset, byte value)
Sets a single value from a page, with data aligned as per the ini file.
Definition pages.cpp:243
constexpr uint8_t PAGE_IDX_CALIBRATION_VALUES
Index of a calibration table values on a "page".
Definition pages.h:39
void setTuneToEmpty(void)
Fill the tune (config pages & tables) with zeroes.
Definition pages.cpp:478
constexpr uint8_t ignMap2Page
Definition pages.h:25
constexpr uint8_t PAGE_IDX_CALIBRATION_CRC
Index of a calibration table CRC on a "page".
Definition pages.h:38
constexpr uint8_t ignSetPage
Definition pages.h:15
constexpr uint8_t boostvvtPage
Definition pages.h:18
constexpr uint8_t veMapPage
Definition pages.h:13
constexpr uint8_t IAT_CALIBRATION_PAGE
IAT sensor calibration table page number.
Definition pages.h:33
constexpr uint8_t ignMapPage
Definition pages.h:14
constexpr uint8_t fuelMap2Page
Definition pages.h:22
page_iterator_t page_begin(uint8_t pageNum)
Definition pages.cpp:524
constexpr uint8_t seqFuelPage
Definition pages.h:19
constexpr uint8_t MIN_PAGE_NUM
Definition pages.h:27
table_value_iterator rows_begin(const page_iterator_t &it)
Definition pages.cpp:537
constexpr uint8_t veSetPage
Definition pages.h:12
constexpr uint8_t canbusPage
Definition pages.h:20
uint16_t getPageSize(uint8_t pageNum)
Definition pages.cpp:488
byte getPageValue(uint8_t pageNum, uint16_t pageOffset)
Gets a single value from a page, with data aligned as per the ini file.
Definition pages.cpp:513
page_iterator_t advance(const page_iterator_t &it)
Definition pages.cpp:529
constexpr uint8_t warmupPage
Definition pages.h:21
table_axis_iterator x_begin(const page_iterator_t &it)
Definition pages.cpp:545
constexpr uint8_t PAGE_IDX_CALIBRATION_BINS
Index of a calibration table bins on a "page".
Definition pages.h:40
constexpr uint8_t boostvvtPage2
Definition pages.h:26
constexpr uint8_t wmiMapPage
Definition pages.h:23
table_axis_iterator x_rbegin(const page_iterator_t &it)
Definition pages.cpp:553
bool setPageValue(uint8_t pageNum, uint16_t pageOffset, byte value)
Sets a single value from a page, with data aligned as per the ini file.
Definition pages.cpp:506
EntityType
Definition pages.h:72
constexpr uint8_t afrMapPage
Definition pages.h:16
byte getEntityValue(const entity_t &entity, uint16_t offset)
Gets a single value from an entity, with data aligned as per the ini file.
Definition pages.cpp:202
constexpr uint8_t CLT_CALIBRATION_PAGE
Coolant sensor calibration table page number.
Definition pages.h:34
constexpr uint8_t O2_CALIBRATION_PAGE
O2 sensor calibration table page number.
Definition pages.h:32
constexpr uint8_t MAX_PAGE_NUM
Definition pages.h:28
constexpr uint8_t progOutsPage
Definition pages.h:24
Definition array.h:14
Definition config_pages.h:165
The unique location of an entity within all pages.
Definition pages.h:80
uint8_t page
Definition pages.h:81
uint8_t index
Definition pages.h:82
friend bool operator!=(const entity_page_location_t &lhs, const entity_page_location_t &rhs)
Definition pages.h:106
friend bool operator==(const entity_page_location_t &lhs, const entity_page_location_t &rhs)
Definition pages.h:100
constexpr entity_page_location_t(void)
Definition pages.h:84
constexpr entity_page_location_t(uint8_t pageNum, uint8_t pageSubIndex)
Definition pages.h:89
constexpr entity_page_location_t next(void) const
Definition pages.h:95
Definition pages.h:113
table3d_t * pTable
If the entity is a table, this points to the table.
Definition pages.h:117
EntityType type
The entity type.
Definition pages.h:114
config_page_t * pRaw
If the entity is a raw block, this points to it.
Definition pages.h:118
bool isEntityAddressWithin(uint16_t entityAddress) const
Definition pages.h:148
uint16_t size
Size of the entity in bytes on the page
Definition pages.h:121
TableType table_key
If the entity is a table, this can be used to get the table type.
Definition pages.h:120
constexpr entity_t(void)
Definition pages.h:123
constexpr entity_t(table3d_t *table, TableType key, uint16_t theSize)
Definition pages.h:134
constexpr entity_t(config_page_t *entity, uint16_t theSize)
Definition pages.h:141
constexpr entity_t(EntityType theType, uint16_t theSize)
Definition pages.h:128
Definition pages.h:156
constexpr page_entity_t(void)
Definition pages.h:159
uint16_t start
Definition pages.h:157
bool isPageAddressWithin(uint16_t pageAddress) const
Check if the offset is within the entity address range.
Definition pages.h:175
constexpr page_entity_t(const entity_t &entity, uint16_t base)
Definition pages.h:163
Definition pages.h:182
entity_page_location_t location
Definition pages.h:184
constexpr page_iterator_t(void)=default
page_entity_t entity
Definition pages.h:183
constexpr page_iterator_t(const page_entity_t &theEntity, const entity_page_location_t &entityLocation)
Definition pages.h:187
Definition table3d.h:79
3D table data types and functions