| 1 | /* |
| 2 | This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl). |
| 3 | Smoothie 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. |
| 4 | Smoothie 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. |
| 5 | You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SERIALCONSOLE_H |
| 9 | #define SERIALCONSOLE_H |
| 10 | |
| 11 | #include "libs/Module.h" |
| 12 | #include "Serial.h" // mbed.h lib |
| 13 | #include "libs/Kernel.h" |
| 14 | #include <vector> |
| 15 | #include <string> |
| 16 | using std::string; |
| 17 | #include "libs/RingBuffer.h" |
| 18 | #include "libs/StreamOutput.h" |
| 19 | |
| 20 | |
| 21 | #define baud_rate_setting_checksum CHECKSUM("baud_rate") |
| 22 | |
| 23 | class SerialConsole : public Module, public StreamOutput { |
| 24 | public: |
| 25 | SerialConsole( PinName rx_pin, PinName tx_pin, int baud_rate ); |
| 26 | |
| 27 | void on_module_loaded(); |
| 28 | void on_serial_char_received(); |
| 29 | void on_main_loop(void * argument); |
| 30 | void on_idle(void * argument); |
| 31 | bool has_char(char letter); |
| 32 | |
| 33 | int _putc(int c); |
| 34 | int _getc(void); |
| 35 | int puts(const char*); |
| 36 | |
| 37 | //string receive_buffer; // Received chars are stored here until a newline character is received |
| 38 | //vector<std::string> received_lines; // Received lines are stored here until they are requested |
| 39 | RingBuffer<char,256> buffer; // Receive buffer |
| 40 | mbed::Serial* serial; |
| 41 | struct { |
| 42 | bool query_flag:1; |
| 43 | bool halt_flag:1; |
| 44 | }; |
| 45 | }; |
| 46 | |
| 47 | #endif |