@@ -193,27 +193,30 @@ void Encoders::encA_rising() {
193
193
return ;
194
194
}
195
195
196
- // For KH-270, if the carriage is already set, ignore the rest.
197
- if (Machine_t::Kh270 == m_machineType && Carriage_t::Knit == m_carriage) {
198
- return ;
199
- }
200
-
201
- // Only set the belt shift the first time a magnet passes the turn mark.
202
- // Headed to the right.
203
- if (!m_passedLeft && Direction_t::Right == m_direction) {
204
- // Belt shift signal only decided in front of hall sensor
205
- m_beltShift = digitalRead (ENC_PIN_C) != 0 ? BeltShift::Shifted : BeltShift::Regular;
206
- m_passedLeft = true ;
196
+ // The KH270 carriage also has two magnets, but:
197
+ // - the sensors and magnets are set up such that the carriage center
198
+ // is in front of the first/last needle when the carriage's outermost
199
+ // magnet is in front of the sensor;
200
+ // - we will always see the outermost magnet last and reset the position
201
+ // to a correct value, so it's not a problem if we detect the innermost
202
+ // first, even though that gives us a wrong position for a few needles
203
+ // (since we're not selecting anything at that point this has no impact)
204
+ // So there's no need to special-case position detection for the KH270 carriage.
205
+
206
+ // KH270 has no belt shift
207
+ if (m_machineType != Machine_t::Kh270) {
208
+ // Only set the belt shift the first time a magnet passes the turn mark.
209
+ // Headed to the right.
210
+ if (!m_passedLeft && Direction_t::Right == m_direction) {
211
+ // Belt shift signal only decided in front of hall sensor
212
+ m_beltShift = digitalRead (ENC_PIN_C) != 0 ? BeltShift::Shifted : BeltShift::Regular;
213
+ m_passedLeft = true ;
214
+ }
207
215
}
208
216
209
217
uint8_t start_position = END_LEFT_PLUS_OFFSET[static_cast <uint8_t >(m_machineType)];
210
218
211
- if (m_machineType == Machine_t::Kh270) {
212
- m_carriage = Carriage_t::Knit;
213
-
214
- // Assume the rightmost magnet was detected
215
- start_position = start_position + MAGNET_DISTANCE_270;
216
- } else if (m_carriage == Carriage_t::Lace &&
219
+ if (m_carriage == Carriage_t::Lace &&
217
220
detected_carriage == Carriage_t::Knit &&
218
221
m_position > start_position) {
219
222
m_carriage = Carriage_t::Garter;
@@ -281,29 +284,32 @@ void Encoders::encA_falling() {
281
284
return ;
282
285
}
283
286
284
- // For KH-270, if the carriage is already set, ignore the rest.
285
- if (Machine_t::Kh270 == m_machineType && Carriage_t::Knit == m_carriage) {
286
- return ;
287
- }
288
-
289
- // Only set the belt shift the first time a magnet passes the turn mark.
290
- // Headed to the left.
291
- if (!m_passedRight && Direction_t::Left == m_direction) {
292
- // Belt shift signal only decided in front of hall sensor
293
- m_beltShift = digitalRead (ENC_PIN_C) != 0 ? BeltShift::Regular : BeltShift::Shifted;
294
- m_passedRight = true ;
295
-
296
- // Shift doesn't need to be swapped for the g-carriage in this direction.
287
+ // The KH270 carriage also has two magnets, but:
288
+ // - the sensors and magnets are set up such that the carriage center
289
+ // is in front of the first/last needle when the carriage's outermost
290
+ // magnet is in front of the sensor;
291
+ // - we will always see the outermost magnet last and reset the position
292
+ // to a correct value, so it's not a problem if we detect the innermost
293
+ // first, even though that gives us a wrong position for a few needles
294
+ // (since we're not selecting anything at that point this has no impact)
295
+ // So there's no need to special-case position detection for the KH270 carriage.
296
+
297
+ // KH270 has no belt shift
298
+ if (m_machineType != Machine_t::Kh270) {
299
+ // Only set the belt shift the first time a magnet passes the turn mark.
300
+ // Headed to the left.
301
+ if (!m_passedRight && Direction_t::Left == m_direction) {
302
+ // Belt shift signal only decided in front of hall sensor
303
+ m_beltShift = digitalRead (ENC_PIN_C) != 0 ? BeltShift::Regular : BeltShift::Shifted;
304
+ m_passedRight = true ;
305
+
306
+ // Shift doesn't need to be swapped for the g-carriage in this direction.
307
+ }
297
308
}
298
309
299
310
uint8_t start_position = END_RIGHT_MINUS_OFFSET[static_cast <uint8_t >(m_machineType)];
300
311
301
- if (m_machineType == Machine_t::Kh270) {
302
- m_carriage = Carriage_t::Knit;
303
-
304
- // Assume the leftmost magnet was detected
305
- start_position = start_position; // FIXME
306
- } else if (m_carriage == Carriage_t::Lace &&
312
+ if (m_carriage == Carriage_t::Lace &&
307
313
detected_carriage == Carriage_t::Knit &&
308
314
m_position < start_position) {
309
315
m_carriage = Carriage_t::Garter;
0 commit comments