mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-09-02 19:02:35 +02:00
WIP
This commit is contained in:
@@ -1,35 +1,69 @@
|
|||||||
|
/*
|
||||||
|
user_gcode_example.cpp
|
||||||
|
|
||||||
// value_words - Tells the parser what value words are required
|
Copyright (c) 2021 Barton Dring @buildlog
|
||||||
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') {
|
Used to add simple G or M codes to the firmware
|
||||||
return false;
|
If in doubt use an M code
|
||||||
} else if (letter == 'M') {
|
|
||||||
switch (code_num) {
|
You can pass letter values like
|
||||||
|
|
||||||
|
see the definiitons of parser_block_t and gc_values_t
|
||||||
|
Note: letters have different types like unit32_t and float
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
char current_letter = '\0';
|
||||||
|
uint8_t current_code_num = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Used as a basic validator to tell Grbl_ESP32 that the gcode is supported in this file.
|
||||||
|
Do not execute the gcode. That is in another function
|
||||||
|
|
||||||
|
letter 'G' or 'M' ('M' in the case of M115)
|
||||||
|
code_num xxx (115 in the case of M115)
|
||||||
|
value_words This will be sent as zer. You need to add every one you need (M114 E15 would need bit(GCodeWord::E) added to it)
|
||||||
|
|
||||||
|
return return true if the letter and code_num are support
|
||||||
|
|
||||||
|
*/
|
||||||
|
bool user_validate_gcode(char letter, uint8_t code_num, uint32_t& value_words) {
|
||||||
|
current_letter = letter;
|
||||||
|
current_code_num = code_num;
|
||||||
|
|
||||||
|
if (current_letter == 'G') {
|
||||||
|
// we don't support anythibg yet
|
||||||
|
} else if (current_letter == 'M') {
|
||||||
|
switch (current_code_num) {
|
||||||
case 115:
|
case 115:
|
||||||
bit_true(value_words, bit(GCodeWord::E));
|
//bit_true(value_words, bit(GCodeWord::E)); (not used, just here an an example)
|
||||||
|
return true;
|
||||||
return true;
|
default:
|
||||||
break;
|
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);
|
|
||||||
|
|
||||||
|
current_letter = '\0';
|
||||||
|
current_code_num = 0;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Execute the gcode.
|
||||||
|
|
||||||
|
parse_block contains a lot of info, most notably the letter and values like P12
|
||||||
|
*/
|
||||||
|
|
||||||
|
bool user_execute_gcode(parser_block_t parser_block) {
|
||||||
|
if (current_letter == 'G') {
|
||||||
|
return false;
|
||||||
|
} else if (current_letter == 'M') {
|
||||||
|
switch (current_code_num) {
|
||||||
|
case 115:
|
||||||
|
//grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Execute %c%d %d", current_letter, current_code_num, parser_block.values.e);
|
||||||
|
grbl_sendf(
|
||||||
|
CLIENT_SERIAL, "FIRMWARE_NAME:Grbl_ESP32, FIRMWARE_VERSION:%s, FIRMWARE_BUILD:%s\r\n", GRBL_VERSION, GRBL_VERSION_BUILD);
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@@ -1274,8 +1274,7 @@ Error gc_execute_line(char* line, uint8_t client) {
|
|||||||
bit(GCodeWord::C))); // Remove axis words.
|
bit(GCodeWord::C))); // Remove axis words.
|
||||||
}
|
}
|
||||||
if (gc_block.non_modal_command == NonModal::UserDefinedGcode) {
|
if (gc_block.non_modal_command == NonModal::UserDefinedGcode) {
|
||||||
// clean up words
|
// Clean up value word from user gcode checking
|
||||||
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Cleanup: %d %d", value_words, user_value_words);
|
|
||||||
bit_false(value_words, user_value_words);
|
bit_false(value_words, user_value_words);
|
||||||
}
|
}
|
||||||
if (value_words) {
|
if (value_words) {
|
||||||
@@ -1522,9 +1521,7 @@ Error gc_execute_line(char* line, uint8_t client) {
|
|||||||
system_flag_wco_change();
|
system_flag_wco_change();
|
||||||
break;
|
break;
|
||||||
case NonModal::UserDefinedGcode:
|
case NonModal::UserDefinedGcode:
|
||||||
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Execute my gcode");
|
user_execute_gcode(gc_block);
|
||||||
user_execute_gcode('M', 115, gc_block);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -1641,7 +1638,7 @@ bool __attribute__((weak)) user_validate_gcode(char letter, uint8_t code_num, ui
|
|||||||
return false; // default is to reject all unknown numbers
|
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) {
|
bool __attribute__((weak)) user_execute_gcode(parser_block_t parser_block) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -336,4 +336,4 @@ Error gc_execute_line(char* line, uint8_t client);
|
|||||||
void gc_sync_position();
|
void gc_sync_position();
|
||||||
|
|
||||||
bool user_validate_gcode(char letter, uint8_t code_num, uint32_t &value_words);
|
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);
|
bool user_execute_gcode(parser_block_t parser_block);
|
||||||
|
Reference in New Issue
Block a user