Welcome to mirror list, hosted at ThFree Co, Russian Federation.

GCodeBuffer.cpp « GCodeBuffer « GCodes « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 17ece53e84eec9fc060228cf33aa25850c0fa8ae (plain)
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
/*
 * GCodeBuffer.cpp
 *
 *  Created on: 6 Feb 2015
 *      Author: David
 */

//*************************************************************************************

#include "GCodeBuffer.h"
#if HAS_MASS_STORAGE || HAS_EMBEDDED_FILES
# include <GCodes/GCodeInput.h>
#endif
#if HAS_SBC_INTERFACE
# include <SBC/SbcInterface.h>
#endif
#include "BinaryParser.h"
#include "StringParser.h"
#include <GCodes/GCodeException.h>
#include <Platform/RepRap.h>
#include <Platform/Platform.h>
#include <Movement/StepTimer.h>

// Macros to reduce the amount of explicit conditional compilation in this file
#if HAS_SBC_INTERFACE

# define PARSER_OPERATION(_x)	((isBinaryBuffer) ? (binaryParser._x) : (stringParser._x))
# define IS_BINARY_OR(_x)		((isBinaryBuffer) || (_x))
# define NOT_BINARY_AND(_x)		((!isBinaryBuffer) && (_x))
# define IF_NOT_BINARY(_x)		{ if (!isBinaryBuffer) { _x; } }

#else

# define PARSER_OPERATION(_x)	(stringParser._x)
# define IS_BINARY_OR(_x)		(_x)
# define NOT_BINARY_AND(_x)		(_x)
# define IF_NOT_BINARY(_x)		{ _x; }

#endif

#if SUPPORT_OBJECT_MODEL
// Object model table and functions
// Note: if using GCC version 7.3.1 20180622 and lambda functions are used in this table, you must compile this file with option -std=gnu++17.
// Otherwise the table will be allocate in RAM instead of flash, which wastes too much RAM.

// Macro to build a standard lambda function that includes the necessary type conversions
#define OBJECT_MODEL_FUNC(...) OBJECT_MODEL_FUNC_BODY(GCodeBuffer, __VA_ARGS__)

constexpr ObjectModelTableEntry GCodeBuffer::objectModelTable[] =
{
	// Within each group, these entries must be in alphabetical order
	// 0. inputs[] root
	{ "axesRelative",		OBJECT_MODEL_FUNC((bool)self->machineState->axesRelative),							ObjectModelEntryFlags::none },
	{ "compatibility",		OBJECT_MODEL_FUNC(self->machineState->compatibility.ToString()),					ObjectModelEntryFlags::none },
	{ "distanceUnit",		OBJECT_MODEL_FUNC(self->GetDistanceUnits()),										ObjectModelEntryFlags::none },
	{ "drivesRelative",		OBJECT_MODEL_FUNC((bool)self->machineState->drivesRelative),						ObjectModelEntryFlags::none },
	{ "feedRate",			OBJECT_MODEL_FUNC(InverseConvertSpeedToMmPerSec(self->machineState->feedRate), 1),	ObjectModelEntryFlags::live },
	{ "inMacro",			OBJECT_MODEL_FUNC((bool)self->machineState->doingFileMacro),						ObjectModelEntryFlags::live },
	{ "inverseTimeMode",	OBJECT_MODEL_FUNC((bool)self->machineState->inverseTimeMode),						ObjectModelEntryFlags::none },
	{ "lineNumber",			OBJECT_MODEL_FUNC((int32_t)self->GetLineNumber()),									ObjectModelEntryFlags::live },
	{ "macroRestartable",	OBJECT_MODEL_FUNC((bool)self->machineState->macroRestartable),						ObjectModelEntryFlags::none },
#if SUPPORT_ASYNC_MOVES
	{ "motionSystem",		OBJECT_MODEL_FUNC((int32_t)self->GetActiveQueueNumber()),							ObjectModelEntryFlags::live },
#endif
	{ "name",				OBJECT_MODEL_FUNC(self->codeChannel.ToString()),									ObjectModelEntryFlags::none },
	{ "selectedPlane",		OBJECT_MODEL_FUNC((int32_t)self->machineState->selectedPlane),						ObjectModelEntryFlags::none },
	{ "stackDepth",			OBJECT_MODEL_FUNC((int32_t)self->GetStackDepth()),									ObjectModelEntryFlags::none },
	{ "state",				OBJECT_MODEL_FUNC(self->GetStateText()),											ObjectModelEntryFlags::live },
	{ "volumetric",			OBJECT_MODEL_FUNC((bool)self->machineState->volumetricExtrusion),					ObjectModelEntryFlags::none },
};

constexpr uint8_t GCodeBuffer::objectModelTableDescriptor[] = { 1, 14 + SUPPORT_ASYNC_MOVES };

DEFINE_GET_OBJECT_MODEL_TABLE(GCodeBuffer)

const char *GCodeBuffer::GetStateText() const noexcept
{
	if (machineState->waitingForAcknowledgement)
	{
		return "awaitingAcknowledgement";
	}

	switch (bufferState)
	{
	case GCodeBufferState::parseNotStarted:		return "idle";
	case GCodeBufferState::ready:				return "executing";
	case GCodeBufferState::executing:			return "waiting";
	default:									return "reading";
	}
}

#endif

// Create a default GCodeBuffer
GCodeBuffer::GCodeBuffer(GCodeChannel::RawType channel, GCodeInput *normalIn, FileGCodeInput *fileIn, MessageType mt, Compatibility::RawType c) noexcept
	:
