x
Dependencies: mbed ihm_L476_full
main.cpp@1:ecfc0ff62c52, 2020-05-15 (annotated)
- Committer:
- gr91
- Date:
- Fri May 15 15:05:52 2020 +0000
- Revision:
- 1:ecfc0ff62c52
- Parent:
- 0:ec600fef44bc
V1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gr91 | 0:ec600fef44bc | 1 | //#include "mbed.h" |
gr91 | 0:ec600fef44bc | 2 | #include "ihm_L476.h" |
gr91 | 0:ec600fef44bc | 3 | #define PI 3.14f |
gr91 | 0:ec600fef44bc | 4 | Serial pc(SERIAL_TX, SERIAL_RX); |
gr91 | 0:ec600fef44bc | 5 | CircularBuffer <unsigned char,1024> buf; |
gr91 | 0:ec600fef44bc | 6 | DigitalOut led1(LED1); |
gr91 | 0:ec600fef44bc | 7 | DigitalOut led2(LED2); |
gr91 | 0:ec600fef44bc | 8 | IHM_L476 ihm; |
gr91 | 0:ec600fef44bc | 9 | |
gr91 | 0:ec600fef44bc | 10 | void serial_receive() |
gr91 | 0:ec600fef44bc | 11 | { |
gr91 | 0:ec600fef44bc | 12 | unsigned char c=pc.getc(); // attention à protéger les appels pc |
gr91 | 0:ec600fef44bc | 13 | buf.push(c); |
gr91 | 0:ec600fef44bc | 14 | } |
gr91 | 0:ec600fef44bc | 15 | // |
gr91 | 0:ec600fef44bc | 16 | int main() |
gr91 | 0:ec600fef44bc | 17 | { |
gr91 | 0:ec600fef44bc | 18 | char l1,l2; |
gr91 | 0:ec600fef44bc | 19 | pc.baud(9600); |
gr91 | 0:ec600fef44bc | 20 | pc.printf("Hello World !\n"); |
gr91 | 0:ec600fef44bc | 21 | pc.attach(&serial_receive); // isr sur reception char |
gr91 | 0:ec600fef44bc | 22 | float f=10; |
gr91 | 0:ec600fef44bc | 23 | int j=0; |
gr91 | 0:ec600fef44bc | 24 | char str[20]; |
gr91 | 0:ec600fef44bc | 25 | while(1) { |
gr91 | 0:ec600fef44bc | 26 | while(!buf.empty()) { |
gr91 | 0:ec600fef44bc | 27 | unsigned char c; |
gr91 | 0:ec600fef44bc | 28 | buf.pop(c); |
gr91 | 0:ec600fef44bc | 29 | switch(c) { |
gr91 | 0:ec600fef44bc | 30 | case '\r' : // fin de message on traite |
gr91 | 0:ec600fef44bc | 31 | str[j]=NULL; // fin de chaine |
gr91 | 0:ec600fef44bc | 32 | j=0; |
gr91 | 0:ec600fef44bc | 33 | // debut traitement chaine recue |
gr91 | 0:ec600fef44bc | 34 | sscanf(str,"%d %d %f",&l1,&l2,&f); |
gr91 | 0:ec600fef44bc | 35 | led1=l1; |
gr91 | 0:ec600fef44bc | 36 | led2=l2; |
gr91 | 0:ec600fef44bc | 37 | ihm.LCD_printf("%f",f); |
gr91 | 0:ec600fef44bc | 38 | // fin traitement chaine recue |
gr91 | 0:ec600fef44bc | 39 | break; |
gr91 | 0:ec600fef44bc | 40 | case '\n': // on ignore |
gr91 | 0:ec600fef44bc | 41 | break; |
gr91 | 0:ec600fef44bc | 42 | default : // on stocke |
gr91 | 0:ec600fef44bc | 43 | str[j]=c; |
gr91 | 0:ec600fef44bc | 44 | j++; |
gr91 | 0:ec600fef44bc | 45 | } |
gr91 | 0:ec600fef44bc | 46 | } |
gr91 | 0:ec600fef44bc | 47 | } |
gr91 | 0:ec600fef44bc | 48 | } |