Allow TABS in config
[clinton/Smoothieware.git] / src / modules / communication / SerialConsole.cpp
index 4c33262..301937d 100644 (file)
@@ -15,6 +15,7 @@ using std::string;
 #include "libs/RingBuffer.h"
 #include "libs/SerialMessage.h"
 #include "libs/StreamOutput.h"
+#include "libs/StreamOutputPool.h"
 
 // Serial reading module
 // Treats every received line as a command and passes it ( via event call ) to the command dispatcher.
@@ -33,9 +34,9 @@ void SerialConsole::on_module_loaded() {
     this->register_for_event(ON_MAIN_LOOP);
 
     // Add to the pack of streams kernel can call to, for example for broadcasting
-    this->kernel->streams->append_stream(this);
+    THEKERNEL->streams->append_stream(this);
 }
-        
+
 // Called on Serial::RxIrq interrupt, meaning we have received a char
 void SerialConsole::on_serial_char_received(){
     while(this->serial->readable()){
@@ -45,11 +46,12 @@ void SerialConsole::on_serial_char_received(){
         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') ){
         string received;
+        received.reserve(20);
         while(1){
            char c;
            this->buffer.pop_front(c);
@@ -57,7 +59,7 @@ void SerialConsole::on_main_loop(void * argument){
                 struct SerialMessage message;
                 message.message = received;
                 message.stream = this;
-                this->kernel->call_event(ON_CONSOLE_LINE_RECEIVED, &message );
+                THEKERNEL->call_event(ON_CONSOLE_LINE_RECEIVED, &message );
                 return;
             }else{
                 received += c;
@@ -67,19 +69,25 @@ void SerialConsole::on_main_loop(void * argument){
 }
 
 
-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));
 }
 
+int SerialConsole::_putc(int c)
+{
+    return this->serial->putc(c);
+}
+
+int SerialConsole::_getc()
+{
+    return this->serial->getc();
+}
 
+// Does the queue have a given char ?
 bool SerialConsole::has_char(char letter){
-    int index = this->buffer.head;
-    while( index != this->buffer.tail ){
+    int index = this->buffer.tail;
+    while( index != this->buffer.head ){
         if( this->buffer.buffer[index] == letter ){
             return true;
         }