EEQWRQEWF

Dependencies:   mbed tsi_sensor

Revision:
0:c58c860f51f3
diff -r 000000000000 -r c58c860f51f3 bluetooth.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bluetooth.cpp	Tue Sep 27 11:41:12 2022 +0000
@@ -0,0 +1,149 @@
+#include "bluetooth.h"
+
+#define startData      '$'
+#define endData         '%'
+
+Serial pc(USBTX, USBRX);
+Serial bt(PTE22, PTE23);
+
+enum{
+    standby = 0,
+    data,
+};
+
+char beb1[25] = " ", beb2[25] = " ", beb3[25] = " ", beb4[25] = " ", beb5[25] = " ", beb6[25] = " ";
+int auxBL = 0;
+char datos[100];
+
+char charRecieve = 0;
+int i=0, bebidas = 0,aux1=0,aux2=0,aux3=0,aux4=0,aux5=0,aux6=0;
+
+void bluetooth_RX(void){
+
+            charRecieve = bt.getc();
+            static int state = standby;
+            switch(state){
+            case standby:
+                if(charRecieve == startData)
+                {
+                    //pc.printf("Recibe $$\n");
+                    state = data;
+                }
+                break;
+            case data:
+                if(charRecieve == endData){
+                    //pc.printf("Recibe %%\n");
+                    pc.printf("%s\n",datos); 
+                    
+                    state = standby;
+                    auxBL=0;
+                    aux1=0;
+                    aux2=0;
+                    aux3=0;
+                    aux4=0;
+                    aux5=0;
+                    aux6=0;
+                    
+                    for(i=0; i < strlen(datos); i++){ 
+                    switch (bebidas){
+                        case 0:
+                            if(datos[i] == '#'){
+                                bebidas++;
+                                break;
+                            }
+                            else{
+                                beb1[aux1++] = datos[i];
+                            }
+                            break;
+                        case 1:
+                            if(datos[i] == '#'){
+                                bebidas++;
+                                break;
+                            }
+                            else{
+                                beb2[aux2++] = datos[i];
+                            }
+                            break;
+                        case 2:
+                            if(datos[i] == '#'){
+                                bebidas++;
+                                break;
+                            }
+                            else{
+                                beb3[aux3++] = datos[i];
+                            }
+                            break;
+                        case 3:
+                            if(datos[i] == '#'){
+                                bebidas++;
+                                break;
+                            }
+                            else{
+                                beb4[aux4++] = datos[i];
+                            }
+                            break;
+                        case 4:
+                            if(datos[i] == '#'){
+                                bebidas++;
+                                break;
+                            }
+                            else{
+                                beb5[aux5++] = datos[i];
+                            }
+                            break;
+                        case 5:
+                            if(datos[i] == '#'){
+                                bebidas=0;
+                                state = standby;
+                                
+                                break;
+                            }
+                            else{
+                                beb6[aux6++] = datos[i];
+                                
+                            }
+                            break;
+                        }
+                    
+                    }
+                    memset(datos,0,100);
+                    pc.printf("%s\n",beb1);
+                    pc.printf("%s\n",beb2);
+                    pc.printf("%s\n",beb3);
+                    pc.printf("%s\n",beb4);
+                    pc.printf("%s\n",beb5);
+                    pc.printf("%s\n",beb6);
+                    memset(beb1,0,25);
+                    memset(beb2,0,25);
+                    memset(beb3,0,25);
+                    memset(beb4,0,25);
+                    memset(beb5,0,25);
+                    memset(beb6,0,25);
+                }
+                else{
+                    datos[auxBL++] = charRecieve;
+                }
+                break;
+            }    
+}
+
+void load_simple_drink(void){
+    /*
+    strcpy(simple_drink_matrix[0], beb1);
+    strcpy(simple_drink_matrix[1], beb2);
+    strcpy(simple_drink_matrix[2], beb3);
+    strcpy(simple_drink_matrix[3], beb4);
+    strcpy(simple_drink_matrix[4], beb5);
+    strcpy(simple_drink_matrix[5], beb6);
+    */
+}
+void load_elaborated_drinks(void){
+    /*
+    strcpy(elaborated_drink_matrix[0], Ebeb1);
+    strcpy(elaborated_drink_matrix[1], Ebeb2);
+    strcpy(elaborated_drink_matrix[2], Ebeb3);
+    strcpy(elaborated_drink_matrix[3], Ebeb4);
+    strcpy(elaborated_drink_matrix[4], Ebeb5);
+    strcpy(elaborated_drink_matrix[5], Ebeb6);
+    */
+}
\ No newline at end of file