#if SUPPORT_ASYNC_MOVES
	  syncState(SyncState::running),
#endif
	  printFilePositionAtMacroStart(0),
	  normalInput(normalIn),
#if HAS_MASS_STORAGE || HAS_EMBEDDED_FILES
	  fileInput(fileIn),
#endif
	  responseMessageType(mt),
#if HAS_SBC_INTERFACE
	  binaryParser(*this),
#endif
	  stringParser(*this),
	  machineState(new GCodeMachineState()), whenReportDueTimerStarted(millis()),
	  codeChannel(channel), lastResult(GCodeResult::ok),
	  timerRunning(false), motionCommanded(false)

#if HAS_SBC_INTERFACE
	  , isWaitingForMacro(false), isBinaryBuffer(false), invalidated(false)
#endif
{
	mutex.Create(((GCodeChannel)channel).ToString());
	machineState->compatibility = c;
	Reset();
}

// Reset it to its state after start-up
void GCodeBuffer::Reset() noexcept
{
#if HAS_SBC_INTERFACE
	if (isWaitingForMacro)
	{
		ResolveMacroRequest(true, false);
	}
#endif

	while (PopState(false)) { }

#if HAS_SBC_INTERFACE
	isBinaryBuffer = false;
	requestedMacroFile.Clear();
	isWaitingForMacro = macroFileClosed = false;
	macroJustStarted = macroFileError = macroFileEmpty = abortFile = abortAllFiles = sendToSbc = messagePromptPending = messageAcknowledged = false;
	machineState->lastCodeFromSbc = machineState->macroStartedByCode = false;
#endif
	Init();
}

// Set it up to parse another G-code
void GCodeBuffer::Init() noexcept
{
#if HAS_SBC_INTERFACE
	sendToSbc = false;
	binaryParser.Init();
#endif
	stringParser.Init();
	timerRunning = false;
}

void GCodeBuffer::StartTimer() noexcept
{
	whenTimerStarted = millis();
	timerRunning = true;
}

// Delay executing this GCodeBuffer for the specified time. Return true when the timer has expired.
bool GCodeBuffer::DoDwellTime(uint32_t dwellMillis) noexcept
{
	const uint32_t now = millis();

	// Are we already in the dwell?
	if (timerRunning)
	{
		if (now - whenTimerStarted >= dwellMillis)
		{
			timerRunning = false;
			return true;
		}
		return false;
	}

	// New dwell - set it up
	StartTimer();
	return false;
}

// Delay executing this GCodeBuffer for the specified time. Return true when the timer has expired.
bool GCodeBuffer::IsReportDue() noexcept
{
	const uint32_t now = millis();

	// Are we due?
	if (now - whenReportDueTimerStarted >= reportDueInterval)
	{
		ResetReportDueTimer();
		return true;
	}
	return false;
}

// Write some debug info
void GCodeBuffer::Diagnostics(MessageType mtype) noexcept
{
	String<StringLength256> scratchString;
	scratchString.copy(codeChannel.ToString());
#if HAS_SBC_INTERFACE
	scratchString.cat(IsBinary() ? "* " : " ");
#else
	scratchString.cat(" ");
#endif
	switch (bufferState)
	{
	case GCodeBufferState::parseNotStarted:
		scratchString.cat("is idle");
		break;

	case GCodeBufferState::ready:
		scratchString.cat("is ready with \"");
		AppendFullCommand(scratchString.GetRef());
		scratchString.cat('"');
		break;

	case GCodeBufferState::executing:
		scratchString.cat("is doing \"");
		AppendFullCommand(scratchString.GetRef());
		scratchString.cat('"');
		break;

	default:
		scratchString.cat("is assembling a command");
	}

	scratchString.cat(" in state(s)");
	const GCodeMachineState *ms = machineState;
	do
	{
		scratchString.catf(" %d", (int)ms->GetState());
		ms = ms->GetPrevious();
	} while (ms != nullptr);
	if (IsDoingFileMacro())
	{
		scratchString.cat(", running macro");
	}
	scratchString.cat('\n');
	reprap.GetPlatform().Message(mtype, scratchString.c_str());
}

// Add a character to the end
bool GCodeBuffer::Put(char c) noexcept
{
#if HAS_SBC_INTERFACE
	machineState->lastCodeFromSbc = false;
	isBinaryBuffer = false;
#endif
	return stringParser.Put(c);
}

// Decode the command in the buffer when it is complete
void GCodeBuffer::DecodeCommand() noexcept
{
	PARSER_OPERATION(DecodeCommand());
}

// Check whether the current command is a meta command, or we are skipping a block. Return true if we are and the current line no longer needs to be processed.
bool GCodeBuffer::CheckMetaCommand(const StringRef& reply)
{
	return NOT_BINARY_AND(stringParser.CheckMetaCommand(reply));
}

#if HAS_SBC_INTERFACE

// Add an entire binary G-Code, overwriting any existing content
// CAUTION! This may be called with the task scheduler suspended, so don't do anything that might block or take more than a few microseconds to execute
void GCodeBuffer::PutBinary(const uint32_t *data, size_t len) noexcept
{
	machineState->lastCodeFromSbc = true;
	isBinaryBuffer = true;
	macroJustStarted = false;
	binaryParser.Put(data, len);
}

#endif

