-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTables.cpp
More file actions
280 lines (250 loc) · 14.5 KB
/
Tables.cpp
File metadata and controls
280 lines (250 loc) · 14.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
// Pico Electronic Leadscrew
// https://github.com/funkenjaeger/pico-els
//
// MIT License
//
// Copyright (c) 2025 Evan Dudzik
//
// This software is based on the Clough42 Electronic Leadscrew project under the MIT license
// https://github.com/clough42/electronic-leadscrew
// Leveraged portions of this software are Copyright (c) 2019 James Clough
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "Tables.h"
//
// INCH THREAD DEFINITIONS
//
// Each row in the table defines a standard imperial thread, with the display data,
// LED indicator states and gear ratio fraction to use.
//
#if defined(LEADSCREW_TPI)
#define TPI_NUMERATOR(tpi) (uint64_t(LEADSCREW_TPI*STEPPER_RESOLUTION*STEPPER_MICROSTEPS*10))
#define TPI_DENOMINATOR(tpi) (uint64_t(tpi*ENCODER_RESOLUTION))
#endif
#if defined(LEADSCREW_HMM)
#define TPI_NUMERATOR(tpi) (uint64_t(254*100*STEPPER_RESOLUTION*STEPPER_MICROSTEPS))
#define TPI_DENOMINATOR(tpi) (uint64_t(tpi*ENCODER_RESOLUTION*LEADSCREW_HMM))
#endif
#define TPI_FRACTION(tpi) .numerator = TPI_NUMERATOR(tpi), .denominator = TPI_DENOMINATOR(tpi)
const FEED_THREAD inch_thread_table[] =
{
{ .display = {BLANK, BLANK, BLANK, EIGHT}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(80) },
{ .display = {BLANK, BLANK, BLANK, NINE}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(90) },
{ .display = {BLANK, BLANK, ONE, ZERO}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(100) },
{ .display = {BLANK, BLANK, ONE, ONE}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(110) },
{ .display = {BLANK, ONE, ONE|POINT,FIVE}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(115) },
{ .display = {BLANK, BLANK, ONE, TWO}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(120) },
{ .display = {BLANK, BLANK, ONE, THREE}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(130) },
{ .display = {BLANK, BLANK, ONE, FOUR}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(140) },
{ .display = {BLANK, BLANK, ONE, SIX}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(160) },
{ .display = {BLANK, BLANK, ONE, EIGHT}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(180) },
{ .display = {BLANK, BLANK, ONE, NINE}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(190) },
{ .display = {BLANK, BLANK, TWO, ZERO}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(200) },
{ .display = {BLANK, BLANK, TWO, FOUR}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(240) },
{ .display = {BLANK, BLANK, TWO, SIX}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(260) },
{ .display = {BLANK, BLANK, TWO, SEVEN}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(270) },
{ .display = {BLANK, BLANK, TWO, EIGHT}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(280) },
{ .display = {BLANK, BLANK, THREE, TWO}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(320) },
{ .display = {BLANK, BLANK, THREE, SIX}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(360) },
{ .display = {BLANK, BLANK, FOUR, ZERO}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(400) },
{ .display = {BLANK, BLANK, FOUR, FOUR}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(440) },
{ .display = {BLANK, BLANK, FOUR, EIGHT}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(480) },
{ .display = {BLANK, BLANK, FIVE, SIX}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(560) },
{ .display = {BLANK, BLANK, SIX, FOUR}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(640) },
{ .display = {BLANK, BLANK, SEVEN, TWO}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(720) },
{ .display = {BLANK, BLANK, EIGHT, ZERO}, .leds = LED_THREAD | LED_TPI, TPI_FRACTION(800) },
};
//
// INCH FEED DEFINITIONS
//
// Each row in the table defines a standard imperial feed rate, with the display data,
// LED indicator states and gear ratio fraction to use.
//
#if defined(LEADSCREW_TPI)
#define THOU_IN_NUMERATOR(thou) ((uint64_t)thou*LEADSCREW_TPI*STEPPER_RESOLUTION_FEED*STEPPER_MICROSTEPS_FEED)
#define THOU_IN_DENOMINATOR(thou) ((uint64_t)ENCODER_RESOLUTION*1000)
#endif
#if defined(LEADSCREW_HMM)
#define THOU_IN_NUMERATOR(thou) ((uint64_t)thou*254*STEPPER_RESOLUTION_FEED*STEPPER_MICROSTEPS_FEED)
#define THOU_IN_DENOMINATOR(thou) ((uint64_t)ENCODER_RESOLUTION*100*LEADSCREW_HMM)
#endif
#define THOU_IN_FRACTION(thou) .numerator = THOU_IN_NUMERATOR(thou), .denominator = THOU_IN_DENOMINATOR(thou)
const FEED_THREAD inch_feed_table[] =
{
{ .display = {POINT, ZERO, ZERO, ONE}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(1) },
{ .display = {POINT, ZERO, ZERO, TWO}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(2) },
{ .display = {POINT, ZERO, ZERO, THREE}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(3) },
{ .display = {POINT, ZERO, ZERO, FOUR}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(4) },
{ .display = {POINT, ZERO, ZERO, FIVE}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(5) },
{ .display = {POINT, ZERO, ZERO, SIX}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(6) },
{ .display = {POINT, ZERO, ZERO, SEVEN}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(7) },
{ .display = {POINT, ZERO, ZERO, EIGHT}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(8) },
{ .display = {POINT, ZERO, ZERO, NINE}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(9) },
{ .display = {POINT, ZERO, ONE, ZERO}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(10) },
{ .display = {POINT, ZERO, ONE, ONE}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(11) },
{ .display = {POINT, ZERO, ONE, TWO}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(12) },
{ .display = {POINT, ZERO, ONE, THREE}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(13) },
{ .display = {POINT, ZERO, ONE, FIVE}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(15) },
{ .display = {POINT, ZERO, ONE, SEVEN}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(17) },
{ .display = {POINT, ZERO, TWO, ZERO}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(20) },
{ .display = {POINT, ZERO, TWO, THREE}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(23) },
{ .display = {POINT, ZERO, TWO, SIX}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(26) },
{ .display = {POINT, ZERO, THREE, ZERO}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(30) },
{ .display = {POINT, ZERO, THREE, FIVE}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(35) },
{ .display = {POINT, ZERO, FOUR, ZERO}, .leds = LED_FEED | LED_INCH, THOU_IN_FRACTION(40) },
};
//
// METRIC THREAD DEFINITIONS
//
// Each row in the table defines a standard metric thread, with the display data,
// LED indicator states and gear ratio fraction to use.
//
#if defined(LEADSCREW_TPI)
#define HMM_NUMERATOR(hmm) ((uint64_t)hmm*10*LEADSCREW_TPI*STEPPER_RESOLUTION*STEPPER_MICROSTEPS)
#define HMM_DENOMINATOR(hmm) ((uint64_t)ENCODER_RESOLUTION*254*100)
#endif
#if defined(LEADSCREW_HMM)
#define HMM_NUMERATOR(hmm) ((uint64_t)hmm*STEPPER_RESOLUTION*STEPPER_MICROSTEPS)
#define HMM_DENOMINATOR(hmm) ((uint64_t)ENCODER_RESOLUTION*LEADSCREW_HMM)
#endif
#define HMM_FRACTION(hmm) .numerator = HMM_NUMERATOR(hmm), .denominator = HMM_DENOMINATOR(hmm)
const FEED_THREAD metric_thread_table[] =
{
{ .display = {BLANK, POINT, TWO, BLANK}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(20) },
{ .display = {BLANK, POINT, TWO, FIVE}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(25) },
{ .display = {BLANK, POINT, THREE, BLANK}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(30) },
{ .display = {BLANK, POINT, THREE, FIVE}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(35) },
{ .display = {BLANK, POINT, FOUR, BLANK}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(40) },
{ .display = {BLANK, POINT, FOUR, FIVE}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(45) },
{ .display = {BLANK, POINT, FIVE, BLANK}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(50) },
{ .display = {BLANK, POINT, SIX, BLANK}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(60) },
{ .display = {BLANK, POINT, SEVEN, BLANK}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(70) },
{ .display = {BLANK, POINT, SEVEN, FIVE}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(75) },
{ .display = {BLANK, POINT, EIGHT, BLANK}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(80) },
{ .display = {BLANK, ONE, BLANK, BLANK}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(100) },
{ .display = {BLANK, ONE | POINT, TWO, FIVE}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(125) },
{ .display = {BLANK, ONE | POINT, FIVE, BLANK}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(150) },
{ .display = {BLANK, ONE | POINT, SEVEN, FIVE}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(175) },
{ .display = {BLANK, TWO, BLANK, BLANK}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(200) },
{ .display = {BLANK, TWO | POINT, FIVE, BLANK}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(250) },
{ .display = {BLANK, THREE, BLANK, BLANK}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(300) },
{ .display = {BLANK, THREE | POINT, FIVE, BLANK}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(350) },
{ .display = {BLANK, FOUR, BLANK, BLANK}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(400) },
{ .display = {BLANK, FOUR | POINT, FIVE, BLANK}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(450) },
{ .display = {BLANK, FIVE, BLANK, BLANK}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(500) },
{ .display = {BLANK, FIVE | POINT, FIVE, BLANK}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(550) },
{ .display = {BLANK, SIX, BLANK, BLANK}, .leds = LED_THREAD | LED_MM, HMM_FRACTION(600) },
};
//
// METRIC FEED DEFINITIONS
//
// Each row in the table defines a standard metric feed, with the display data,
// LED indicator states and gear ratio fraction to use.
//
#if defined(LEADSCREW_TPI)
#define HMM_NUMERATOR_FEED(hmm) ((uint64_t)hmm*10*LEADSCREW_TPI*STEPPER_RESOLUTION_FEED*STEPPER_MICROSTEPS_FEED)
#define HMM_DENOMINATOR_FEED(hmm) ((uint64_t)ENCODER_RESOLUTION*254*100)
#endif
#if defined(LEADSCREW_HMM)
#define HMM_NUMERATOR_FEED(hmm) ((uint64_t)hmm*STEPPER_RESOLUTION_FEED*STEPPER_MICROSTEPS_FEED)
#define HMM_DENOMINATOR_FEED(hmm) ((uint64_t)ENCODER_RESOLUTION*LEADSCREW_HMM)
#endif
#define HMM_FRACTION_FEED(hmm) .numerator = HMM_NUMERATOR_FEED(hmm), .denominator = HMM_DENOMINATOR_FEED(hmm)
const FEED_THREAD metric_feed_table[] =
{
{ .display = {BLANK, POINT, ZERO, TWO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(2) },
{ .display = {BLANK, POINT, ZERO, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(5) },
{ .display = {BLANK, POINT, ZERO, SEVEN}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(7) },
{ .display = {BLANK, POINT, ONE, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(10) },
{ .display = {BLANK, POINT, ONE, TWO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(12) },
{ .display = {BLANK, POINT, ONE, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(15) },
{ .display = {BLANK, POINT, ONE, SEVEN}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(17) },
{ .display = {BLANK, POINT, TWO, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(20) },
{ .display = {BLANK, POINT, TWO, TWO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(22) },
{ .display = {BLANK, POINT, TWO, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(25) },
{ .display = {BLANK, POINT, TWO, SEVEN}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(27) },
{ .display = {BLANK, POINT, THREE, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(30) },
{ .display = {BLANK, POINT, THREE, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(35) },
{ .display = {BLANK, POINT, FOUR, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(40) },
{ .display = {BLANK, POINT, FOUR, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(45) },
{ .display = {BLANK, POINT, FIVE, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(50) },
{ .display = {BLANK, POINT, FIVE, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(55) },
{ .display = {BLANK, POINT, SIX, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(60) },
{ .display = {BLANK, POINT, SEVEN, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(70) },
{ .display = {BLANK, POINT, EIGHT, FIVE}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(85) },
{ .display = {BLANK, ONE | POINT, ZERO, ZERO}, .leds = LED_FEED | LED_MM, HMM_FRACTION_FEED(100) },
};
FeedTable::FeedTable(const FEED_THREAD *table, uint16_t numRows, uint16_t defaultSelection)
{
this->table = table;
this->numRows = numRows;
this->selectedRow = defaultSelection;
}
const FEED_THREAD *FeedTable :: current(void)
{
return &table[selectedRow];
}
const FEED_THREAD *FeedTable :: next(void)
{
if( this->selectedRow < this->numRows - 1 )
{
this->selectedRow++;
}
return this->current();
}
const FEED_THREAD *FeedTable :: previous(void)
{
if( this->selectedRow > 0 )
{
this->selectedRow--;
}
return this->current();
}
FeedTableFactory::FeedTableFactory(void):
inchThreads(inch_thread_table, sizeof(inch_thread_table)/sizeof(inch_thread_table[0]), 12),
inchFeeds(inch_feed_table, sizeof(inch_feed_table)/sizeof(inch_feed_table[0]), 4),
metricThreads(metric_thread_table, sizeof(metric_thread_table)/sizeof(metric_thread_table[0]), 6),
metricFeeds(metric_feed_table, sizeof(metric_feed_table)/sizeof(metric_feed_table[0]), 4)
{
}
FeedTable *FeedTableFactory::getFeedTable(bool metric, bool thread)
{
if( metric )
{
if( thread )
{
return &this->metricThreads;
}
else
{
return &this->metricFeeds;
}
}
else
{
if( thread )
{
return &this->inchThreads;
}
else
{
return &this->inchFeeds;
}
}
}