From 1d86f200fa12369f8c8cb548dc3d4c6ef784faa8 Mon Sep 17 00:00:00 2001 From: bdring Date: Wed, 10 Mar 2021 16:42:36 -0600 Subject: [PATCH] WIP --- Grbl_Esp32/Custom/user_gcode_example.cpp | 76 +++++++++++++++++------- Grbl_Esp32/src/GCode.cpp | 9 +-- Grbl_Esp32/src/GCode.h | 2 +- 3 files changed, 59 insertions(+), 28 deletions(-) diff --git a/Grbl_Esp32/Custom/user_gcode_example.cpp b/Grbl_Esp32/Custom/user_gcode_example.cpp index 8767f725..298db517 100644 --- a/Grbl_Esp32/Custom/user_gcode_example.cpp +++ b/Grbl_Esp32/Custom/user_gcode_example.cpp @@ -1,35 +1,69 @@ +/* + user_gcode_example.cpp -// value_words - Tells the parser what value words are required -bool user_validate_gcode(char letter, uint8_t code_num, uint32_t &value_words) { - grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Testing gcode"); + Copyright (c) 2021 Barton Dring @buildlog - if (letter == 'G') { - return false; - } else if (letter == 'M') { - switch (code_num) { + Used to add simple G or M codes to the firmware + If in doubt use an M code + + 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: - bit_true(value_words, bit(GCodeWord::E)); - + //bit_true(value_words, bit(GCodeWord::E)); (not used, just here an an example) return true; - break; default: - return false; break; } - - } else { - return false; // default is to reject all unknown numbers } + + current_letter = '\0'; + current_code_num = 0; + + return false; } -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); +/* + 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; break; default: diff --git a/Grbl_Esp32/src/GCode.cpp b/Grbl_Esp32/src/GCode.cpp index aab043b9..c3889b26 100644 --- a/Grbl_Esp32/src/GCode.cpp +++ b/Grbl_Esp32/src/GCode.cpp @@ -1274,8 +1274,7 @@ Error gc_execute_line(char* line, uint8_t client) { bit(GCodeWord::C))); // Remove axis words. } if (gc_block.non_modal_command == NonModal::UserDefinedGcode) { - // clean up words - grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Cleanup: %d %d", value_words, user_value_words); + // Clean up value word from user gcode checking bit_false(value_words, user_value_words); } if (value_words) { @@ -1522,9 +1521,7 @@ Error gc_execute_line(char* line, uint8_t client) { 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); - + user_execute_gcode(gc_block); break; default: 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 } -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; } diff --git a/Grbl_Esp32/src/GCode.h b/Grbl_Esp32/src/GCode.h index 587b3e94..ca7815e5 100644 --- a/Grbl_Esp32/src/GCode.h +++ b/Grbl_Esp32/src/GCode.h @@ -336,4 +336,4 @@ Error gc_execute_line(char* line, uint8_t client); 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); +bool user_execute_gcode(parser_block_t parser_block);