// Add an entire G-Code, overwriting any existing content
void GCodeBuffer::PutAndDecode(const char *str, size_t len) noexcept
{
#if HAS_SBC_INTERFACE
	machineState->lastCodeFromSbc = false;
	isBinaryBuffer = false;
#endif
	stringParser.PutAndDecode(str, len);
}

// Add a null-terminated string, overwriting any existing content
void GCodeBuffer::PutAndDecode(const char *str) noexcept
{
#if HAS_SBC_INTERFACE
	machineState->lastCodeFromSbc = false;
	isBinaryBuffer = false;
#endif
	stringParser.PutAndDecode(str);
}

void GCodeBuffer::StartNewFile() noexcept
{
#if HAS_SBC_INTERFACE
	machineState->SetFileExecuting();
#endif
	machineState->lineNumber = 0;						// reset line numbering when M32 is run
	IF_NOT_BINARY(stringParser.StartNewFile());
}

// Called when we reach the end of the file we are reading from. Return true if there is a line waiting to be processed.
bool GCodeBuffer::FileEnded() noexcept
{
	return NOT_BINARY_AND(stringParser.FileEnded());
}

char GCodeBuffer::GetCommandLetter() const noexcept
{
	return PARSER_OPERATION(GetCommandLetter());
}

bool GCodeBuffer::HasCommandNumber() const noexcept
{
	return PARSER_OPERATION(HasCommandNumber());
}

int GCodeBuffer::GetCommandNumber() const noexcept
{
	return PARSER_OPERATION(GetCommandNumber());
}

void GCodeBuffer::GetCompleteParameters(const StringRef& str) THROWS(GCodeException)
{
	PARSER_OPERATION(GetCompleteParameters(str));
}

int8_t GCodeBuffer::GetCommandFraction() const noexcept
{
	return PARSER_OPERATION(GetCommandFraction());
}

#if SUPPORT_ASYNC_MOVES

// Determine whether the other input channel is at a strictly later point than we are
bool GCodeBuffer::IsLaterThan(const GCodeBuffer& other) const noexcept
{
	unsigned int ourDepth = GetStackDepth();
	unsigned int otherDepth = other.GetStackDepth();
	const GCodeMachineState *ourState = machineState;
	const GCodeMachineState *otherState = other.machineState;
	while (ourDepth > otherDepth)
	{
		ourState = ourState->GetPrevious();
		--ourDepth;
	}
	while (otherDepth > ourDepth)
	{
		otherState = otherState->GetPrevious();
		--otherDepth;
	}

	bool otherIsLater = false;
	while (ourState != nullptr)
	{
		if (otherState->lineNumber > ourState->lineNumber)
		{
			otherIsLater = true;
		}
		else if (otherState->lineNumber < ourState->lineNumber)
		{
			otherIsLater = false;
		}
		otherState = otherState->GetPrevious();
		ourState = ourState->GetPrevious();
	}

	return otherIsLater;
}

#endif

// Return true if the command we have just completed was the last command in the line of GCode.
// If the command was or called a macro then there will be no command in the buffer, so we must return true for this case also.
bool GCodeBuffer::IsLastCommand() const noexcept
{
	return IS_BINARY_OR((bufferState != GCodeBufferState::ready && bufferState != GCodeBufferState::executing) || stringParser.IsLastCommand());
}

bool GCodeBuffer::ContainsExpression() const noexcept
{
	return PARSER_OPERATION(ContainsExpression());
}

// Is a character present?
bool GCodeBuffer::Seen(char c) noexcept
{
	return PARSER_OPERATION(Seen(c));
}

ParameterLettersBitmap GCodeBuffer::AllParameters() const noexcept
{
	return PARSER_OPERATION(AllParameters());
}

// Test for character present, throw error if not
void GCodeBuffer::MustSee(char c) THROWS(GCodeException)
{
	if (!Seen(c))
	{
		throw GCodeException(GetLineNumber(), -1, "missing parameter '%c'", (uint32_t)c);
	}
}

// Test for one of two characters present, throw error if not saying that the first one is missing
char GCodeBuffer::MustSee(char c1, char c2) THROWS(GCodeException)
{
	if (Seen(c1)) { return c1; }
	if (Seen(c2)) { return c2; }
	throw GCodeException(GetLineNumber(), -1, "missing parameter '%c'", (uint32_t)c1);
}

// Get a float after a key letter
float GCodeBuffer::GetFValue() THROWS(GCodeException)
{
	return PARSER_OPERATION(GetFValue());
}

// Get a float after a key letter and check that it is greater then zero
float GCodeBuffer::GetPositiveFValue() THROWS(GCodeException)
{
	const int column =
#if HAS_SBC_INTERFACE
						(isBinaryBuffer) ? -1 :
#endif
							stringParser.GetColumn();
	const float val = GetFValue();
	if (val > 0.0) { return val; }
	throw GCodeException(GetLineNumber(), column, "value must be greater than zero");
}

// Get a float after a key letter and check that it is greater than or equal to zero
float GCodeBuffer::GetNonNegativeFValue() THROWS(GCodeException)
{
	const int column =
#if HAS_SBC_INTERFACE
						(isBinaryBuffer) ? -1 :
#endif
							stringParser.GetColumn();
	const float val = GetFValue();
	if (val >= 0.0) { return val; }
	throw GCodeException(GetLineNumber(), column, "value must be not less than zero");
}

