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
RawSerialPc.cpp@0:ab6e0939a63f, 2015-12-19 (annotated)
- Committer:
- jcabello7
- Date:
- Sat Dec 19 01:09:28 2015 +0000
- Revision:
- 0:ab6e0939a63f
Programa final, fent servir les llibreries RTOS, amb les llibreries RawSerialPc i Hc05 separades per facilitar la modificaci? del programa. Comprovat que funciona.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jcabello7 | 0:ab6e0939a63f | 1 | #include "RawSerialPc.h" |
| jcabello7 | 0:ab6e0939a63f | 2 | #include "mbed.h" |
| jcabello7 | 0:ab6e0939a63f | 3 | |
| jcabello7 | 0:ab6e0939a63f | 4 | |
| jcabello7 | 0:ab6e0939a63f | 5 | RawSerialPc::RawSerialPc(PinName tx, PinName rx) : RawSerial(tx, rx){ |
| jcabello7 | 0:ab6e0939a63f | 6 | baud(115200); |
| jcabello7 | 0:ab6e0939a63f | 7 | }; |
| jcabello7 | 0:ab6e0939a63f | 8 | |
| jcabello7 | 0:ab6e0939a63f | 9 | void RawSerialPc::enviaString(char* str){ |
| jcabello7 | 0:ab6e0939a63f | 10 | int i = 0; |
| jcabello7 | 0:ab6e0939a63f | 11 | while((i < longString) && (str[i] != '\0')) { |
| jcabello7 | 0:ab6e0939a63f | 12 | putc(str[i]); |
| jcabello7 | 0:ab6e0939a63f | 13 | i++; |
| jcabello7 | 0:ab6e0939a63f | 14 | } |
| jcabello7 | 0:ab6e0939a63f | 15 | putc(10); |
| jcabello7 | 0:ab6e0939a63f | 16 | }; |
| jcabello7 | 0:ab6e0939a63f | 17 | |
| jcabello7 | 0:ab6e0939a63f | 18 | bool RawSerialPc::llegirString(char* str){ |
| jcabello7 | 0:ab6e0939a63f | 19 | if(readable()){ |
| jcabello7 | 0:ab6e0939a63f | 20 | int i= 0; |
| jcabello7 | 0:ab6e0939a63f | 21 | str[i] = getc(); |
| jcabello7 | 0:ab6e0939a63f | 22 | while((i < longString) && (str[i] != 13)) { |
| jcabello7 | 0:ab6e0939a63f | 23 | if (str[i] != '@') |
| jcabello7 | 0:ab6e0939a63f | 24 | i++; |
| jcabello7 | 0:ab6e0939a63f | 25 | str[i] = getc(); |
| jcabello7 | 0:ab6e0939a63f | 26 | } |
| jcabello7 | 0:ab6e0939a63f | 27 | str[i] = '\0'; |
| jcabello7 | 0:ab6e0939a63f | 28 | return true; |
| jcabello7 | 0:ab6e0939a63f | 29 | } |
| jcabello7 | 0:ab6e0939a63f | 30 | return false; |
| jcabello7 | 0:ab6e0939a63f | 31 | }; |