From e1554ddd863b17b53b1cf00efff89040ca56cc57 Mon Sep 17 00:00:00 2001 From: Terje Io Date: Fri, 23 Apr 2021 16:40:39 +0200 Subject: [PATCH] added HAL entry for writing single character to output stream, core event for unknown real time command (character) --- grbl.h | 2 +- hal.h | 14 +++++++++----- protocol.c | 4 ++-- stream.c | 2 +- stream.h | 14 +++++++++++++- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/grbl.h b/grbl.h index 7499b19..6026c04 100644 --- a/grbl.h +++ b/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20210408" +#define GRBL_VERSION_BUILD "20210421" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/hal.h b/hal.h index 4b85925..baa3485 100644 --- a/hal.h +++ b/hal.h @@ -73,16 +73,18 @@ typedef void (*driver_reset_ptr)(void); // I/O stream +typedef int16_t (*stream_read_ptr)(void); typedef void (*stream_write_ptr)(const char *s); +typedef bool (*stream_write_char_ptr)(const char c); typedef bool (*enqueue_realtime_command_ptr)(char data); typedef struct { stream_type_t type; uint16_t (*get_rx_buffer_available)(void); -// bool (*stream_write)(char c); - stream_write_ptr write; // write string to current I/O stream only. - stream_write_ptr write_all; // write string to all active output streams. - int16_t (*read)(void); + stream_write_ptr write; // write string to current I/O stream only. + stream_write_ptr write_all; // write string to all active output streams. + stream_write_char_ptr write_char; // write single character to current I/O stream only. + stream_read_ptr read; void (*reset_read_buffer)(void); void (*cancel_read_buffer)(void); bool (*suspend_read)(bool await); @@ -343,11 +345,12 @@ typedef void (*on_probe_completed_ptr)(void); typedef void (*on_program_completed_ptr)(program_flow_t program_flow, bool check_mode); typedef void (*on_execute_realtime_ptr)(sys_state_t state); typedef void (*on_unknown_accessory_override_ptr)(uint8_t cmd); +typedef bool (*on_unknown_realtime_cmd_ptr)(char c); typedef void (*on_report_options_ptr)(bool newopt); typedef void (*on_report_command_help_ptr)(void); typedef void (*on_global_settings_restore_ptr)(void); typedef setting_details_t *(*on_get_settings_ptr)(void); // NOTE: this must match the signature of the same definition in - // the setting_details_t structure in settings.h! + // the setting_details_t structure in settings.h! typedef void (*on_realtime_report_ptr)(stream_write_ptr stream_write, report_tracking_flags_t report); typedef void (*on_unknown_feedback_message_ptr)(stream_write_ptr stream_write); typedef bool (*on_laser_ppi_enable_ptr)(uint_fast16_t ppi, uint_fast16_t pulse_length); @@ -370,6 +373,7 @@ typedef struct { on_get_settings_ptr on_get_settings; on_realtime_report_ptr on_realtime_report; on_unknown_feedback_message_ptr on_unknown_feedback_message; + on_unknown_realtime_cmd_ptr on_unknown_realtime_cmd; on_unknown_sys_command_ptr on_unknown_sys_command; // return Status_Unhandled if not handled. on_get_commands_ptr on_get_commands; on_user_command_ptr on_user_command; diff --git a/protocol.c b/protocol.c index a15f70e..b67b0c0 100644 --- a/protocol.c +++ b/protocol.c @@ -855,13 +855,13 @@ ISR_CODE bool protocol_enqueue_realtime_command (char c) default: if(c < ' ' || (c >= 0x7F && c <= 0xBF)) - drop = true; + drop = grbl.on_unknown_realtime_cmd == NULL || grbl.on_unknown_realtime_cmd(c); break; } // 2. Process printable ASCII characters and top-bit set characters // If legacy realtime commands are disabled they are returned to the input stream - // when appering in settings ($ commands) or comments + // when appearing in settings ($ commands) or comments if(!drop) switch ((unsigned char)c) { diff --git a/stream.c b/stream.c index ba9b604..da86fe6 100644 --- a/stream.c +++ b/stream.c @@ -26,7 +26,7 @@ static stream_rx_buffer_t rxbackup; // "dummy" version of serialGetC -static int16_t stream_get_null (void) +int16_t stream_get_null (void) { return SERIAL_NO_DATA; } diff --git a/stream.h b/stream.h index 07e62c0..f89270c 100644 --- a/stream.h +++ b/stream.h @@ -3,7 +3,7 @@ Part of grblHAL - Copyright (c) 2019-2020 Terje Io + Copyright (c) 2019-2021 Terje Io Grbl is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,7 +22,10 @@ #ifndef _STREAM_H_ #define _STREAM_H_ +#define ASCII_SOH 0x01 +#define ASCII_STX 0x02 #define ASCII_ETX 0x03 +#define ASCII_EOT 0x04 #define ASCII_ACK 0x06 #define ASCII_BS 0x08 #define ASCII_TAB 0x09 @@ -104,7 +107,16 @@ typedef struct { char data[BLOCK_TX_BUFFER_SIZE]; } stream_block_tx_buffer_t; +#ifdef __cplusplus +extern "C" { +#endif + +int16_t stream_get_null (void); bool stream_rx_suspend (stream_rx_buffer_t *rxbuffer, bool suspend); void stream_rx_backup (stream_rx_buffer_t *rxbuffer); +#ifdef __cplusplus +} +#endif + #endif