float GCodeBuffer::GetLimitedFValue(char c, float minValue, float maxValue) THROWS(GCodeException)
{
	MustSee(c);
	const int column =
#if HAS_SBC_INTERFACE
						(isBinaryBuffer) ? -1 :
#endif
							stringParser.GetColumn();
	const float ret = GetFValue();
	if (ret < minValue) { throw GCodeException(GetLineNumber(), column, "parameter '%c' too low", (uint32_t)c); }
	if (ret > maxValue) { throw GCodeException(GetLineNumber(), column, "parameter '%c' too high", (uint32_t)c); }
	return ret;
}

// Get a distance or coordinate and convert it from inches to mm if necessary
float GCodeBuffer::GetDistance() THROWS(GCodeException)
{
	return ConvertDistance(GetFValue());
}

// Get a speed in mm/min or inches/min and convert it to mm/step_clock
float GCodeBuffer::GetSpeed() THROWS(GCodeException)
{
	return ConvertSpeed(GetFValue());
}

// Get a speed in mm/min mm/sec and convert it to mm/step_clock
float GCodeBuffer::GetSpeedFromMm(bool useSeconds) THROWS(GCodeException)
{
	return ConvertSpeedFromMm(GetFValue(), useSeconds);
}

// Get an acceleration in mm/sec^2 and convert it to mm/step_clock^2
float GCodeBuffer::GetAcceleration() THROWS(GCodeException)
{
	return ConvertAcceleration(GetFValue());
}

// Get an integer after a key letter
int32_t GCodeBuffer::GetIValue() THROWS(GCodeException)
{
	return PARSER_OPERATION(GetIValue());
}

// Get an integer with limit checking
int32_t GCodeBuffer::GetLimitedIValue(char c, int32_t minValue, int32_t maxValue) THROWS(GCodeException)
{
	MustSee(c);
	const int32_t ret = GetIValue();
	if (ret < minValue)
	{
		throw GCodeException(GetLineNumber(), -1, "parameter '%c' too low", (uint32_t)c);
	}
	if (ret > maxValue)
	{
		throw GCodeException(GetLineNumber(), -1, "parameter '%c' too high", (uint32_t)c);
	}
	return ret;
}

// Get an unsigned integer value
uint32_t GCodeBuffer::GetUIValue() THROWS(GCodeException)
{
	return PARSER_OPERATION(GetUIValue());
}

// Get an unsigned integer value, throw if >= limit
uint32_t GCodeBuffer::GetLimitedUIValue(char c, uint32_t minValue, uint32_t maxValuePlusOne) THROWS(GCodeException)
{
	MustSee(c);
	const uint32_t ret = GetUIValue();
	if (ret < minValue)
	{
		throw GCodeException(GetLineNumber(), -1, "parameter '%c' too low", (uint32_t)c);
	}
	if (ret >= maxValuePlusOne)
	{
		throw GCodeException(GetLineNumber(), -1, "parameter '%c' too high", (uint32_t)c);
	}
	return ret;
}

// Get an IP address quad after a key letter
void GCodeBuffer::GetIPAddress(IPAddress& returnedIp) THROWS(GCodeException)
{
	PARSER_OPERATION(GetIPAddress(returnedIp));
}

// Get a MAC address sextet after a key letter
void GCodeBuffer::GetMacAddress(MacAddress& mac) THROWS(GCodeException)
{
	PARSER_OPERATION(GetMacAddress(mac));
}

// Get a string with no preceding key letter
void GCodeBuffer::GetUnprecedentedString(const StringRef& str, bool allowEmpty) THROWS(GCodeException)
{
	PARSER_OPERATION(GetUnprecedentedString(str, allowEmpty));
}

// Get and copy a quoted string
void GCodeBuffer::GetQuotedString(const StringRef& str, bool allowEmpty) THROWS(GCodeException)
{
	PARSER_OPERATION(GetQuotedString(str, allowEmpty));
}

// Get and copy a string which may or may not be quoted
void GCodeBuffer::GetPossiblyQuotedString(const StringRef& str, bool allowEmpty) THROWS(GCodeException)
{
	PARSER_OPERATION(GetPossiblyQuotedString(str, allowEmpty));
}

void GCodeBuffer::GetReducedString(const StringRef& str) THROWS(GCodeException)
{
	// In order to handle string expressions here we first get a quoted string, then we reduce it
	PARSER_OPERATION(GetQuotedString(str, false));
	char *q = str.Pointer();
	const char *p = q;
	while (*p != 0)
	{
		const char c = *p++;
		if (c != '-' && c != '_' && c != ' ')
		{
			*q++ = tolower(c);
		}
	}
	*q = 0;
}

// Get a colon-separated list of floats after a key letter
void GCodeBuffer::GetFloatArray(float arr[], size_t& length, bool doPad) THROWS(GCodeException)
{
	const size_t maxLength = length;
	PARSER_OPERATION(GetFloatArray(arr, length));
	// If there is one entry and doPad is true, fill the rest of the array with the first entry.
	if (doPad && length == 1)
	{
		while (length < maxLength)
		{
			arr[length++] = arr[0];
		}
	}
}

// Get a :-separated list of ints after a key letter
void GCodeBuffer::GetIntArray(int32_t arr[], size_t& length, bool doPad) THROWS(GCodeException)
{
	const size_t maxLength = length;
	PARSER_OPERATION(GetIntArray(arr, length));
	// If there is one entry and doPad is true, fill the rest of the array with the first entry.
	if (doPad && length == 1)
	{
		while (length < maxLength)
		{
			arr[length++] = arr[0];
		}
	}
}

