1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-09-01 02:21:46 +02:00
This commit is contained in:
bdring
2021-03-10 11:44:27 -06:00
parent d76a5fe2f2
commit 14016f9132
4 changed files with 78 additions and 4 deletions

View File

@@ -0,0 +1,43 @@
bool user_validate_gcode(char letter, uint8_t code_num, uint32_t &value_words) {
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Testing gcode");
if (letter == 'G') {
return false;
} else if (letter == 'M') {
switch (code_num) {
case 115:
bit_false(value_words, bit(GCodeWord::E));
return true;
break;
default:
return false;
break;
}
} else {
return false; // default is to reject all unknown numbers
}
}
bool user_execute_gcode(char letter, uint8_t code_num, parser_block_t parser_block) {
if (letter == 'G') {
return false;
} else if (letter == 'M') {
switch (code_num) {
case 115:
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Execute M115 %d", parser_block.values.e);
return true;
break;
default:
return false;
break;
}
} else {
return false; // default is to reject all unknown numbers
}
}

View File

@@ -433,7 +433,12 @@ Error gc_execute_line(char* line, uint8_t client) {
mg_word_bit = ModalGroup::MG13;
break;
default:
FAIL(Error::GcodeUnsupportedCommand); // [Unsupported G command]
if (!user_validate_gcode(letter, int_value, value_words)) {
FAIL(Error::GcodeUnsupportedCommand); // [Unsupported G command]
} else {
gc_block.non_modal_command = NonModal::UserDefinedGcode;
//mg_word_bit = ModalGroup::MM99;
}
}
if (mantissa > 0) {
FAIL(Error::GcodeCommandValueNotInteger); // [Unsupported or invalid Gxx.x command]
@@ -550,7 +555,11 @@ Error gc_execute_line(char* line, uint8_t client) {
mg_word_bit = ModalGroup::MM10;
break;
default:
FAIL(Error::GcodeUnsupportedCommand); // [Unsupported M command]
if (!user_validate_gcode(letter, int_value, value_words)) {
FAIL(Error::GcodeUnsupportedCommand); // [Unsupported G command]
} else {
gc_block.non_modal_command = NonModal::UserDefinedGcode;
}
}
// Check for more than one command per modal group violations in the current block
// NOTE: Variable 'mg_word_bit' is always assigned, if the command is valid.
@@ -1041,6 +1050,8 @@ Error gc_execute_line(char* line, uint8_t client) {
FAIL(Error::GcodeG53InvalidMotionMode); // [G53 G0/1 not active]
}
break;
case NonModal::UserDefinedGcode:
break;
default:
break;
}
@@ -1503,6 +1514,11 @@ Error gc_execute_line(char* line, uint8_t client) {
case NonModal::ResetCoordinateOffset:
clear_vector(gc_state.coord_offset); // Disable G92 offsets by zeroing offset vector.
system_flag_wco_change();
break;
case NonModal::UserDefinedGcode:
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Execute my gcode");
user_execute_gcode('M', 115, gc_block);
break;
default:
break;
@@ -1615,7 +1631,15 @@ Error gc_execute_line(char* line, uint8_t client) {
return Error::Ok;
}
/*
bool __attribute__((weak)) user_validate_gcode(char letter, uint8_t code_num, uint32_t &value_words) {
return false; // default is to reject all unknown numbers
}
bool __attribute__((weak)) user_execute_gcode(char letter, uint8_t code_num, parser_block_t parser_block) {
return false;
}
/*
Not supported:
- Canned cycles

View File

@@ -48,7 +48,8 @@ enum class ModalGroup : uint8_t {
MM7 = 12, // [M3,M4,M5] Spindle turning
MM8 = 13, // [M7,M8,M9] Coolant control
MM9 = 14, // [M56] Override control
MM10 = 15, // [M62, M63, M64, M65, M67, M68] User Defined http://linuxcnc.org/docs/html/gcode/overview.html#_modal_groups
MM10 = 15, // [M62, M63, M64, M65, M67, M68] User Defined http://linuxcnc.org/docs/html/gcode/overview.html#_modal_groups
};
// Command actions for within execution-type modal groups (motion, stopping, non-modal). Used
@@ -71,6 +72,7 @@ enum class NonModal : uint8_t {
AbsoluteOverride = 53, // G53 (Do not alter value)
SetCoordinateOffset = 92, // G92 (Do not alter value)
ResetCoordinateOffset = 102, //G92.1 (Do not alter value)
UserDefinedGcode = 255, // User defined Gcode
};
// Modal Group G1: Motion modes
@@ -332,3 +334,6 @@ Error gc_execute_line(char* line, uint8_t client);
// Set g-code parser position. Input in steps.
void gc_sync_position();
bool user_validate_gcode(char letter, uint8_t code_num, uint32_t &value_words);
bool user_execute_gcode(char letter, uint8_t code_num, parser_block_t parser_block);

View File

@@ -37,6 +37,8 @@
#define MACHINE_NAME "Test Drive - Demo Only No I/O!"
#define CUSTOM_CODE_FILENAME "Custom/user_gcode_example.cpp"
#define N_AXIS 3
// This cannot use homing because there are no switches