#include "libs/RingBuffer.h"
#include "libs/SerialMessage.h"
#include "libs/StreamOutput.h"
#include "libs/RingBuffer.h"
#include "libs/SerialMessage.h"
#include "libs/StreamOutput.h"
void SerialConsole::on_module_loaded() {
// We want to be called every time a new char is received
this->serial->attach(this, &SerialConsole::on_serial_char_received, mbed::Serial::RxIrq);
void SerialConsole::on_module_loaded() {
// We want to be called every time a new char is received
this->serial->attach(this, &SerialConsole::on_serial_char_received, mbed::Serial::RxIrq);
// 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(){
while(this->serial->readable()){
char received = this->serial->getc();
}
// Called on Serial::RxIrq interrupt, meaning we have received a char
void SerialConsole::on_serial_char_received(){
while(this->serial->readable()){
char received = this->serial->getc();
// convert CR to NL (for host OSs that don't send NL)
if( received == '\r' ){ received = '\n'; }
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') ){
- return fwrite(s, strlen(s), 1, (FILE*)this->serial);
+ return fwrite(s, strlen(s), 1, (FILE*)(*this->serial));