// Get a :-separated list of unsigned ints after a key letter
void GCodeBuffer::GetUnsignedArray(uint32_t arr[], size_t& length, bool doPad) THROWS(GCodeException)
{
	const size_t maxLength = length;
	PARSER_OPERATION(GetUnsignedArray(arr, length));
	// If there is one entry and doPad is true, fill the rest of the array with the first entry.
	if (doPad && length == 1)
	{
		while (length < maxLength)
		{
			arr[length++] = arr[0];
		}
	}
}

// Get a string array after a key letter
ExpressionValue GCodeBuffer::GetExpression() THROWS(GCodeException)
{
	return PARSER_OPERATION(GetExpression());
}

// Get a :-separated list of drivers after a key letter
void GCodeBuffer::GetDriverIdArray(DriverId arr[], size_t& length)
{
	PARSER_OPERATION(GetDriverIdArray(arr, length));
}

// If the specified parameter character is found, fetch 'value' and set 'seen'. Otherwise leave val and seen alone.
bool GCodeBuffer::TryGetFValue(char c, float& val, bool& seen) THROWS(GCodeException)
{
	const bool ret = Seen(c);
	if (ret)
	{
		val = GetFValue();
		seen = true;
	}
	return ret;
}

// If the specified parameter character is found, fetch 'value' and set 'seen'. Otherwise leave val and seen alone.
bool GCodeBuffer::TryGetIValue(char c, int32_t& val, bool& seen) THROWS(GCodeException)
{
	const bool ret = Seen(c);
	if (ret)
	{
		val = GetIValue();
		seen = true;
	}
	return ret;
}

// Try to get a signed integer value, throw if outside limits
bool GCodeBuffer::TryGetLimitedIValue(char c, int32_t& val, bool& seen, int32_t minValue, int32_t maxValue) THROWS(GCodeException)
{
	if (Seen(c))
	{
		val = GetLimitedUIValue(c, minValue, maxValue);
		seen = true;
		return true;
	}
	return false;
}

bool GCodeBuffer::TryGetNonNegativeFValue(char c, float& val, bool& seen) THROWS(GCodeException)
{
	if (Seen(c))
	{
		val = GetNonNegativeFValue();
		seen = true;
		return true;
	}
	return false;
}

// If the specified parameter character is found, fetch 'value' and set 'seen'. Otherwise leave val and seen alone.
bool GCodeBuffer::TryGetUIValue(char c, uint32_t& val, bool& seen) THROWS(GCodeException)
{
	const bool ret = Seen(c);
	if (ret)
	{
		val = GetUIValue();
		seen = true;
	}
	return ret;
}

// Try to get an unsigned integer value, throw if >= limit
bool GCodeBuffer::TryGetLimitedUIValue(char c, uint32_t& val, bool& seen, uint32_t maxValuePlusOne) THROWS(GCodeException)
{
	if (Seen(c))
	{
		val = GetLimitedUIValue(c, maxValuePlusOne);
		seen = true;
		return true;
	}
	return false;
}

// If the specified parameter character is found, fetch 'value' as a Boolean and set 'seen'. Otherwise leave val and seen alone.
bool GCodeBuffer::TryGetBValue(char c, bool& val, bool& seen) THROWS(GCodeException)
{
	const bool ret = Seen(c);
	if (ret)
	{
		val = GetIValue() > 0;
		seen = true;
	}
	return ret;
}

// Try to get an int array exactly 'numVals' long after parameter letter 'c'.
// If the wrong number of values is provided, generate an error message and return true.
// Else set 'seen' if we saw the letter and value, and return false.
void GCodeBuffer::TryGetUIArray(char c, size_t numVals, uint32_t vals[], bool& seen, bool doPad) THROWS(GCodeException)
{
	if (Seen(c))
	{
		size_t count = numVals;
		GetUnsignedArray(vals, count, doPad);
		if (count == numVals)
		{
			seen = true;
		}
		else
		{
			ThrowGCodeException("Wrong number of values in array, expected %u", (uint32_t)numVals);
		}
	}
}

// Try to get a float array exactly 'numVals' long after parameter letter 'c'.
// If the wrong number of values is provided, generate an error message and return true.
// Else set 'seen' if we saw the letter and value, and return false.
void GCodeBuffer::TryGetFloatArray(char c, size_t numVals, float vals[], bool& seen, bool doPad) THROWS(GCodeException)
{
	if (Seen(c))
	{
		size_t count = numVals;
		GetFloatArray(vals, count, doPad);
		if (count == numVals)
		{
			seen = true;
		}
		else
		{
			ThrowGCodeException("Wrong number of values in array, expected %u", (uint32_t)numVals);
		}
	}
}

// Try to get a quoted string after parameter letter.
// If we found it then set 'seen' true and return true, else leave 'seen' alone and return false
bool GCodeBuffer::TryGetQuotedString(char c, const StringRef& str, bool& seen, bool allowEmpty) THROWS(GCodeException)
{
	if (Seen(c))
	{
		seen = true;
		GetQuotedString(str, allowEmpty);
		return true;
	}
	return false;
}

// Try to get a non-empty string, which may be quoted, after parameter letter.
// If we found it then set 'seen' true and return true, else leave 'seen' alone and return false
bool GCodeBuffer::TryGetPossiblyQuotedString(char c, const StringRef& str, bool& seen) THROWS(GCodeException)
{
	if (Seen(c))
	{
		seen = true;
		GetPossiblyQuotedString(str);
		return true;
	}
	return false;
}

