/* report.c - reporting and messaging methods Part of Grbl Copyright (c) 2012 Sungeun K. Jeon Grbl is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Grbl is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Grbl. If not, see . */ /* This file functions as the primary feedback interface for Grbl. Any outgoing data, such as the protocol status messages, feedback messages, and status reports, are stored here. For the most part, these functions primarily are called from protocol.c methods. If a different style feedback is desired (i.e. JSON), then a user can change these following methods to accomodate their needs. */ #include #include "report.h" #include "print.h" #include "settings.h" #include "nuts_bolts.h" #include "gcode.h" #include "coolant_control.h" // Handles the primary confirmation protocol response for streaming interfaces and human-feedback. // For every incoming line, this method responds with an 'ok' for a successful command or an // 'error:' to indicate some error event with the line or some critical system error during // operation. Errors events can originate from the g-code parser, settings module, or asynchronously // from a critical error, such as a triggered hard limit. Interface should always monitor for these // responses. // NOTE: In silent mode, all error codes are greater than zero. // TODO: Install silent mode to return only numeric values, primarily for GUIs. void report_status_message(uint8_t status_code) { if (status_code == 0) { // STATUS_OK printPgmString(PSTR("ok\r\n")); } else { printPgmString(PSTR("error: ")); switch(status_code) { case STATUS_BAD_NUMBER_FORMAT: printPgmString(PSTR("Bad number format")); break; case STATUS_EXPECTED_COMMAND_LETTER: printPgmString(PSTR("Expected command letter")); break; case STATUS_UNSUPPORTED_STATEMENT: printPgmString(PSTR("Unsupported statement")); break; case STATUS_ARC_RADIUS_ERROR: printPgmString(PSTR("Invalid radius")); break; case STATUS_MODAL_GROUP_VIOLATION: printPgmString(PSTR("Modal group violation")); break; case STATUS_INVALID_STATEMENT: printPgmString(PSTR("Invalid statement")); break; case STATUS_HARD_LIMIT: printPgmString(PSTR("Hard limit. MPos lost?")); break; case STATUS_SETTING_DISABLED: printPgmString(PSTR("Setting disabled")); break; case STATUS_SETTING_VALUE_NEG: printPgmString(PSTR("Value < 0.0")); break; case STATUS_SETTING_STEP_PULSE_MIN: printPgmString(PSTR("Value < 3 usec")); break; case STATUS_SETTING_READ_FAIL: printPgmString(PSTR("EEPROM read fail. Using defaults")); break; case STATUS_IDLE_ERROR: printPgmString(PSTR("Busy or locked")); break; case STATUS_ABORT_CYCLE: printPgmString(PSTR("Abort during cycle. MPos lost?")); break; case STATUS_HOMING_LOCK: printPgmString(PSTR("Locked until homed")); break; } printPgmString(PSTR("\r\n")); } } // Prints feedback messages. This serves as a centralized method to provide additional // user feedback for things that are not of the status message response protocol. These // are messages such as setup warnings and how to exit alarms. // NOTE: For interfaces, messages are always placed within brackets. And if silent mode // is installed, the message number codes are less than zero. // TODO: Install silence feedback messages option in settings void report_feedback_message(int8_t message_code) { printPgmString(PSTR("[")); switch(message_code) { case MESSAGE_CRITICAL_EVENT: printPgmString(PSTR("ALARM: Check and reset")); break; case MESSAGE_HOMING_ALARM: printPgmString(PSTR("'$H' to home and unlock")); break; case MESSAGE_ENABLED: printPgmString(PSTR("Enabled")); break; case MESSAGE_DISABLED: printPgmString(PSTR("Disabled")); break; case MESSAGE_HOMING_UNLOCK: printPgmString(PSTR("Unlocked. MPos lost?")); break; } printPgmString(PSTR("]\r\n")); } // Welcome message void report_init_message() { printPgmString(PSTR("\r\nGrbl " GRBL_VERSION " ['$' for help]\r\n")); } // Grbl help message void report_grbl_help() { printPgmString(PSTR("$$ (view Grbl settings)\r\n" "$# (view # parameters)\r\n" "$G (view parser state)\r\n" "$N (view startup blocks)\r\n" "$x=value (save Grbl setting)\r\n" "$Nx=line (save startup block)\r\n" "$S0 (toggle check gcode)\r\n" "$S1 (toggle blk del)\r\n" "$S2 (toggle single blk)\r\n" "$S3 (toggle opt stop)\r\n" "$X (kill homing lock)\r\n" "$H (run homing cycle)\r\n" "~ (cycle start)\r\n" "! (feed hold)\r\n" "? (position)\r\n" "ctrl-x (reset Grbl)\r\n")); } // Grbl global settings print out. // NOTE: The numbering scheme here must correlate to storing in settings.c void report_grbl_settings() { printPgmString(PSTR("$0=")); printFloat(settings.steps_per_mm[X_AXIS]); printPgmString(PSTR(" (x, step/mm)\r\n$1=")); printFloat(settings.steps_per_mm[Y_AXIS]); printPgmString(PSTR(" (y, step/mm)\r\n$2=")); printFloat(settings.steps_per_mm[Z_AXIS]); printPgmString(PSTR(" (z, step/mm)\r\n$3=")); printInteger(settings.pulse_microseconds); printPgmString(PSTR(" (step pulse, usec)\r\n$4=")); printFloat(settings.default_feed_rate); printPgmString(PSTR(" (default feed, mm/min)\r\n$5=")); printFloat(settings.default_seek_rate); printPgmString(PSTR(" (default seek, mm/min)\r\n$6=")); printInteger(settings.invert_mask); printPgmString(PSTR(" (step port invert mask, int:")); print_uint8_base2(settings.invert_mask); printPgmString(PSTR(")\r\n$7=")); printInteger(settings.stepper_idle_lock_time); printPgmString(PSTR(" (step idle delay, msec)\r\n$8=")); printFloat(settings.acceleration/(60*60)); // Convert from mm/min^2 for human readability printPgmString(PSTR(" (acceleration, mm/sec^2)\r\n$9=")); printFloat(settings.junction_deviation); printPgmString(PSTR(" (junction deviation, mm)\r\n$10=")); printFloat(settings.mm_per_arc_segment); printPgmString(PSTR(" (arc, mm/segment)\r\n$11=")); printInteger(settings.n_arc_correction); printPgmString(PSTR(" (n-arc correction, int)\r\n$12=")); printInteger(settings.decimal_places); printPgmString(PSTR(" (n-decimals, int)\r\n$13=")); printInteger(bit_istrue(settings.flags,BITFLAG_REPORT_INCHES)); printPgmString(PSTR(" (report inches, bool)\r\n$14=")); printInteger(bit_istrue(settings.flags,BITFLAG_AUTO_START)); printPgmString(PSTR(" (auto start, bool)\r\n$15=")); printInteger(bit_istrue(settings.flags,BITFLAG_INVERT_ST_ENABLE)); printPgmString(PSTR(" (invert step enable, bool)\r\n$16=")); printInteger(bit_istrue(settings.flags,BITFLAG_HARD_LIMIT_ENABLE)); printPgmString(PSTR(" (hard limits, bool)\r\n$17=")); printInteger(bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)); printPgmString(PSTR(" (homing cycle, bool)\r\n$18=")); printInteger(settings.homing_dir_mask); printPgmString(PSTR(" (homing dir invert mask, int:")); print_uint8_base2(settings.homing_dir_mask); printPgmString(PSTR(")\r\n$19=")); printFloat(settings.homing_feed_rate); printPgmString(PSTR(" (homing feed, mm/min)\r\n$20=")); printFloat(settings.homing_seek_rate); printPgmString(PSTR(" (homing seek, mm/min)\r\n$21=")); printInteger(settings.homing_debounce_delay); printPgmString(PSTR(" (homing debounce, msec)\r\n$22=")); printFloat(settings.homing_pulloff); printPgmString(PSTR(" (homing pull-off, mm)\r\n")); } // Prints gcode coordinate offset parameters void report_gcode_parameters() { float coord_data[N_AXIS]; uint8_t coord_select, i; for (coord_select = 0; coord_select <= SETTING_INDEX_NCOORD; coord_select++) { if (!(settings_read_coord_data(coord_select,coord_data))) { report_status_message(STATUS_SETTING_READ_FAIL); return; } switch (coord_select) { case 0: printPgmString(PSTR("G54")); break; case 1: printPgmString(PSTR("G55")); break; case 2: printPgmString(PSTR("G56")); break; case 3: printPgmString(PSTR("G57")); break; case 4: printPgmString(PSTR("G58")); break; case 5: printPgmString(PSTR("G59")); break; case 6: printPgmString(PSTR("G28")); break; case 7: printPgmString(PSTR("G30")); break; // case 8: printPgmString(PSTR("G92")); break; // G92.2, G92.3 not supported. Hence not stored. } printPgmString(PSTR(":[")); for (i=0; i