EEQWRQEWF

Dependencies:   mbed tsi_sensor

Committer:
manzi
Date:
Tue Sep 27 11:41:12 2022 +0000
Revision:
0:c58c860f51f3
RENZO BOBI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manzi 0:c58c860f51f3 1 #include "bluetooth.h"
manzi 0:c58c860f51f3 2
manzi 0:c58c860f51f3 3 #define startData '$'
manzi 0:c58c860f51f3 4 #define endData '%'
manzi 0:c58c860f51f3 5
manzi 0:c58c860f51f3 6 Serial pc(USBTX, USBRX);
manzi 0:c58c860f51f3 7 Serial bt(PTE22, PTE23);
manzi 0:c58c860f51f3 8
manzi 0:c58c860f51f3 9 enum{
manzi 0:c58c860f51f3 10 standby = 0,
manzi 0:c58c860f51f3 11 data,
manzi 0:c58c860f51f3 12 };
manzi 0:c58c860f51f3 13
manzi 0:c58c860f51f3 14 char beb1[25] = " ", beb2[25] = " ", beb3[25] = " ", beb4[25] = " ", beb5[25] = " ", beb6[25] = " ";
manzi 0:c58c860f51f3 15 int auxBL = 0;
manzi 0:c58c860f51f3 16 char datos[100];
manzi 0:c58c860f51f3 17
manzi 0:c58c860f51f3 18 char charRecieve = 0;
manzi 0:c58c860f51f3 19 int i=0, bebidas = 0,aux1=0,aux2=0,aux3=0,aux4=0,aux5=0,aux6=0;
manzi 0:c58c860f51f3 20
manzi 0:c58c860f51f3 21 void bluetooth_RX(void){
manzi 0:c58c860f51f3 22
manzi 0:c58c860f51f3 23 charRecieve = bt.getc();
manzi 0:c58c860f51f3 24 static int state = standby;
manzi 0:c58c860f51f3 25 switch(state){
manzi 0:c58c860f51f3 26 case standby:
manzi 0:c58c860f51f3 27 if(charRecieve == startData)
manzi 0:c58c860f51f3 28 {
manzi 0:c58c860f51f3 29 //pc.printf("Recibe $$\n");
manzi 0:c58c860f51f3 30 state = data;
manzi 0:c58c860f51f3 31 }
manzi 0:c58c860f51f3 32 break;
manzi 0:c58c860f51f3 33 case data:
manzi 0:c58c860f51f3 34 if(charRecieve == endData){
manzi 0:c58c860f51f3 35 //pc.printf("Recibe %%\n");
manzi 0:c58c860f51f3 36 pc.printf("%s\n",datos);
manzi 0:c58c860f51f3 37
manzi 0:c58c860f51f3 38 state = standby;
manzi 0:c58c860f51f3 39 auxBL=0;
manzi 0:c58c860f51f3 40 aux1=0;
manzi 0:c58c860f51f3 41 aux2=0;
manzi 0:c58c860f51f3 42 aux3=0;
manzi 0:c58c860f51f3 43 aux4=0;
manzi 0:c58c860f51f3 44 aux5=0;
manzi 0:c58c860f51f3 45 aux6=0;
manzi 0:c58c860f51f3 46
manzi 0:c58c860f51f3 47 for(i=0; i < strlen(datos); i++){
manzi 0:c58c860f51f3 48 switch (bebidas){
manzi 0:c58c860f51f3 49 case 0:
manzi 0:c58c860f51f3 50 if(datos[i] == '#'){
manzi 0:c58c860f51f3 51 bebidas++;
manzi 0:c58c860f51f3 52 break;
manzi 0:c58c860f51f3 53 }
manzi 0:c58c860f51f3 54 else{
manzi 0:c58c860f51f3 55 beb1[aux1++] = datos[i];
manzi 0:c58c860f51f3 56 }
manzi 0:c58c860f51f3 57 break;
manzi 0:c58c860f51f3 58 case 1:
manzi 0:c58c860f51f3 59 if(datos[i] == '#'){
manzi 0:c58c860f51f3 60 bebidas++;
manzi 0:c58c860f51f3 61 break;
manzi 0:c58c860f51f3 62 }
manzi 0:c58c860f51f3 63 else{
manzi 0:c58c860f51f3 64 beb2[aux2++] = datos[i];
manzi 0:c58c860f51f3 65 }
manzi 0:c58c860f51f3 66 break;
manzi 0:c58c860f51f3 67 case 2:
manzi 0:c58c860f51f3 68 if(datos[i] == '#'){
manzi 0:c58c860f51f3 69 bebidas++;
manzi 0:c58c860f51f3 70 break;
manzi 0:c58c860f51f3 71 }
manzi 0:c58c860f51f3 72 else{
manzi 0:c58c860f51f3 73 beb3[aux3++] = datos[i];
manzi 0:c58c860f51f3 74 }
manzi 0:c58c860f51f3 75 break;
manzi 0:c58c860f51f3 76 case 3:
manzi 0:c58c860f51f3 77 if(datos[i] == '#'){
manzi 0:c58c860f51f3 78 bebidas++;
manzi 0:c58c860f51f3 79 break;
manzi 0:c58c860f51f3 80 }
manzi 0:c58c860f51f3 81 else{
manzi 0:c58c860f51f3 82 beb4[aux4++] = datos[i];
manzi 0:c58c860f51f3 83 }
manzi 0:c58c860f51f3 84 break;
manzi 0:c58c860f51f3 85 case 4:
manzi 0:c58c860f51f3 86 if(datos[i] == '#'){
manzi 0:c58c860f51f3 87 bebidas++;
manzi 0:c58c860f51f3 88 break;
manzi 0:c58c860f51f3 89 }
manzi 0:c58c860f51f3 90 else{
manzi 0:c58c860f51f3 91 beb5[aux5++] = datos[i];
manzi 0:c58c860f51f3 92 }
manzi 0:c58c860f51f3 93 break;
manzi 0:c58c860f51f3 94 case 5:
manzi 0:c58c860f51f3 95 if(datos[i] == '#'){
manzi 0:c58c860f51f3 96 bebidas=0;
manzi 0:c58c860f51f3 97 state = standby;
manzi 0:c58c860f51f3 98
manzi 0:c58c860f51f3 99 break;
manzi 0:c58c860f51f3 100 }
manzi 0:c58c860f51f3 101 else{
manzi 0:c58c860f51f3 102 beb6[aux6++] = datos[i];
manzi 0:c58c860f51f3 103
manzi 0:c58c860f51f3 104 }
manzi 0:c58c860f51f3 105 break;
manzi 0:c58c860f51f3 106 }
manzi 0:c58c860f51f3 107
manzi 0:c58c860f51f3 108 }
manzi 0:c58c860f51f3 109 memset(datos,0,100);
manzi 0:c58c860f51f3 110 pc.printf("%s\n",beb1);
manzi 0:c58c860f51f3 111 pc.printf("%s\n",beb2);
manzi 0:c58c860f51f3 112 pc.printf("%s\n",beb3);
manzi 0:c58c860f51f3 113 pc.printf("%s\n",beb4);
manzi 0:c58c860f51f3 114 pc.printf("%s\n",beb5);
manzi 0:c58c860f51f3 115 pc.printf("%s\n",beb6);
manzi 0:c58c860f51f3 116 memset(beb1,0,25);
manzi 0:c58c860f51f3 117 memset(beb2,0,25);
manzi 0:c58c860f51f3 118 memset(beb3,0,25);
manzi 0:c58c860f51f3 119 memset(beb4,0,25);
manzi 0:c58c860f51f3 120 memset(beb5,0,25);
manzi 0:c58c860f51f3 121 memset(beb6,0,25);
manzi 0:c58c860f51f3 122 }
manzi 0:c58c860f51f3 123 else{
manzi 0:c58c860f51f3 124 datos[auxBL++] = charRecieve;
manzi 0:c58c860f51f3 125 }
manzi 0:c58c860f51f3 126 break;
manzi 0:c58c860f51f3 127 }
manzi 0:c58c860f51f3 128 }
manzi 0:c58c860f51f3 129
manzi 0:c58c860f51f3 130 void load_simple_drink(void){
manzi 0:c58c860f51f3 131 /*
manzi 0:c58c860f51f3 132 strcpy(simple_drink_matrix[0], beb1);
manzi 0:c58c860f51f3 133 strcpy(simple_drink_matrix[1], beb2);
manzi 0:c58c860f51f3 134 strcpy(simple_drink_matrix[2], beb3);
manzi 0:c58c860f51f3 135 strcpy(simple_drink_matrix[3], beb4);
manzi 0:c58c860f51f3 136 strcpy(simple_drink_matrix[4], beb5);
manzi 0:c58c860f51f3 137 strcpy(simple_drink_matrix[5], beb6);
manzi 0:c58c860f51f3 138 */
manzi 0:c58c860f51f3 139 }
manzi 0:c58c860f51f3 140 void load_elaborated_drinks(void){
manzi 0:c58c860f51f3 141 /*
manzi 0:c58c860f51f3 142 strcpy(elaborated_drink_matrix[0], Ebeb1);
manzi 0:c58c860f51f3 143 strcpy(elaborated_drink_matrix[1], Ebeb2);
manzi 0:c58c860f51f3 144 strcpy(elaborated_drink_matrix[2], Ebeb3);
manzi 0:c58c860f51f3 145 strcpy(elaborated_drink_matrix[3], Ebeb4);
manzi 0:c58c860f51f3 146 strcpy(elaborated_drink_matrix[4], Ebeb5);
manzi 0:c58c860f51f3 147 strcpy(elaborated_drink_matrix[5], Ebeb6);
manzi 0:c58c860f51f3 148 */
manzi 0:c58c860f51f3 149 }