This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
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.
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.
This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
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.
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.
#include "libs/RingBuffer.h"
#include "libs/SerialMessage.h"
#include "libs/StreamOutput.h"
#include "libs/RingBuffer.h"
#include "libs/SerialMessage.h"
#include "libs/StreamOutput.h"
// The command dispatcher will then ask other modules if they can do something with it
SerialConsole::SerialConsole( PinName rx_pin, PinName tx_pin, int baud_rate ){
this->serial = new mbed::Serial( rx_pin, tx_pin );
this->serial->baud(baud_rate);
// The command dispatcher will then ask other modules if they can do something with it
SerialConsole::SerialConsole( PinName rx_pin, PinName tx_pin, int baud_rate ){
this->serial = new mbed::Serial( rx_pin, tx_pin );
this->serial->baud(baud_rate);
// We only call the command dispatcher in the main loop, nowhere else
this->register_for_event(ON_MAIN_LOOP);
// We only call the command dispatcher in the main loop, nowhere else
this->register_for_event(ON_MAIN_LOOP);
// Called on Serial::RxIrq interrupt, meaning we have received a char
void SerialConsole::on_serial_char_received(){
// Called on Serial::RxIrq interrupt, meaning we have received a char
void SerialConsole::on_serial_char_received(){
- //On newline, we have received a line, else concatenate in buffer
- if( received == '\r' ){ return; }
- this->buffer.push_back(received);
+ // convert CR to NL (for host OSs that don't send NL)
+ if( received == '\r' ){ received = '\n'; }
+ this->buffer.push_back(received);
// Actual event calling must happen in the main loop because if it happens in the interrupt we will loose data
void SerialConsole::on_main_loop(void * argument){
if( this->has_char('\n') ){
// Actual event calling must happen in the main loop because if it happens in the interrupt we will loose data
void SerialConsole::on_main_loop(void * argument){
if( this->has_char('\n') ){
-int SerialConsole::printf(const char* format, ...){
- va_list args;
- int result;
- va_start (args, format);
- result = vfprintf( this->serial->_file, format, args);
- va_end (args);
- return result;
+int SerialConsole::puts(const char* s)
+{
+ return fwrite(s, strlen(s), 1, (FILE*)(*this->serial));