SNE S1/S2 prime
/
Nucleo446RE_echo_circular_buffer
Echo buffer circulaire
Diff: main.cpp
- Revision:
- 10:8895b56c630c
- Parent:
- 9:a9dfb95b5d8a
--- a/main.cpp Sun Nov 22 15:15:15 2020 +0000 +++ b/main.cpp Mon Nov 23 22:19:13 2020 +0000 @@ -1,27 +1,33 @@ #include "mbed.h" -// Echo +// Echo avec buffer circulaire // lien serie via USB avec Terarerm -// GR 2020 // Universite Paris-Saclay - IUT Cachan RawSerial pc_raw(USBTX, USBRX); // ou SERIAL-TX, SERIAL_RX ou PA_2,PA_3 +CircularBuffer < char, 1024> mon_buffer; // buffer circulaire de 1024 char DigitalOut ledB(D8); void reception_symbole(void); int main() { + char symbole; pc_raw.baud(115200); pc_raw.attach(&reception_symbole); - pc_raw.printf("Echo test\r\n"); + pc_raw.printf("Echo test buffer circulaire\r\n"); ledB=0; + mon_buffer.reset(); while(1) { + while(!mon_buffer.empty()) { + mon_buffer.pop(symbole); + pc_raw.putc(symbole); + } } } void reception_symbole(void) { - unsigned char c; + char symbole; if(pc_raw.readable()) { ledB=!ledB; - c=pc_raw.getc(); - pc_raw.putc(c); + symbole=pc_raw.getc(); + mon_buffer.push(symbole); } }