// Get a PWM frequency
PwmFrequency GCodeBuffer::GetPwmFrequency() THROWS(GCodeException)
{
	return (PwmFrequency)constrain<uint32_t>(GetUIValue(), 1, 65535);
}

// Get a PWM value. If may be in the old style 0..255 in which case convert it to be in the range 0.0..1.0
float GCodeBuffer::GetPwmValue() THROWS(GCodeException)
{
	float v = GetFValue();
	if (v > 1.0)
	{
		v = v/255.0;
	}
	return constrain<float>(v, 0.0, 1.0);
}

// Get a driver ID
DriverId GCodeBuffer::GetDriverId() THROWS(GCodeException)
{
	return PARSER_OPERATION(GetDriverId());
}

bool GCodeBuffer::IsIdle() const noexcept
{
	return bufferState != GCodeBufferState::ready && bufferState != GCodeBufferState::executing;
}

bool GCodeBuffer::IsCompletelyIdle() const noexcept
{
	return GetState() == GCodeState::normal && IsIdle();
}

void GCodeBuffer::SetFinished(bool f) noexcept
{
	if (f)
	{
#if HAS_SBC_INTERFACE
		sendToSbc = false;
#endif
		LatestMachineState().firstCommandAfterRestart = false;
		PARSER_OPERATION(SetFinished());
	}
	else
	{
		bufferState = GCodeBufferState::executing;
	}
}

void GCodeBuffer::SetCommsProperties(uint32_t arg) noexcept
{
	IF_NOT_BINARY(stringParser.SetCommsProperties(arg));
}

// Get the original machine state before we pushed anything
GCodeMachineState& GCodeBuffer::OriginalMachineState() const noexcept
{
	GCodeMachineState *ms = machineState;
	while (ms->GetPrevious() != nullptr)
	{
		ms = ms->GetPrevious();
	}
	return *ms;
}

GCodeMachineState& GCodeBuffer::CurrentFileMachineState() const noexcept
{
	GCodeMachineState *ms = machineState;
	while (ms->localPush && ms->GetPrevious() != nullptr)
	{
		ms = ms->GetPrevious();
	}
	return *ms;
}

// Return true if all GCodes machine states on the stack are 'normal'
bool GCodeBuffer::AllStatesNormal() const noexcept
{
	for (const GCodeMachineState *ms = machineState; ms != nullptr; ms = ms->GetPrevious())
	{
		if (ms->GetState() != GCodeState::normal)
		{
			return false;
		}
	}
	return true;
}

// Convert from inches to mm if necessary
float GCodeBuffer::ConvertDistance(float distance) const noexcept
{
	return (UsingInches()) ? distance * InchToMm : distance;
}

// Convert from mm to inches if necessary
float GCodeBuffer::InverseConvertDistance(float distance) const noexcept
{
	return (UsingInches()) ? distance/InchToMm : distance;
}

// Convert speed from mm/min or inches/min to mm per step clock
float GCodeBuffer::ConvertSpeed(float speed) const noexcept
{
	return speed * ((UsingInches()) ? InchToMm/(StepClockRate * iMinutesToSeconds) : 1.0/(StepClockRate * iMinutesToSeconds));
}

// Convert speed to mm/min or inches/min
float GCodeBuffer::InverseConvertSpeed(float speed) const noexcept
{
	return speed * ((UsingInches()) ? (StepClockRate * iMinutesToSeconds)/InchToMm : (float)(StepClockRate * iMinutesToSeconds));
}

const char *GCodeBuffer::GetDistanceUnits() const noexcept
{
	return (UsingInches()) ? "in" : "mm";
}

// Return the  current stack depth
unsigned int GCodeBuffer::GetStackDepth() const noexcept
{
	unsigned int depth = 0;
	for (const GCodeMachineState *m1 = machineState; m1->GetPrevious() != nullptr; m1 = m1->GetPrevious())
	{
		++depth;
	}
	return depth;
}

// Push state returning true if successful (i.e. stack not overflowed)
bool GCodeBuffer::PushState(bool withinSameFile) noexcept
{
	// Check the current stack depth
	if (GetStackDepth() >= MaxStackDepth)
	{
		return false;
	}

	machineState = new GCodeMachineState(*machineState, withinSameFile);
	reprap.InputsUpdated();
	return true;
}

// Pop state returning true if successful (i.e. no stack underrun)
bool GCodeBuffer::PopState(bool withinSameFile) noexcept
{
	bool poppedFileState;
	do
	{
		GCodeMachineState * const ms = machineState;
		if (ms->GetPrevious() == nullptr)
		{
			ms->messageAcknowledged = false;			// avoid getting stuck in a loop trying to pop
			ms->waitingForAcknowledgement = false;
			return false;
		}

		poppedFileState = !ms->localPush;
		machineState = ms->Pop();						// get the previous state and copy down any error message
		delete ms;
	} while (!withinSameFile && !poppedFileState);
	IF_NOT_BINARY(stringParser.ResetIndentation());

	reprap.InputsUpdated();
	return true;
}

// Abort execution of any files or macros being executed
// We now avoid popping the state if we were not executing from a file, so that if DWC or PanelDue is used to jog the axes before they are homed, we don't report stack underflow.
void GCodeBuffer::AbortFile(bool abortAll, bool requestAbort) noexcept
{
	if (machineState->DoingFile())
	{
		do
		{
			if (machineState->DoingFile())
			{
#if HAS_MASS_STORAGE || HAS_EMBEDDED_FILES
# if HAS_SBC_INTERFACE
				if (!reprap.UsingSbcInterface())
# endif
				{
					fileInput->Reset(machineState->fileState);
				}
#endif
				machineState->CloseFile();
			}
		} while (PopState(false) && abortAll);

#if HAS_SBC_INTERFACE
		abortFile = requestAbort;
		abortAllFiles = requestAbort && abortAll;
	}
	else if (!requestAbort)
	{
		abortFile = abortAllFiles = false;
#endif
	}
}

