Llibreria per connectar via sèrie amb un PC, que permet enviar i rebre strings sense fer servir les funcions scanf i printf que no són compatibles amb la llibreria RTOS.

Dependents:   projecte_v4_rtos ProjecteRobotFinal

Files at this revision

API Documentation at this revision

Comitter:
jcabello7
Date:
Sat Dec 19 01:09:28 2015 +0000
Commit message:
Programa final, fent servir les llibreries RTOS, amb les llibreries RawSerialPc i Hc05 separades per facilitar la modificaci? del programa. Comprovat que funciona.

Changed in this revision

RawSerialPc.cpp Show annotated file Show diff for this revision Revisions of this file
RawSerialPc.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r ab6e0939a63f RawSerialPc.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RawSerialPc.cpp	Sat Dec 19 01:09:28 2015 +0000
@@ -0,0 +1,31 @@
+#include "RawSerialPc.h"
+#include "mbed.h"
+
+
+        RawSerialPc::RawSerialPc(PinName tx, PinName rx) : RawSerial(tx, rx){
+            baud(115200);
+        };
+            
+        void RawSerialPc::enviaString(char* str){
+            int i = 0;
+            while((i < longString) && (str[i] != '\0')) {
+                putc(str[i]);
+                i++;
+            }
+            putc(10);
+        };
+        
+        bool RawSerialPc::llegirString(char* str){
+            if(readable()){
+                int i= 0;
+                str[i] = getc();
+                while((i < longString) && (str[i] != 13)) {                    
+                    if (str[i] != '@')
+                        i++;
+                    str[i] = getc();
+                }
+                str[i] = '\0';
+                return true;           
+            }
+            return false;
+        };
\ No newline at end of file
diff -r 000000000000 -r ab6e0939a63f RawSerialPc.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RawSerialPc.h	Sat Dec 19 01:09:28 2015 +0000
@@ -0,0 +1,16 @@
+#ifndef MBED_RAWSERIALPC_H
+#define MBED_RAWSERIALPC_H
+
+#include "mbed.h"
+
+#define longString 128 //Longitud màxima del string a enviar
+
+class RawSerialPc : public RawSerial {
+    public:
+        RawSerialPc(PinName tx, PinName rx);
+        void enviaString(char* str);
+        bool llegirString(char* str); 
+ };
+
+
+#endif
\ No newline at end of file