// This is called on a fileGCode when we stop a print. It closes the file and re-initialises the buffer.
void GCodeBuffer::ClosePrintFile() noexcept
{
#if HAS_SBC_INTERFACE
	if (reprap.UsingSbcInterface())
	{
		FileId printFileId = OriginalMachineState().fileId;
		if (printFileId != NoFileId)
		{
			for (GCodeMachineState *ms = machineState; ms != nullptr; ms = ms->GetPrevious())
			{
				if (ms->fileId == printFileId)
				{
					ms->fileId = NoFileId;
				}
			}
		}
	}
	else
#endif
	{
#if HAS_MASS_STORAGE || HAS_EMBEDDED_FILES
		FileData& fileBeingPrinted = OriginalMachineState().fileState;
		GetFileInput()->Reset(fileBeingPrinted);
		if (fileBeingPrinted.IsLive())
		{
			fileBeingPrinted.Close();
		}
#endif
	}

	Init();
}

#if HAS_SBC_INTERFACE

void GCodeBuffer::SetFileFinished() noexcept
{
	FileId macroFileId = NoFileId, printFileId = OriginalMachineState().fileId;
	for (GCodeMachineState *ms = machineState; ms != nullptr; ms = ms->GetPrevious())
	{
		if (macroFileId == NoFileId && ms->fileId != NoFileId && ms->fileId != printFileId && !ms->fileFinished)
		{
			// Get the next macro file being executed
			macroFileId = ms->fileId;
		}

		if (macroFileId != NoFileId)
		{
			if (ms->fileId == macroFileId)
			{
				// Flag it (and following machine states) as finished
				ms->fileFinished = true;
			}
			else
			{
				break;
			}
		}
	}

	if (macroFileId != NoFileId)
	{
		reprap.GetSbcInterface().EventOccurred();
	}
}

void GCodeBuffer::SetPrintFinished() noexcept
{
	FileId printFileId = OriginalMachineState().fileId;
	if (printFileId != NoFileId)
	{
		for (GCodeMachineState *ms = machineState; ms != nullptr; ms = ms->GetPrevious())
		{
			if (ms->fileId == printFileId)
			{
				// Mark machine states executing the print file as finished
				ms->fileFinished = true;
			}
		}
		reprap.GetSbcInterface().EventOccurred();
	}
}

// This is only called when using the SBC interface and returns if the macro file could be opened
bool GCodeBuffer::RequestMacroFile(const char *filename, bool fromCode) noexcept
{
	if (!reprap.GetSbcInterface().IsConnected())
	{
		// Don't wait for a macro file if no SBC is connected
		return false;
	}

	// Request the macro file from the SBC
	macroJustStarted = macroFileError = macroFileEmpty = false;
	machineState->macroStartedByCode = fromCode;
	requestedMacroFile.copy(filename);

	// There is no need to block the main task if daemon.g is requested.
	// If it doesn't exist, DSF will simply close the virtual file again
	if (GetChannel() != GCodeChannel::Daemon || machineState->doingFileMacro)
	{
		// Wait for a response (but not forever)
		isWaitingForMacro = true;
		reprap.GetSbcInterface().EventOccurred(true);
		if (!macroSemaphore.Take(SpiMaxRequestTime))
		{
			isWaitingForMacro = false;
			reprap.GetPlatform().MessageF(ErrorMessage, "Timeout while waiting for macro file %s (channel %s)\n", filename, GetChannel().ToString());
			return false;
		}
	}

	// When we get here we expect the SBC interface to have set the variables above for us
	if (!macroFileError)
	{
		macroJustStarted = true;
		return true;
	}
	return false;
}

void GCodeBuffer::ResolveMacroRequest(bool hadError, bool isEmpty) noexcept
{
	macroFileError = hadError;
	macroFileEmpty = !hadError && isEmpty;
	isWaitingForMacro = false;
	macroSemaphore.Give();
}

void GCodeBuffer::MacroFileClosed() noexcept
{
	machineState->CloseFile();
	macroJustStarted = false;
	macroFileClosed = true;
	reprap.GetSbcInterface().EventOccurred();
}

#endif

// Tell this input source that any message it sent and is waiting on has been acknowledged
// Allow for the possibility that the source may have started running a macro since it started waiting
void GCodeBuffer::MessageAcknowledged(bool cancelled, ExpressionValue rslt) noexcept
{
	for (GCodeMachineState *ms = machineState; ms != nullptr; ms = ms->GetPrevious())
	{
		if (ms->waitingForAcknowledgement)
		{
			ms->waitingForAcknowledgement = false;
			ms->messageAcknowledged = true;
			ms->messageCancelled = cancelled;
			m291Result = rslt;
			if (cancelled)
			{
				lastResult = GCodeResult::m291Cancelled;
			}
#if HAS_SBC_INTERFACE
			messageAcknowledged = !cancelled || !ms->DoingFile();
			reprap.GetSbcInterface().EventOccurred();
#endif
		}
	}
}

MessageType GCodeBuffer::GetResponseMessageType() const noexcept
{
#if HAS_SBC_INTERFACE
	if (machineState->lastCodeFromSbc)
	{
		return (MessageType)((1u << codeChannel.ToBaseType()) | BinaryCodeReplyFlag);
	}
#endif
	return responseMessageType;
}

FilePosition GCodeBuffer::GetJobFilePosition() const noexcept
{
	return (IsFileChannel() && !IsDoingFileMacro()) ? PARSER_OPERATION(GetFilePosition()) : noFilePosition;
}

// Return the current position of the file being printed in bytes.
// May return noFilePosition if allowNoFilePos is true
FilePosition GCodeBuffer::GetPrintingFilePosition(bool allowNoFilePos) const noexcept
{
#if HAS_SBC_INTERFACE
	if (!reprap.UsingSbcInterface())
#endif
	{
#if HAS_MASS_STORAGE || HAS_EMBEDDED_FILES
		const FileData& fileBeingPrinted = OriginalMachineState().fileState;
		if (!fileBeingPrinted.IsLive())
		{
			return allowNoFilePos ? noFilePosition : 0;
		}
#endif
	}

#if HAS_MASS_STORAGE || HAS_EMBEDDED_FILES || HAS_SBC_INTERFACE
	const FilePosition pos = (IsDoingFileMacro())
			? printFilePositionAtMacroStart						// the position before we started executing the macro
				: GetJobFilePosition();							// the actual position, allowing for bytes cached but not yet processed
	return (pos != noFilePosition || allowNoFilePos) ? pos : 0;
#else
	return allowNoFilePos ? noFilePosition : 0;
#endif
}

void GCodeBuffer::SavePrintingFilePosition() noexcept
{
	printFilePositionAtMacroStart = PARSER_OPERATION(GetFilePosition());
}

void GCodeBuffer::WaitForAcknowledgement() noexcept
{
	machineState->WaitForAcknowledgement();
#if HAS_SBC_INTERFACE
	if (reprap.UsingSbcInterface())
	{
		messagePromptPending = true;
	}
#endif
}

#if HAS_MASS_STORAGE

bool GCodeBuffer::OpenFileToWrite(const char* directory, const char* fileName, const FilePosition size, const bool binaryWrite, const uint32_t fileCRC32) noexcept
{
	return NOT_BINARY_AND(stringParser.OpenFileToWrite(directory, fileName, size, binaryWrite, fileCRC32));
}

bool GCodeBuffer::IsWritingFile() const noexcept
{
	return NOT_BINARY_AND(stringParser.IsWritingFile());
}

void GCodeBuffer::WriteToFile() noexcept
{
	IF_NOT_BINARY(stringParser.WriteToFile());
}

bool GCodeBuffer::IsWritingBinary() const noexcept
{
	return NOT_BINARY_AND(stringParser.IsWritingBinary());
}

bool GCodeBuffer::WriteBinaryToFile(char b) noexcept
{
	return IS_BINARY_OR(stringParser.WriteBinaryToFile(b));
}

void GCodeBuffer::FinishWritingBinary() noexcept
{
	IF_NOT_BINARY(stringParser.FinishWritingBinary());
}

#endif

void GCodeBuffer::RestartFrom(FilePosition pos) noexcept
{
#if HAS_MASS_STORAGE || HAS_EMBEDDED_FILES
	fileInput->Reset(machineState->fileState);		// clear the buffered data
	machineState->fileState.Seek(pos);				// replay the abandoned instructions when we resume
#endif
	Init();											// clear the next move
}

const char* GCodeBuffer::DataStart() const noexcept
{
	return PARSER_OPERATION(DataStart());
}

// Return the length of the command.
// WARNING! This may return the wrong value if the command has an unquoted string parameter and GetUnprecedentedString or GetPossiblyQuotedString hasn't been called yet.
size_t GCodeBuffer::DataLength() const noexcept
{
	return PARSER_OPERATION(DataLength());
}

void GCodeBuffer::PrintCommand(const StringRef& s) const noexcept
{
	PARSER_OPERATION(PrintCommand(s));
}

void GCodeBuffer::AppendFullCommand(const StringRef &s) const noexcept
{
	PARSER_OPERATION(AppendFullCommand(s));
}

void GCodeBuffer::AddParameters(VariableSet& vars, int codeRunning) noexcept
{
	PARSER_OPERATION(AddParameters(vars, codeRunning));
}

VariableSet& GCodeBuffer::GetVariables() const noexcept
{
	GCodeMachineState *mc = machineState;
	while (mc->localPush && mc->GetPrevious() != nullptr)
	{
		mc = mc->GetPrevious();
	}
	return mc->variables;
}

void GCodeBuffer::ThrowGCodeException(const char *msg) const THROWS(GCodeException)
{
	const int column =
#if HAS_SBC_INTERFACE
						(isBinaryBuffer) ? -1 :
#endif
							stringParser.GetColumn();
	throw GCodeException(GetLineNumber(), column, msg);
}

void GCodeBuffer::ThrowGCodeException(const char *msg, uint32_t param) const THROWS(GCodeException)
{
	const int column =
#if HAS_SBC_INTERFACE
						(isBinaryBuffer) ? -1 :
#endif
							stringParser.GetColumn();
	throw GCodeException(GetLineNumber(), column, msg, param);
}

#if SUPPORT_COORDINATE_ROTATION

bool GCodeBuffer::DoingCoordinateRotation() const noexcept
{
	return !LatestMachineState().g53Active && !LatestMachineState().runningSystemMacro && LatestMachineState().selectedPlane == 0;
}

#endif

// End