Macros Corregidas

Dependencies:   BLE_API mbed

Committer:
Gustavo_Eduardo338
Date:
Sat Oct 01 18:03:24 2016 +0000
Revision:
11:965d5afe3a63
Parent:
10:5580ae8cbe7e
Child:
12:ff38af85a4ba
Macros Corregidas.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dixysleo 0:58e350255405 1 /*
dixysleo 0:58e350255405 2 Copyright (c) 2012-2014 RedBearLab
dixysleo 0:58e350255405 3
Gustavo_Eduardo338 4:a43cbe8aed6a 4 Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Gustavo_Eduardo338 4:a43cbe8aed6a 5 and associated documentation files (the "Software"), to deal in the Software without restriction,
Gustavo_Eduardo338 4:a43cbe8aed6a 6 including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
Gustavo_Eduardo338 4:a43cbe8aed6a 7 and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
dixysleo 0:58e350255405 8 subject to the following conditions:
dixysleo 0:58e350255405 9 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
dixysleo 0:58e350255405 10
Gustavo_Eduardo338 4:a43cbe8aed6a 11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
Gustavo_Eduardo338 4:a43cbe8aed6a 12 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
Gustavo_Eduardo338 4:a43cbe8aed6a 13 PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
Gustavo_Eduardo338 4:a43cbe8aed6a 14 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
dixysleo 0:58e350255405 15 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
dixysleo 0:58e350255405 16
dixysleo 0:58e350255405 17 */
dixysleo 0:58e350255405 18
dixysleo 0:58e350255405 19 #include "mbed.h"
dixysleo 0:58e350255405 20 #include "ble/BLE.h"
dixysleo 0:58e350255405 21 #include "GattCallbackParamTypes.h"
dixysleo 0:58e350255405 22
dixysleo 0:58e350255405 23 #define BLE_UUID_TXRX_SERVICE 0x0000 /**< The UUID of the Nordic UART Service. */
dixysleo 0:58e350255405 24 #define BLE_UUID_TX_CHARACTERISTIC 0x0002 /**< The UUID of the TX Characteristic. */
dixysleo 0:58e350255405 25 #define BLE_UUIDS_RX_CHARACTERISTIC 0x0003 /**< The UUID of the RX Characteristic. */
dixysleo 0:58e350255405 26
dixysleo 0:58e350255405 27 #define TXRX_BUF_LEN 20
dixysleo 0:58e350255405 28
Gustavo_Eduardo338 10:5580ae8cbe7e 29 #define ON 1
Gustavo_Eduardo338 10:5580ae8cbe7e 30 #define OFF 0
Gustavo_Eduardo338 10:5580ae8cbe7e 31 #define IN 1
Gustavo_Eduardo338 10:5580ae8cbe7e 32 #define OUT 0
Gustavo_Eduardo338 10:5580ae8cbe7e 33 #define PWM 2
Gustavo_Eduardo338 10:5580ae8cbe7e 34 #define NONE -1
Gustavo_Eduardo338 10:5580ae8cbe7e 35
Gustavo_Eduardo338 11:965d5afe3a63 36 //static int MODE_MOTE;
Gustavo_Eduardo338 10:5580ae8cbe7e 37 //Solo puede estar definido un solo Board
Gustavo_Eduardo338 10:5580ae8cbe7e 38 //#define nRF51-DK_board
Gustavo_Eduardo338 10:5580ae8cbe7e 39 #define redBearLab_board
Gustavo_Eduardo338 10:5580ae8cbe7e 40
Gustavo_Eduardo338 10:5580ae8cbe7e 41 #ifdef nRF51-DK_board
Gustavo_Eduardo338 10:5580ae8cbe7e 42 //Aqui se define el hardware del nRF51-DK
Gustavo_Eduardo338 10:5580ae8cbe7e 43
Gustavo_Eduardo338 10:5580ae8cbe7e 44 //Analog in
Gustavo_Eduardo338 10:5580ae8cbe7e 45 #define A0 P0_1 //Analog 0
Gustavo_Eduardo338 10:5580ae8cbe7e 46 #define A1 P0_2 //Analog 1
Gustavo_Eduardo338 10:5580ae8cbe7e 47 #define A2 P0_3 //Analog 2
Gustavo_Eduardo338 10:5580ae8cbe7e 48 #define A3 P0_4 //Analog 3
Gustavo_Eduardo338 10:5580ae8cbe7e 49 #define A4 P0_5 //Analog 4
Gustavo_Eduardo338 10:5580ae8cbe7e 50 #define A5 P0_6 //Analog 5
Gustavo_Eduardo338 10:5580ae8cbe7e 51
Gustavo_Eduardo338 10:5580ae8cbe7e 52 //Digital
Gustavo_Eduardo338 10:5580ae8cbe7e 53
Gustavo_Eduardo338 10:5580ae8cbe7e 54 #define D0 P0_14 //Digital I/O
Gustavo_Eduardo338 10:5580ae8cbe7e 55 #define D1 P0_12 //Digital I/O
Gustavo_Eduardo338 10:5580ae8cbe7e 56 #define D2 P0_13 //Digital I/O
Gustavo_Eduardo338 10:5580ae8cbe7e 57 #define D3 P0_15 //Digital I/O
Gustavo_Eduardo338 10:5580ae8cbe7e 58 #define D4 P0_21 //Digital I/O (LED 1)
Gustavo_Eduardo338 10:5580ae8cbe7e 59 #define D5 P0_22 //Digital I/O (LED 2)
Gustavo_Eduardo338 10:5580ae8cbe7e 60 #define D6 P0_23 //Digital I/O (LED 3)
Gustavo_Eduardo338 10:5580ae8cbe7e 61 #define D7 P0_24 //Digital I/O (LED 4)
Gustavo_Eduardo338 10:5580ae8cbe7e 62 #define D8 P0_17 //Digital I/O (BUTTON 1)
Gustavo_Eduardo338 10:5580ae8cbe7e 63 #define D9 P0_19 //Digital I/O (BUTTON 3)
Gustavo_Eduardo338 10:5580ae8cbe7e 64 #define D10 P0_18 //Digital I/O (BUTTON 2)
Gustavo_Eduardo338 10:5580ae8cbe7e 65 #define D11 P0_20 //Digital I/O (BUTTON 4)
Gustavo_Eduardo338 10:5580ae8cbe7e 66 #define D12 P0_7 //Digital I/O
Gustavo_Eduardo338 10:5580ae8cbe7e 67 #define D13 P0_30 //Digital I/O
Gustavo_Eduardo338 10:5580ae8cbe7e 68 #define D14 P0_8 //Digital I/O
Gustavo_Eduardo338 10:5580ae8cbe7e 69 #define D15 P0_16 //Digital I/O
Gustavo_Eduardo338 10:5580ae8cbe7e 70
Gustavo_Eduardo338 10:5580ae8cbe7e 71 //Aplicacion
Gustavo_Eduardo338 10:5580ae8cbe7e 72 #define LED_1 P0_21 //Digital I/O (LED 1)
Gustavo_Eduardo338 10:5580ae8cbe7e 73 #define LED_2 P0_22 //Digital I/O (LED 2)
Gustavo_Eduardo338 10:5580ae8cbe7e 74 #define LED_3 P0_23 //Digital I/O (LED 3)
Gustavo_Eduardo338 10:5580ae8cbe7e 75 #define LED_4 P0_24 //Digital I/O (LED 4)
Gustavo_Eduardo338 10:5580ae8cbe7e 76
Gustavo_Eduardo338 10:5580ae8cbe7e 77 #define BTN_1 P0_17 //Digital I/O (BUTTON 1)
Gustavo_Eduardo338 10:5580ae8cbe7e 78 #define BTN_2 P0_18 //Digital I/O (BUTTON 2)
Gustavo_Eduardo338 10:5580ae8cbe7e 79 #define BTN_3 P0_19 //Digital I/O (BUTTON 3)
Gustavo_Eduardo338 10:5580ae8cbe7e 80 #define BTN_4 P0_20 //Digital I/O (BUTTON 4)
Gustavo_Eduardo338 10:5580ae8cbe7e 81
Gustavo_Eduardo338 10:5580ae8cbe7e 82 // Aqui se acaba la configuracion del board NRF51-DK
Gustavo_Eduardo338 10:5580ae8cbe7e 83
Gustavo_Eduardo338 10:5580ae8cbe7e 84 #else
Gustavo_Eduardo338 10:5580ae8cbe7e 85 //Aqui se define el hardware del redBearLab
Gustavo_Eduardo338 10:5580ae8cbe7e 86 //Analog in
Gustavo_Eduardo338 10:5580ae8cbe7e 87 #define A0 P0_1 //Analog 0
Gustavo_Eduardo338 10:5580ae8cbe7e 88 #define A1 P0_2 //Analog 0
Gustavo_Eduardo338 10:5580ae8cbe7e 89 #define A2 P0_3 //Analog 0
Gustavo_Eduardo338 10:5580ae8cbe7e 90 #define A3 P0_4 //Analog 0
Gustavo_Eduardo338 10:5580ae8cbe7e 91 #define A4 P0_5 //Analog 0
Gustavo_Eduardo338 10:5580ae8cbe7e 92 #define A5 P0_6 //Analog 0
Gustavo_Eduardo338 10:5580ae8cbe7e 93
Gustavo_Eduardo338 10:5580ae8cbe7e 94 //Digital
Gustavo_Eduardo338 10:5580ae8cbe7e 95 #define D0 P0_11 //Digital I/O
Gustavo_Eduardo338 10:5580ae8cbe7e 96 #define D1 P0_9 //Digital I/O
Gustavo_Eduardo338 10:5580ae8cbe7e 97 #define D2 P0_10 //Digital I/O
Gustavo_Eduardo338 10:5580ae8cbe7e 98 #define D3 P0_8 //Digital I/O
Gustavo_Eduardo338 10:5580ae8cbe7e 99 #define D4 P0_21 //Digital I/O
Gustavo_Eduardo338 10:5580ae8cbe7e 100 #define D5 P0_23 //Digital I/O (PWM RBL)
Gustavo_Eduardo338 10:5580ae8cbe7e 101 #define D6 P0_16 //Digital I/O (PWM RBL)
Gustavo_Eduardo338 10:5580ae8cbe7e 102 #define D7 P0_17 //Digital I/O
Gustavo_Eduardo338 10:5580ae8cbe7e 103 #define D8 P0_19 //Digital I/O
Gustavo_Eduardo338 10:5580ae8cbe7e 104 #define D9 P0_18 //Digital I/O (PWM RBL)
Gustavo_Eduardo338 10:5580ae8cbe7e 105 #define D10 P0_14 //Digital I/O
Gustavo_Eduardo338 10:5580ae8cbe7e 106 #define D11 P0_12 //Digital I/O
Gustavo_Eduardo338 10:5580ae8cbe7e 107 #define D12 P0_13 //Digital I/O (LED RBL)
Gustavo_Eduardo338 10:5580ae8cbe7e 108 #define D13 P0_15 //Digital I/O
Gustavo_Eduardo338 10:5580ae8cbe7e 109 #define D14 P0_29 //Digital I/O
Gustavo_Eduardo338 10:5580ae8cbe7e 110 #define D15 P0_28 //Digital I/O
Gustavo_Eduardo338 10:5580ae8cbe7e 111
Gustavo_Eduardo338 10:5580ae8cbe7e 112 //Aplicacion
Gustavo_Eduardo338 10:5580ae8cbe7e 113 #define LED_1 P0_21 //Digital I/O (LED 1)
Gustavo_Eduardo338 10:5580ae8cbe7e 114 #define LED_2 P0_23 //Digital I/O (LED 2)
Gustavo_Eduardo338 10:5580ae8cbe7e 115 #define LED_3 P0_16 //Digital I/O (LED 3)
Gustavo_Eduardo338 10:5580ae8cbe7e 116 #define LED_4 P0_17 //Digital I/O (LED 4)
Gustavo_Eduardo338 10:5580ae8cbe7e 117
Gustavo_Eduardo338 10:5580ae8cbe7e 118 #define BTN_1 P0_11 //Digital I/O (BUTTON 1)
Gustavo_Eduardo338 10:5580ae8cbe7e 119 #define BTN_2 P0_9 //Digital I/O (BUTTON 2)
Gustavo_Eduardo338 10:5580ae8cbe7e 120 #define BTN_3 P0_10 //Digital I/O (BUTTON 3)
Gustavo_Eduardo338 10:5580ae8cbe7e 121 #define BTN_4 P0_8 //Digital I/O (BUTTON 4)
Gustavo_Eduardo338 10:5580ae8cbe7e 122
Gustavo_Eduardo338 10:5580ae8cbe7e 123 #endif
Gustavo_Eduardo338 10:5580ae8cbe7e 124
Gustavo_Eduardo338 10:5580ae8cbe7e 125
Gustavo_Eduardo338 10:5580ae8cbe7e 126 // Aqui se acabo la definicion del board REDBEARLAB
Gustavo_Eduardo338 10:5580ae8cbe7e 127
Gustavo_Eduardo338 10:5580ae8cbe7e 128 /**** Aqui se definen los pines necesarios independientemente del board seleccionado ******************
Gustavo_Eduardo338 10:5580ae8cbe7e 129
Gustavo_Eduardo338 10:5580ae8cbe7e 130 Instrucciones:
Gustavo_Eduardo338 10:5580ae8cbe7e 131 Pines digitales -->
Gustavo_Eduardo338 10:5580ae8cbe7e 132 ON --> Usado
Gustavo_Eduardo338 10:5580ae8cbe7e 133 OFF --> No sera usado
Gustavo_Eduardo338 10:5580ae8cbe7e 134 IN --> Entrada
Gustavo_Eduardo338 10:5580ae8cbe7e 135 OUT --> Salida
Gustavo_Eduardo338 10:5580ae8cbe7e 136
Gustavo_Eduardo338 10:5580ae8cbe7e 137 Pines Analogicos -->
Gustavo_Eduardo338 10:5580ae8cbe7e 138 ON --> Usado
Gustavo_Eduardo338 10:5580ae8cbe7e 139 OFF --> No sera usado
Gustavo_Eduardo338 10:5580ae8cbe7e 140 Valor del TED en numero reales, ejemplo 39.1, sino se va a usar se queda con 0
Gustavo_Eduardo338 10:5580ae8cbe7e 141 ********************************************************************************************************/
Gustavo_Eduardo338 10:5580ae8cbe7e 142
Gustavo_Eduardo338 11:965d5afe3a63 143 #define A0_USO OFF //-> Divisor de voltaje para medir bateria VDD
Gustavo_Eduardo338 11:965d5afe3a63 144 #define A1_USO OFF //-> Temperatura PT1000 (Borneras Shield de pruebas) Borneras
Gustavo_Eduardo338 10:5580ae8cbe7e 145 #define A2_USO OFF //-> Temperatura PT1000 (Borneras Shield de pruebas)
Gustavo_Eduardo338 10:5580ae8cbe7e 146 #define A3_USO OFF //-> Humedad (Borneras Shield de pruebas)
Gustavo_Eduardo338 10:5580ae8cbe7e 147 #define A4_USO OFF //-> Humedad (Borneras Shield de pruebas)
Gustavo_Eduardo338 11:965d5afe3a63 148 #define A5_USO ON //-> Conectarlo al LM35
Gustavo_Eduardo338 5:a8c07a29df8a 149
Gustavo_Eduardo338 11:965d5afe3a63 150 #define A0_TED 0 //Volts, bateria
Gustavo_Eduardo338 11:965d5afe3a63 151 #define A1_TED 0 // ºC temperatura PT 1000
Gustavo_Eduardo338 10:5580ae8cbe7e 152 #define A2_TED 0 // ºC temperatura PT 1000
Gustavo_Eduardo338 10:5580ae8cbe7e 153 #define A3_TED 0
Gustavo_Eduardo338 10:5580ae8cbe7e 154 #define A4_TED 0
Gustavo_Eduardo338 11:965d5afe3a63 155 #define A5_TED 39.10 // ºC temperatura ambiental con el LM35
Gustavo_Eduardo338 10:5580ae8cbe7e 156
Gustavo_Eduardo338 10:5580ae8cbe7e 157 #define D0_USO OFF //Ejemplo: ON
Gustavo_Eduardo338 10:5580ae8cbe7e 158 #define D1_USO OFF //Ejemplo: OFF
Gustavo_Eduardo338 11:965d5afe3a63 159 #define D2_USO OFF
Gustavo_Eduardo338 10:5580ae8cbe7e 160 #define D3_USO ON
Gustavo_Eduardo338 10:5580ae8cbe7e 161 #define D4_USO ON
Gustavo_Eduardo338 10:5580ae8cbe7e 162 #define D5_USO ON
Gustavo_Eduardo338 11:965d5afe3a63 163 #define D6_USO ON
Gustavo_Eduardo338 11:965d5afe3a63 164 #define D7_USO OFF
Gustavo_Eduardo338 11:965d5afe3a63 165 #define D8_USO OFF
Gustavo_Eduardo338 11:965d5afe3a63 166 #define D9_USO OFF //BUTTON 1 (NRF51-DK)
Gustavo_Eduardo338 10:5580ae8cbe7e 167 #define D10_USO OFF //BUTTON 2 (NRF51-DK)
Gustavo_Eduardo338 10:5580ae8cbe7e 168 #define D11_USO OFF //BUTTON 3 (NRF51-DK)
Gustavo_Eduardo338 10:5580ae8cbe7e 169 #define D12_USO OFF //BUTTON 4 (NRF51-DK)
Gustavo_Eduardo338 10:5580ae8cbe7e 170 #define D13_USO OFF
Gustavo_Eduardo338 10:5580ae8cbe7e 171 #define D14_USO OFF
Gustavo_Eduardo338 10:5580ae8cbe7e 172 #define D15_USO OFF
Gustavo_Eduardo338 10:5580ae8cbe7e 173
Gustavo_Eduardo338 10:5580ae8cbe7e 174 #define D0_TYPE NONE // Ejemplo: OUT
Gustavo_Eduardo338 10:5580ae8cbe7e 175 #define D1_TYPE NONE // Ejemplo: IN
Gustavo_Eduardo338 11:965d5afe3a63 176 #define D2_TYPE NONE // Para medir Humedad con Resistencia AC
Gustavo_Eduardo338 11:965d5afe3a63 177 #define D3_TYPE OUT // Led encienden con 1
Gustavo_Eduardo338 11:965d5afe3a63 178 #define D4_TYPE OUT // Led encienden con 0
Gustavo_Eduardo338 11:965d5afe3a63 179 #define D5_TYPE OUT // Led encienden con 0
Gustavo_Eduardo338 11:965d5afe3a63 180 #define D6_TYPE OUT // Led encienden con 1
Gustavo_Eduardo338 11:965d5afe3a63 181 #define D7_TYPE NONE // Pushbuttons (Activos en bajo)
Gustavo_Eduardo338 11:965d5afe3a63 182 #define D8_TYPE NONE // Pushbuttons (Activos en bajo)
Gustavo_Eduardo338 11:965d5afe3a63 183 #define D9_TYPE NONE // DIP Switch 1 (Activos en bajo)
Gustavo_Eduardo338 10:5580ae8cbe7e 184 #define D10_TYPE NONE // DIP Switch 2 (Activos en bajo)
Gustavo_Eduardo338 10:5580ae8cbe7e 185 #define D11_TYPE NONE // DIP Switch 3 (Activos en bajo)
Gustavo_Eduardo338 10:5580ae8cbe7e 186 #define D12_TYPE NONE // Para medir Humedad con Resistencia AC
Gustavo_Eduardo338 10:5580ae8cbe7e 187 #define D13_TYPE NONE // DIP Switch 4 (Activos en bajo)
Gustavo_Eduardo338 10:5580ae8cbe7e 188 #define D14_TYPE NONE // Para medir Humedad con Resistencia AC
Gustavo_Eduardo338 10:5580ae8cbe7e 189 #define D15_TYPE NONE // Para medir Humedad con Resistencia AC
Gustavo_Eduardo338 10:5580ae8cbe7e 190
Gustavo_Eduardo338 10:5580ae8cbe7e 191 //Macros de mbed
Gustavo_Eduardo338 10:5580ae8cbe7e 192 /*** Aqui Se definen todas macros en funcion de si el bit esta ON u OFF ************
Gustavo_Eduardo338 10:5580ae8cbe7e 193
Gustavo_Eduardo338 10:5580ae8cbe7e 194 Estos son las macors ya definidas:
Gustavo_Eduardo338 10:5580ae8cbe7e 195 DigitalOut LED_SET(DIGITAL_OUT_PIN); //Modo de uso --> LED_SET = 1 o LED_SET = 0;
Gustavo_Eduardo338 10:5580ae8cbe7e 196 DigitalIn BUTTON(DIGITAL_IN_PIN); //Modo de uso --> if (BUTTON != old_state)
Gustavo_Eduardo338 10:5580ae8cbe7e 197 PwmOut PWM(PWM_PIN); //Modo de uso --> PWM = value;
Gustavo_Eduardo338 10:5580ae8cbe7e 198 AnalogIn ANALOGTEMP(ANALOG_IN_PIN); //Modo de uso -> float s = ANALOG_A0;
Gustavo_Eduardo338 10:5580ae8cbe7e 199 AnalogIn ANALOGBAT(ANALOG_IN_BAT);
Gustavo_Eduardo338 10:5580ae8cbe7e 200 Servo MYSERVO(SERVO_PIN);
Gustavo_Eduardo338 10:5580ae8cbe7e 201 *************************************************************************************/
Gustavo_Eduardo338 10:5580ae8cbe7e 202
Gustavo_Eduardo338 10:5580ae8cbe7e 203 //Macros analogicas
Gustavo_Eduardo338 10:5580ae8cbe7e 204 AnalogIn ANALOG_A0(A0); //Bateria
Gustavo_Eduardo338 10:5580ae8cbe7e 205 AnalogIn ANALOG_A1(A1);
Gustavo_Eduardo338 10:5580ae8cbe7e 206 AnalogIn ANALOG_A2(A2);
Gustavo_Eduardo338 10:5580ae8cbe7e 207 AnalogIn ANALOG_A3(A3);
Gustavo_Eduardo338 10:5580ae8cbe7e 208 AnalogIn ANALOG_A4(A4);
Gustavo_Eduardo338 10:5580ae8cbe7e 209 AnalogIn ANALOG_A5(A5); //Temperatura ambiental con LM35
Gustavo_Eduardo338 5:a8c07a29df8a 210
Gustavo_Eduardo338 11:965d5afe3a63 211 #if D0_USO == ON
Gustavo_Eduardo338 11:965d5afe3a63 212 #if D0_TYPE == IN
Gustavo_Eduardo338 11:965d5afe3a63 213 DigitalIn PIN_D0(D0);
Gustavo_Eduardo338 11:965d5afe3a63 214 #else
Gustavo_Eduardo338 11:965d5afe3a63 215 DigitalOut PIN_D0(D0);
Gustavo_Eduardo338 11:965d5afe3a63 216 #endif
Gustavo_Eduardo338 11:965d5afe3a63 217 #endif
Gustavo_Eduardo338 11:965d5afe3a63 218
Gustavo_Eduardo338 11:965d5afe3a63 219 #if D1_USO == ON
Gustavo_Eduardo338 11:965d5afe3a63 220 #if D1_TYPE == IN
Gustavo_Eduardo338 11:965d5afe3a63 221 DigitalIn PIN_D1(D1);
Gustavo_Eduardo338 11:965d5afe3a63 222 #else
Gustavo_Eduardo338 11:965d5afe3a63 223 DigitalOut PIN_D1(D1);
Gustavo_Eduardo338 11:965d5afe3a63 224 #endif
Gustavo_Eduardo338 11:965d5afe3a63 225 #endif
Gustavo_Eduardo338 11:965d5afe3a63 226
Gustavo_Eduardo338 11:965d5afe3a63 227 #if D2_USO == ON
Gustavo_Eduardo338 11:965d5afe3a63 228 #if D2_TYPE == IN
Gustavo_Eduardo338 11:965d5afe3a63 229 DigitalIn PIN_D2(D2);
Gustavo_Eduardo338 11:965d5afe3a63 230 #else
Gustavo_Eduardo338 11:965d5afe3a63 231 DigitalOut PIN_D2(D2);
Gustavo_Eduardo338 11:965d5afe3a63 232 #endif
Gustavo_Eduardo338 11:965d5afe3a63 233 #else
Gustavo_Eduardo338 11:965d5afe3a63 234 static int PIN_D2 = 0;
Gustavo_Eduardo338 11:965d5afe3a63 235 #endif
Gustavo_Eduardo338 11:965d5afe3a63 236
Gustavo_Eduardo338 11:965d5afe3a63 237 #if D3_USO == ON
Gustavo_Eduardo338 11:965d5afe3a63 238 #if D3_TYPE == IN
Gustavo_Eduardo338 11:965d5afe3a63 239 DigitalIn PIN_D3(D3);
Gustavo_Eduardo338 11:965d5afe3a63 240 #else
Gustavo_Eduardo338 11:965d5afe3a63 241 DigitalOut PIN_D3(D3);
Gustavo_Eduardo338 11:965d5afe3a63 242 #endif
Gustavo_Eduardo338 11:965d5afe3a63 243 #endif
Gustavo_Eduardo338 11:965d5afe3a63 244
Gustavo_Eduardo338 11:965d5afe3a63 245 #if D4_USO == ON
Gustavo_Eduardo338 11:965d5afe3a63 246 #if D4_TYPE == IN
Gustavo_Eduardo338 11:965d5afe3a63 247 DigitalIn PIN_D4(D4);
Gustavo_Eduardo338 11:965d5afe3a63 248 #else
Gustavo_Eduardo338 11:965d5afe3a63 249 DigitalOut PIN_D4(D4);
Gustavo_Eduardo338 11:965d5afe3a63 250 #endif
Gustavo_Eduardo338 11:965d5afe3a63 251 #endif
Gustavo_Eduardo338 11:965d5afe3a63 252
Gustavo_Eduardo338 11:965d5afe3a63 253 #if D5_USO == ON
Gustavo_Eduardo338 11:965d5afe3a63 254 #if D5_TYPE == IN
Gustavo_Eduardo338 11:965d5afe3a63 255 DigitalIn PIN_D5(D5);
Gustavo_Eduardo338 11:965d5afe3a63 256 #endif
Gustavo_Eduardo338 11:965d5afe3a63 257 #if D5_TYPE == OUT
Gustavo_Eduardo338 11:965d5afe3a63 258 DigitalOut PIN_D5(D5);
Gustavo_Eduardo338 11:965d5afe3a63 259 #endif
Gustavo_Eduardo338 11:965d5afe3a63 260 #if D5_TYPE == PWM
Gustavo_Eduardo338 11:965d5afe3a63 261 PwmOut PIN_D5(D5);
Gustavo_Eduardo338 11:965d5afe3a63 262 #endif
Gustavo_Eduardo338 11:965d5afe3a63 263 #endif
Gustavo_Eduardo338 11:965d5afe3a63 264
Gustavo_Eduardo338 11:965d5afe3a63 265 #if D6_USO == ON
Gustavo_Eduardo338 11:965d5afe3a63 266 #if D6_TYPE == IN
Gustavo_Eduardo338 11:965d5afe3a63 267 DigitalIn PIN_D6(D6);
Gustavo_Eduardo338 11:965d5afe3a63 268 #endif
Gustavo_Eduardo338 11:965d5afe3a63 269 #if D6_TYPE == OUT
Gustavo_Eduardo338 11:965d5afe3a63 270 DigitalOut PIN_D6(D6);
Gustavo_Eduardo338 11:965d5afe3a63 271 #endif
Gustavo_Eduardo338 11:965d5afe3a63 272 #if D6_TYPE == PWM
Gustavo_Eduardo338 11:965d5afe3a63 273 PwmOut PIN_D6(D6);
Gustavo_Eduardo338 11:965d5afe3a63 274 #endif
Gustavo_Eduardo338 11:965d5afe3a63 275 #endif
Gustavo_Eduardo338 11:965d5afe3a63 276
Gustavo_Eduardo338 11:965d5afe3a63 277 #if D7_USO == ON
Gustavo_Eduardo338 11:965d5afe3a63 278 #if D7_TYPE == IN
Gustavo_Eduardo338 11:965d5afe3a63 279 DigitalIn PIN_D7(D7);
Gustavo_Eduardo338 11:965d5afe3a63 280 #endif
Gustavo_Eduardo338 11:965d5afe3a63 281 #if D7_TYPE == OUT
Gustavo_Eduardo338 11:965d5afe3a63 282 DigitalOut PIN_D7(D7);
Gustavo_Eduardo338 11:965d5afe3a63 283 #endif
Gustavo_Eduardo338 11:965d5afe3a63 284 #else
Gustavo_Eduardo338 11:965d5afe3a63 285 static int PIN_D7 = 0;
Gustavo_Eduardo338 11:965d5afe3a63 286 #endif
Gustavo_Eduardo338 10:5580ae8cbe7e 287
Gustavo_Eduardo338 11:965d5afe3a63 288 #if D8_USO == ON
Gustavo_Eduardo338 11:965d5afe3a63 289 #if D8_TYPE == IN
Gustavo_Eduardo338 11:965d5afe3a63 290 DigitalIn PIN_D8(D8);
Gustavo_Eduardo338 11:965d5afe3a63 291 #endif
Gustavo_Eduardo338 11:965d5afe3a63 292 #if D8_TYPE == OUT
Gustavo_Eduardo338 11:965d5afe3a63 293 DigitalOut PIN_D8(D8);
Gustavo_Eduardo338 11:965d5afe3a63 294 #endif
Gustavo_Eduardo338 11:965d5afe3a63 295 #else
Gustavo_Eduardo338 11:965d5afe3a63 296 static int PIN_D8 = 0;
Gustavo_Eduardo338 11:965d5afe3a63 297 #endif
Gustavo_Eduardo338 11:965d5afe3a63 298
Gustavo_Eduardo338 11:965d5afe3a63 299
Gustavo_Eduardo338 11:965d5afe3a63 300 #if D9_USO == ON
Gustavo_Eduardo338 11:965d5afe3a63 301 #if D9_TYPE == IN
Gustavo_Eduardo338 11:965d5afe3a63 302 DigitalIn PIN_D9(D9);
Gustavo_Eduardo338 11:965d5afe3a63 303 #endif
Gustavo_Eduardo338 11:965d5afe3a63 304 #if D9_TYPE == OUT
Gustavo_Eduardo338 11:965d5afe3a63 305 DigitalOut PIN_D9(D9);
Gustavo_Eduardo338 11:965d5afe3a63 306 #endif
Gustavo_Eduardo338 11:965d5afe3a63 307 #if D9_TYPE == PWM
Gustavo_Eduardo338 11:965d5afe3a63 308 PwmOut PIN_D9(D9);
Gustavo_Eduardo338 11:965d5afe3a63 309 #endif
Gustavo_Eduardo338 11:965d5afe3a63 310 #else
Gustavo_Eduardo338 11:965d5afe3a63 311 static int PIN_D9 = 0;
Gustavo_Eduardo338 11:965d5afe3a63 312 #endif
Gustavo_Eduardo338 11:965d5afe3a63 313
Gustavo_Eduardo338 11:965d5afe3a63 314 #if D10_USO == ON
Gustavo_Eduardo338 11:965d5afe3a63 315 #if D10_TYPE == IN
Gustavo_Eduardo338 11:965d5afe3a63 316 DigitalIn PIN_D10(D10);
Gustavo_Eduardo338 11:965d5afe3a63 317 #endif
Gustavo_Eduardo338 11:965d5afe3a63 318 #if D10_TYPE == OUT
Gustavo_Eduardo338 11:965d5afe3a63 319 DigitalOut PIN_D10(D10);
Gustavo_Eduardo338 11:965d5afe3a63 320 #endif
Gustavo_Eduardo338 11:965d5afe3a63 321 #else
Gustavo_Eduardo338 11:965d5afe3a63 322 static int PIN_D10 = 0;
Gustavo_Eduardo338 11:965d5afe3a63 323 #endif
Gustavo_Eduardo338 10:5580ae8cbe7e 324
Gustavo_Eduardo338 11:965d5afe3a63 325 #if D11_USO == ON
Gustavo_Eduardo338 11:965d5afe3a63 326 #if D11_TYPE == IN
Gustavo_Eduardo338 11:965d5afe3a63 327 DigitalIn PIN_D11(D11);
Gustavo_Eduardo338 11:965d5afe3a63 328 #endif
Gustavo_Eduardo338 11:965d5afe3a63 329 #if D11_TYPE == OUT
Gustavo_Eduardo338 11:965d5afe3a63 330 DigitalOut PIN_D11(D11);
Gustavo_Eduardo338 11:965d5afe3a63 331 #endif
Gustavo_Eduardo338 11:965d5afe3a63 332 #else
Gustavo_Eduardo338 11:965d5afe3a63 333 static int PIN_D11 = 0;
Gustavo_Eduardo338 11:965d5afe3a63 334 #endif
Gustavo_Eduardo338 11:965d5afe3a63 335
Gustavo_Eduardo338 11:965d5afe3a63 336 #if D12_USO == ON
Gustavo_Eduardo338 11:965d5afe3a63 337 #if D12_TYPE == IN
Gustavo_Eduardo338 11:965d5afe3a63 338 DigitalIn PIN_D12(D12);
Gustavo_Eduardo338 11:965d5afe3a63 339 #endif
Gustavo_Eduardo338 11:965d5afe3a63 340 #if D12_TYPE == OUT
Gustavo_Eduardo338 11:965d5afe3a63 341 DigitalOut PIN_D12(D12);
Gustavo_Eduardo338 11:965d5afe3a63 342 #endif
Gustavo_Eduardo338 11:965d5afe3a63 343 #else
Gustavo_Eduardo338 11:965d5afe3a63 344 static int PIN_D12 = 0;
Gustavo_Eduardo338 11:965d5afe3a63 345 #endif
Gustavo_Eduardo338 11:965d5afe3a63 346
Gustavo_Eduardo338 11:965d5afe3a63 347 #if D13_USO == ON
Gustavo_Eduardo338 11:965d5afe3a63 348 #if D13_TYPE == IN
Gustavo_Eduardo338 11:965d5afe3a63 349 DigitalIn PIN_D13(D13);
Gustavo_Eduardo338 11:965d5afe3a63 350 #endif
Gustavo_Eduardo338 11:965d5afe3a63 351 #if D13_TYPE == OUT
Gustavo_Eduardo338 11:965d5afe3a63 352 DigitalOut PIN_D13(D13);
Gustavo_Eduardo338 11:965d5afe3a63 353 #endif
Gustavo_Eduardo338 11:965d5afe3a63 354 #else
Gustavo_Eduardo338 11:965d5afe3a63 355 static int PIN_D13 = 0;
Gustavo_Eduardo338 11:965d5afe3a63 356 #endif
Gustavo_Eduardo338 11:965d5afe3a63 357
Gustavo_Eduardo338 11:965d5afe3a63 358 #if D14_USO == ON
Gustavo_Eduardo338 11:965d5afe3a63 359 #if D14_TYPE == IN
Gustavo_Eduardo338 11:965d5afe3a63 360 DigitalIn PIN_D14(D14);
Gustavo_Eduardo338 11:965d5afe3a63 361 #endif
Gustavo_Eduardo338 11:965d5afe3a63 362 #if D14_TYPE == OUT
Gustavo_Eduardo338 11:965d5afe3a63 363 DigitalOut PIN_D14(D14);
Gustavo_Eduardo338 11:965d5afe3a63 364 #endif
Gustavo_Eduardo338 11:965d5afe3a63 365 #else
Gustavo_Eduardo338 11:965d5afe3a63 366 static int PIN_D14 = 0;
Gustavo_Eduardo338 11:965d5afe3a63 367 #endif
Gustavo_Eduardo338 11:965d5afe3a63 368
Gustavo_Eduardo338 11:965d5afe3a63 369 #if D15_USO == ON
Gustavo_Eduardo338 11:965d5afe3a63 370 #if D15_TYPE == IN
Gustavo_Eduardo338 11:965d5afe3a63 371 DigitalIn PIN_D15(D15);
Gustavo_Eduardo338 11:965d5afe3a63 372 #endif
Gustavo_Eduardo338 11:965d5afe3a63 373 #if D15_TYPE == OUT
Gustavo_Eduardo338 11:965d5afe3a63 374 DigitalOut PIN_D15(D15);
Gustavo_Eduardo338 11:965d5afe3a63 375 #endif
Gustavo_Eduardo338 11:965d5afe3a63 376 #else
Gustavo_Eduardo338 11:965d5afe3a63 377 static int PIN_D15 = 0;
Gustavo_Eduardo338 11:965d5afe3a63 378 #endif
Gustavo_Eduardo338 11:965d5afe3a63 379
Gustavo_Eduardo338 10:5580ae8cbe7e 380
Gustavo_Eduardo338 10:5580ae8cbe7e 381 //Hasta aqui la definicion de macos
Gustavo_Eduardo338 10:5580ae8cbe7e 382 //Digital Inputs --> DATA VALUE
Gustavo_Eduardo338 10:5580ae8cbe7e 383 uint16_t DigitalInput_DATA = 0x0000; //Mapa de bits con los valores de la entrada digital segun la posicion
Gustavo_Eduardo338 11:965d5afe3a63 384 uint16_t ESTADO_ENTRADAS_DIGITALES = 0x0000;
Gustavo_Eduardo338 10:5580ae8cbe7e 385 uint16_t PAQUETE_ID = 0;
Gustavo_Eduardo338 10:5580ae8cbe7e 386
Gustavo_Eduardo338 10:5580ae8cbe7e 387 float AnalogInput_Ted [6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; //Si el TED es cero, es que no está en uso
Gustavo_Eduardo338 10:5580ae8cbe7e 388
Gustavo_Eduardo338 10:5580ae8cbe7e 389 //Digital input, cantidad, posiciones --> de todos, ted = 0, tipico hasta 16
Gustavo_Eduardo338 10:5580ae8cbe7e 390 uint16_t DigitalInput_Pos = 0x0000; //Mapa de bits, seran usados los bytes del TED 16 bits
Gustavo_Eduardo338 10:5580ae8cbe7e 391
Gustavo_Eduardo338 10:5580ae8cbe7e 392 //Digital output, cantidad, pocisiones --> de todos, ted = 0, tipico hasta 16
Gustavo_Eduardo338 10:5580ae8cbe7e 393 uint16_t DigitalOutput_Pos = 0x0000; //Mapa de bits, seran usados los bytes del TED 16 bits
Gustavo_Eduardo338 10:5580ae8cbe7e 394
Gustavo_Eduardo338 10:5580ae8cbe7e 395 uint16_t DigitalPwm_Pos = 0x0000; //Mapa de bits, seran usados los bytes del TED 16 bits
Gustavo_Eduardo338 10:5580ae8cbe7e 396
Gustavo_Eduardo338 10:5580ae8cbe7e 397 //Digital input, cantidad, posiciones --> de todos, ted = 0, tipico hasta 16
Gustavo_Eduardo338 11:965d5afe3a63 398 uint8_t AnalogInput_Pos = 0x0000; //Mapa de bits, seran usados los bytes del TED 8 bits
Gustavo_Eduardo338 10:5580ae8cbe7e 399
Gustavo_Eduardo338 10:5580ae8cbe7e 400 //Digital output, cantidad, pocisiones --> de todos, ted = 0, tipico hasta 16
Gustavo_Eduardo338 11:965d5afe3a63 401 uint8_t AnalogOutput_Pos = 0x0000; //Mapa de bits, seran usados los bytes del TED 8 bits
Gustavo_Eduardo338 10:5580ae8cbe7e 402
dixysleo 0:58e350255405 403
Gustavo_Eduardo338 5:a8c07a29df8a 404 // Declarando los pines
Gustavo_Eduardo338 7:fb4c6c1dd3a9 405 //static int32_t send_config = 0;
dixysleo 0:58e350255405 406
Gustavo_Eduardo338 10:5580ae8cbe7e 407 static int8_t SEND_CONFIG_GENERAL = 0;
Gustavo_Eduardo338 11:965d5afe3a63 408 static int8_t SEND_CONFIG_ANALOG_0, SEND_CONFIG_ANALOG_1, SEND_CONFIG_ANALOG_2, SEND_CONFIG_ANALOG_3, SEND_CONFIG_ANALOG_4, SEND_CONFIG_ANALOG_5;
Gustavo_Eduardo338 5:a8c07a29df8a 409
Gustavo_Eduardo338 8:c4130ea78471 410
Gustavo_Eduardo338 5:a8c07a29df8a 411 BLE ble;
Gustavo_Eduardo338 5:a8c07a29df8a 412
Gustavo_Eduardo338 7:fb4c6c1dd3a9 413 // Permite imprimir mensajes en la consola
dixysleo 0:58e350255405 414 Serial pc(USBTX, USBRX);
dixysleo 0:58e350255405 415
Gustavo_Eduardo338 11:965d5afe3a63 416 static uint8_t analog_enabled;
Gustavo_Eduardo338 11:965d5afe3a63 417
Gustavo_Eduardo338 11:965d5afe3a63 418 // Para las entradas digitales (Botones)
Gustavo_Eduardo338 10:5580ae8cbe7e 419 static uint8_t state_button_2 = 0, state_button_3 = 0,state_button_4 = 0,state_button_5 = 0 ;
Gustavo_Eduardo338 10:5580ae8cbe7e 420 static uint8_t state_button_6 = 0, state_button_7 = 0, state_button_8 = 0, state_button_9 = 0,state_button_10 = 0,state_button_11 = 0 ;
Gustavo_Eduardo338 10:5580ae8cbe7e 421 static uint8_t state_button_12 = 0, state_button_13 = 0, state_button_14 = 0, state_button_15 = 0;
dixysleo 0:58e350255405 422
Gustavo_Eduardo338 11:965d5afe3a63 423 // Para las entradas analogicas (Sensores)
Gustavo_Eduardo338 11:965d5afe3a63 424 static float value_A0, value_A1, value_A2, value_A3, value_A4, value_A5;
Gustavo_Eduardo338 11:965d5afe3a63 425
dixysleo 0:58e350255405 426 // The Nordic UART Service
dixysleo 0:58e350255405 427 static const uint8_t uart_base_uuid[] = {0x71, 0x3D, 0, 0, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
dixysleo 0:58e350255405 428 static const uint8_t uart_tx_uuid[] = {0x71, 0x3D, 0, 3, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
dixysleo 0:58e350255405 429 static const uint8_t uart_rx_uuid[] = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
dixysleo 0:58e350255405 430 static const uint8_t uart_base_uuid_rev[] = {0x1E, 0x94, 0x8D, 0xF1, 0x48, 0x31, 0x94, 0xBA, 0x75, 0x4C, 0x3E, 0x50, 0, 0, 0x3D, 0x71};
dixysleo 0:58e350255405 431
Gustavo_Eduardo338 7:fb4c6c1dd3a9 432 // Trama de Configuracion de los Pines (a).
Gustavo_Eduardo338 10:5580ae8cbe7e 433 static uint8_t TRAMA_CONFIG_GENERAL[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 , 0x00}; // Length 12
dixysleo 0:58e350255405 434
dixysleo 0:58e350255405 435 uint8_t txPayload[TXRX_BUF_LEN] = {0,};
dixysleo 0:58e350255405 436 uint8_t rxPayload[TXRX_BUF_LEN] = {0,};
dixysleo 0:58e350255405 437
dixysleo 0:58e350255405 438 GattCharacteristic txCharacteristic (uart_tx_uuid, txPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);
dixysleo 0:58e350255405 439 GattCharacteristic rxCharacteristic (uart_rx_uuid, rxPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
dixysleo 0:58e350255405 440 GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic};
dixysleo 0:58e350255405 441 GattService uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *));
dixysleo 0:58e350255405 442
Gustavo_Eduardo338 10:5580ae8cbe7e 443
dixysleo 0:58e350255405 444 // https://developer.mbed.org/forum/repo-61676-BLE_GAP_Example-community/topic/17193/
Gustavo_Eduardo338 4:a43cbe8aed6a 445 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *)
Gustavo_Eduardo338 4:a43cbe8aed6a 446 {
Gustavo_Eduardo338 4:a43cbe8aed6a 447 BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE);
dixysleo 0:58e350255405 448 pc.printf("Disconnected \r\n");
dixysleo 0:58e350255405 449 pc.printf("Restart advertising \r\n");
Gustavo_Eduardo338 4:a43cbe8aed6a 450 ble.startAdvertising();
Gustavo_Eduardo338 7:fb4c6c1dd3a9 451 analog_enabled = 0; // Deja que envie lecturas el PT 1000
Gustavo_Eduardo338 9:501a9e6710d2 452
Gustavo_Eduardo338 10:5580ae8cbe7e 453 SEND_CONFIG_GENERAL = 0;
Gustavo_Eduardo338 10:5580ae8cbe7e 454
Gustavo_Eduardo338 10:5580ae8cbe7e 455 // En caso de no completarse el envio de la configuraciones las detenemos por completo, y dehabilitamos el envio.
Gustavo_Eduardo338 11:965d5afe3a63 456 SEND_CONFIG_ANALOG_0 = OFF;
Gustavo_Eduardo338 11:965d5afe3a63 457 SEND_CONFIG_ANALOG_1 = OFF;
Gustavo_Eduardo338 11:965d5afe3a63 458 SEND_CONFIG_ANALOG_2 = OFF;
Gustavo_Eduardo338 11:965d5afe3a63 459 SEND_CONFIG_ANALOG_3 = OFF;
Gustavo_Eduardo338 11:965d5afe3a63 460 SEND_CONFIG_ANALOG_4 = OFF;
Gustavo_Eduardo338 11:965d5afe3a63 461 SEND_CONFIG_ANALOG_5 = OFF;
Gustavo_Eduardo338 10:5580ae8cbe7e 462
Gustavo_Eduardo338 10:5580ae8cbe7e 463 }
Gustavo_Eduardo338 10:5580ae8cbe7e 464
Gustavo_Eduardo338 11:965d5afe3a63 465 // Carga la configuración de las entradas digitales del MOTE.
Gustavo_Eduardo338 10:5580ae8cbe7e 466 void readDigitalInputs_Value ()
Gustavo_Eduardo338 10:5580ae8cbe7e 467 {
Gustavo_Eduardo338 11:965d5afe3a63 468 // ORIGINAL
Gustavo_Eduardo338 11:965d5afe3a63 469 //DigitalInput_DATA = (uint16_t) ((BUTTON_15 << 15) | (BUTTON_14 << 14) | (BUTTON_13 << 13) | (BUTTON_12 << 12) | (BUTTON_11 << 11) | (BUTTON_10 << 10) | (BUTTON_9 << 9) | (BUTTON_8 << 8) | (BUTTON_7 << 7) | (BUTTON_6 << 6) |(BUTTON_5 << 5) | (BUTTON_4 << 4) | (BUTTON_3 << 3) | (BUTTON_2 << 2));
Gustavo_Eduardo338 11:965d5afe3a63 470 DigitalInput_DATA = (uint16_t) (((D15_TYPE == IN ? 1:0) << 15) | ((D14_TYPE == IN?1:0)<< 14) | ((D13_TYPE == IN ?1:0) << 13) | ((D12_TYPE == IN ?1:0) << 12) | ((D11_TYPE == IN ?1:0) << 11) | ((D10_TYPE == IN? 1:0) << 10) | ((D9_TYPE == IN? 1:0) << 9) | ((D8_TYPE == IN ? 1:0) << 8) | ((D7_TYPE == IN ? 1:0) << 7) | ((D6_TYPE == IN ? 1:0) << 6) |((D5_TYPE == IN ? 1:0) << 5) | ((D4_TYPE == IN ? 1:0) << 4) | ((D3_TYPE == IN ? 1:0) << 3) | ((D2_TYPE == IN ? 1:0) << 2));
Gustavo_Eduardo338 11:965d5afe3a63 471 }
Gustavo_Eduardo338 11:965d5afe3a63 472
Gustavo_Eduardo338 11:965d5afe3a63 473 void cargarEstadoEntradasDigitales(){
Gustavo_Eduardo338 11:965d5afe3a63 474 ESTADO_ENTRADAS_DIGITALES = (uint16_t) (((D15_TYPE == IN ? state_button_15 :0) << 15) |((D14_TYPE == IN ? state_button_14 :0) << 14) |((D13_TYPE == IN ? state_button_13 :0) << 13) |((D12_TYPE == IN ? state_button_12 :0) << 12));
Gustavo_Eduardo338 11:965d5afe3a63 475 ESTADO_ENTRADAS_DIGITALES |= (uint16_t) (((D11_TYPE == IN ? state_button_11 :0) << 11) |((D10_TYPE == IN ? state_button_10 :0) << 10) |((D9_TYPE == IN ? state_button_9 :0) << 9) |((D8_TYPE == IN ? state_button_8 :0) << 8));
Gustavo_Eduardo338 11:965d5afe3a63 476 ESTADO_ENTRADAS_DIGITALES |= (uint16_t) (((D7_TYPE == IN ? state_button_7 :0) << 7) |((D6_TYPE == IN ? state_button_6 :0) << 6) |((D5_TYPE == IN ? state_button_5 :0) << 5) |((D4_TYPE == IN ? state_button_4 :0) << 4));
Gustavo_Eduardo338 11:965d5afe3a63 477 ESTADO_ENTRADAS_DIGITALES |= (uint16_t) (((D3_TYPE == IN ? state_button_3 :0) << 3) |((D2_TYPE == IN ? state_button_2 :0) << 2));
Gustavo_Eduardo338 10:5580ae8cbe7e 478 }
Gustavo_Eduardo338 10:5580ae8cbe7e 479
Gustavo_Eduardo338 10:5580ae8cbe7e 480 //Funcion para crear los extra bytes
Gustavo_Eduardo338 10:5580ae8cbe7e 481 void makeExtraBytes_CONFIG ()
Gustavo_Eduardo338 10:5580ae8cbe7e 482 {
Gustavo_Eduardo338 10:5580ae8cbe7e 483 // Teds de los Analog inputs
Gustavo_Eduardo338 10:5580ae8cbe7e 484 AnalogInput_Ted [0] = A0_TED;
Gustavo_Eduardo338 10:5580ae8cbe7e 485 AnalogInput_Ted [1] = A1_TED;
Gustavo_Eduardo338 10:5580ae8cbe7e 486 AnalogInput_Ted [2] = A2_TED;
Gustavo_Eduardo338 10:5580ae8cbe7e 487 AnalogInput_Ted [3] = A3_TED;
Gustavo_Eduardo338 10:5580ae8cbe7e 488 AnalogInput_Ted [4] = A4_TED;
Gustavo_Eduardo338 10:5580ae8cbe7e 489 AnalogInput_Ted [5] = A5_TED;
Gustavo_Eduardo338 10:5580ae8cbe7e 490
Gustavo_Eduardo338 10:5580ae8cbe7e 491 if (D15_USO == ON && D15_TYPE == IN)
Gustavo_Eduardo338 10:5580ae8cbe7e 492 DigitalInput_Pos |= (uint16_t) (D15_USO << 15);
Gustavo_Eduardo338 10:5580ae8cbe7e 493
Gustavo_Eduardo338 10:5580ae8cbe7e 494 if (D14_USO == ON && D14_TYPE == IN)
Gustavo_Eduardo338 10:5580ae8cbe7e 495 DigitalInput_Pos |= (uint16_t) (D14_USO << 14);
Gustavo_Eduardo338 10:5580ae8cbe7e 496
Gustavo_Eduardo338 10:5580ae8cbe7e 497 if (D13_USO == ON && D13_TYPE == IN)
Gustavo_Eduardo338 10:5580ae8cbe7e 498 DigitalInput_Pos |= (uint16_t) (D13_USO << 13);
Gustavo_Eduardo338 10:5580ae8cbe7e 499
Gustavo_Eduardo338 10:5580ae8cbe7e 500 if (D12_USO == ON && D12_TYPE == IN)
Gustavo_Eduardo338 10:5580ae8cbe7e 501 DigitalInput_Pos |= (uint16_t) (D12_USO << 12);
Gustavo_Eduardo338 10:5580ae8cbe7e 502
Gustavo_Eduardo338 10:5580ae8cbe7e 503 if (D11_USO == ON && D11_TYPE == IN)
Gustavo_Eduardo338 10:5580ae8cbe7e 504 DigitalInput_Pos |= (uint16_t) (D11_USO << 11);
Gustavo_Eduardo338 10:5580ae8cbe7e 505
Gustavo_Eduardo338 10:5580ae8cbe7e 506 if (D10_USO == ON && D10_TYPE == IN)
Gustavo_Eduardo338 10:5580ae8cbe7e 507 DigitalInput_Pos |= (uint16_t) (D10_USO << 10);
Gustavo_Eduardo338 10:5580ae8cbe7e 508
Gustavo_Eduardo338 10:5580ae8cbe7e 509 if (D9_USO == ON && D9_TYPE == IN)
Gustavo_Eduardo338 10:5580ae8cbe7e 510 DigitalInput_Pos |= (uint16_t) (D9_USO << 9);
Gustavo_Eduardo338 10:5580ae8cbe7e 511
Gustavo_Eduardo338 10:5580ae8cbe7e 512 if (D8_USO == ON && D8_TYPE == IN)
Gustavo_Eduardo338 10:5580ae8cbe7e 513 DigitalInput_Pos |= (uint16_t) (D8_USO << 8);
Gustavo_Eduardo338 10:5580ae8cbe7e 514
Gustavo_Eduardo338 10:5580ae8cbe7e 515 if (D7_USO == ON && D7_TYPE == IN)
Gustavo_Eduardo338 10:5580ae8cbe7e 516 DigitalInput_Pos |= (uint16_t) (D7_USO << 7);
Gustavo_Eduardo338 10:5580ae8cbe7e 517
Gustavo_Eduardo338 10:5580ae8cbe7e 518 if (D6_USO == ON && D6_TYPE == IN)
Gustavo_Eduardo338 10:5580ae8cbe7e 519 DigitalInput_Pos |= (uint16_t) (D6_USO << 6);
Gustavo_Eduardo338 10:5580ae8cbe7e 520
Gustavo_Eduardo338 10:5580ae8cbe7e 521 if (D5_USO == ON && D5_TYPE == IN)
Gustavo_Eduardo338 10:5580ae8cbe7e 522 DigitalInput_Pos |= (uint16_t) (D5_USO << 5);
Gustavo_Eduardo338 10:5580ae8cbe7e 523
Gustavo_Eduardo338 10:5580ae8cbe7e 524 if (D4_USO == ON && D4_TYPE == IN)
Gustavo_Eduardo338 10:5580ae8cbe7e 525 DigitalInput_Pos |= (uint16_t) (D4_USO << 4);
Gustavo_Eduardo338 10:5580ae8cbe7e 526
Gustavo_Eduardo338 10:5580ae8cbe7e 527 if (D3_USO == ON && D3_TYPE == IN)
Gustavo_Eduardo338 10:5580ae8cbe7e 528 DigitalInput_Pos |= (uint16_t) (D3_USO << 3);
Gustavo_Eduardo338 10:5580ae8cbe7e 529
Gustavo_Eduardo338 10:5580ae8cbe7e 530 if (D2_USO == ON && D2_TYPE == IN)
Gustavo_Eduardo338 10:5580ae8cbe7e 531 DigitalInput_Pos |= (uint16_t) (D2_USO << 2);
Gustavo_Eduardo338 10:5580ae8cbe7e 532
Gustavo_Eduardo338 10:5580ae8cbe7e 533 if (D1_USO == ON && D1_TYPE == IN)
Gustavo_Eduardo338 10:5580ae8cbe7e 534 DigitalInput_Pos |= (uint16_t) (D1_USO << 1);
Gustavo_Eduardo338 10:5580ae8cbe7e 535
Gustavo_Eduardo338 10:5580ae8cbe7e 536 if (D0_USO == ON && D0_TYPE == IN)
Gustavo_Eduardo338 10:5580ae8cbe7e 537 DigitalInput_Pos |= (uint16_t) (D0_USO << 0);
Gustavo_Eduardo338 10:5580ae8cbe7e 538
Gustavo_Eduardo338 10:5580ae8cbe7e 539
Gustavo_Eduardo338 10:5580ae8cbe7e 540
Gustavo_Eduardo338 10:5580ae8cbe7e 541
Gustavo_Eduardo338 10:5580ae8cbe7e 542 if (D15_USO == 1 && D15_TYPE == OUT)
Gustavo_Eduardo338 10:5580ae8cbe7e 543 DigitalOutput_Pos |= (uint16_t) (D15_USO << 15);
Gustavo_Eduardo338 10:5580ae8cbe7e 544
Gustavo_Eduardo338 10:5580ae8cbe7e 545 if (D14_USO == 1 && D14_TYPE == OUT)
Gustavo_Eduardo338 10:5580ae8cbe7e 546 DigitalOutput_Pos |= (uint16_t) (D14_USO << 14);
Gustavo_Eduardo338 10:5580ae8cbe7e 547
Gustavo_Eduardo338 10:5580ae8cbe7e 548 if (D13_USO == 1 && D13_TYPE == OUT)
Gustavo_Eduardo338 10:5580ae8cbe7e 549 DigitalOutput_Pos |= (uint16_t) (D13_USO << 13);
Gustavo_Eduardo338 10:5580ae8cbe7e 550
Gustavo_Eduardo338 10:5580ae8cbe7e 551 if (D12_USO == 1 && D12_TYPE == OUT)
Gustavo_Eduardo338 10:5580ae8cbe7e 552 DigitalOutput_Pos |= (uint16_t) (D12_USO << 12);
Gustavo_Eduardo338 10:5580ae8cbe7e 553
Gustavo_Eduardo338 10:5580ae8cbe7e 554 if (D11_USO == 1 && D11_TYPE == OUT)
Gustavo_Eduardo338 10:5580ae8cbe7e 555 DigitalOutput_Pos |= (uint16_t) (D11_USO << 11);
Gustavo_Eduardo338 10:5580ae8cbe7e 556
Gustavo_Eduardo338 10:5580ae8cbe7e 557 if (D10_USO == 1 && D10_TYPE == OUT)
Gustavo_Eduardo338 10:5580ae8cbe7e 558 DigitalOutput_Pos |= (uint16_t) (D10_USO << 10);
Gustavo_Eduardo338 10:5580ae8cbe7e 559
Gustavo_Eduardo338 10:5580ae8cbe7e 560 if (D9_USO == 1 && D9_TYPE == OUT)
Gustavo_Eduardo338 10:5580ae8cbe7e 561 DigitalOutput_Pos |= (uint16_t) (D9_USO << 9);
Gustavo_Eduardo338 10:5580ae8cbe7e 562
Gustavo_Eduardo338 10:5580ae8cbe7e 563 if (D8_USO == 1 && D8_TYPE == OUT)
Gustavo_Eduardo338 10:5580ae8cbe7e 564 DigitalOutput_Pos |= (uint16_t) (D8_USO << 8);
Gustavo_Eduardo338 9:501a9e6710d2 565
Gustavo_Eduardo338 10:5580ae8cbe7e 566 if (D7_USO == 1 && D7_TYPE == OUT)
Gustavo_Eduardo338 10:5580ae8cbe7e 567 DigitalOutput_Pos |= (uint16_t) (D7_USO << 7);
Gustavo_Eduardo338 10:5580ae8cbe7e 568
Gustavo_Eduardo338 10:5580ae8cbe7e 569 if (D6_USO == 1 && D6_TYPE == OUT)
Gustavo_Eduardo338 10:5580ae8cbe7e 570 DigitalOutput_Pos |= (uint16_t) (D6_USO << 6);
Gustavo_Eduardo338 10:5580ae8cbe7e 571
Gustavo_Eduardo338 10:5580ae8cbe7e 572 if (D5_USO == 1 && D5_TYPE == OUT)
Gustavo_Eduardo338 10:5580ae8cbe7e 573 DigitalOutput_Pos |= (uint16_t) (D5_USO << 5);
Gustavo_Eduardo338 10:5580ae8cbe7e 574
Gustavo_Eduardo338 10:5580ae8cbe7e 575 if (D4_USO == 1 && D4_TYPE == OUT)
Gustavo_Eduardo338 10:5580ae8cbe7e 576 DigitalOutput_Pos |= (uint16_t) (D4_USO << 4);
Gustavo_Eduardo338 10:5580ae8cbe7e 577
Gustavo_Eduardo338 10:5580ae8cbe7e 578 if (D3_USO == 1 && D3_TYPE == OUT)
Gustavo_Eduardo338 10:5580ae8cbe7e 579 DigitalOutput_Pos |= (uint16_t) (D3_USO << 3);
Gustavo_Eduardo338 10:5580ae8cbe7e 580
Gustavo_Eduardo338 10:5580ae8cbe7e 581 if (D2_USO == 1 && D2_TYPE == OUT)
Gustavo_Eduardo338 10:5580ae8cbe7e 582 DigitalOutput_Pos |= (uint16_t) (D2_USO << 2);
Gustavo_Eduardo338 10:5580ae8cbe7e 583
Gustavo_Eduardo338 10:5580ae8cbe7e 584 if (D1_USO == 1 && D1_TYPE == OUT)
Gustavo_Eduardo338 10:5580ae8cbe7e 585 DigitalOutput_Pos |= (uint16_t) (D1_USO << 1);
Gustavo_Eduardo338 10:5580ae8cbe7e 586
Gustavo_Eduardo338 10:5580ae8cbe7e 587 if (D0_USO == 1 && D0_TYPE == OUT)
Gustavo_Eduardo338 10:5580ae8cbe7e 588 DigitalOutput_Pos |= (uint16_t) (D0_USO << 0);
Gustavo_Eduardo338 10:5580ae8cbe7e 589
Gustavo_Eduardo338 10:5580ae8cbe7e 590
Gustavo_Eduardo338 10:5580ae8cbe7e 591
Gustavo_Eduardo338 10:5580ae8cbe7e 592 if (D15_USO == 1 && D15_TYPE == PWM)
Gustavo_Eduardo338 10:5580ae8cbe7e 593 DigitalPwm_Pos |= (uint16_t) (D15_USO << 15);
Gustavo_Eduardo338 10:5580ae8cbe7e 594
Gustavo_Eduardo338 10:5580ae8cbe7e 595 if (D14_USO == 1 && D14_TYPE == PWM)
Gustavo_Eduardo338 10:5580ae8cbe7e 596 DigitalPwm_Pos |= (uint16_t) (D14_USO << 14);
Gustavo_Eduardo338 10:5580ae8cbe7e 597
Gustavo_Eduardo338 10:5580ae8cbe7e 598 if (D13_USO == 1 && D13_TYPE == PWM)
Gustavo_Eduardo338 10:5580ae8cbe7e 599 DigitalPwm_Pos |= (uint16_t) (D13_USO << 13);
Gustavo_Eduardo338 10:5580ae8cbe7e 600
Gustavo_Eduardo338 10:5580ae8cbe7e 601 if (D12_USO == 1 && D12_TYPE == PWM)
Gustavo_Eduardo338 10:5580ae8cbe7e 602 DigitalPwm_Pos |= (uint16_t) (D12_USO << 12);
Gustavo_Eduardo338 10:5580ae8cbe7e 603
Gustavo_Eduardo338 10:5580ae8cbe7e 604 if (D11_USO == 1 && D11_TYPE == PWM)
Gustavo_Eduardo338 10:5580ae8cbe7e 605 DigitalPwm_Pos |= (uint16_t) (D11_USO << 11);
Gustavo_Eduardo338 10:5580ae8cbe7e 606
Gustavo_Eduardo338 10:5580ae8cbe7e 607 if (D10_USO == 1 && D10_TYPE == PWM)
Gustavo_Eduardo338 10:5580ae8cbe7e 608 DigitalPwm_Pos |= (uint16_t) (D10_USO << 10);
Gustavo_Eduardo338 10:5580ae8cbe7e 609
Gustavo_Eduardo338 10:5580ae8cbe7e 610 if (D9_USO == 1 && D9_TYPE == PWM)
Gustavo_Eduardo338 10:5580ae8cbe7e 611 DigitalPwm_Pos |= (uint16_t) (D9_USO << 9);
Gustavo_Eduardo338 10:5580ae8cbe7e 612
Gustavo_Eduardo338 10:5580ae8cbe7e 613 if (D8_USO == 1 && D8_TYPE == PWM)
Gustavo_Eduardo338 10:5580ae8cbe7e 614 DigitalPwm_Pos |= (uint16_t) (D8_USO << 8);
Gustavo_Eduardo338 10:5580ae8cbe7e 615
Gustavo_Eduardo338 10:5580ae8cbe7e 616 if (D7_USO == 1 && D7_TYPE == PWM)
Gustavo_Eduardo338 10:5580ae8cbe7e 617 DigitalPwm_Pos |= (uint16_t) (D7_USO << 7);
Gustavo_Eduardo338 10:5580ae8cbe7e 618
Gustavo_Eduardo338 10:5580ae8cbe7e 619 if (D6_USO == 1 && D6_TYPE == PWM)
Gustavo_Eduardo338 10:5580ae8cbe7e 620 DigitalPwm_Pos |= (uint16_t) (D6_USO << 6);
Gustavo_Eduardo338 10:5580ae8cbe7e 621
Gustavo_Eduardo338 10:5580ae8cbe7e 622 if (D5_USO == 1 && D5_TYPE == PWM)
Gustavo_Eduardo338 10:5580ae8cbe7e 623 DigitalPwm_Pos |= (uint16_t) (D5_USO << 5);
Gustavo_Eduardo338 10:5580ae8cbe7e 624
Gustavo_Eduardo338 10:5580ae8cbe7e 625 if (D4_USO == 1 && D4_TYPE == PWM)
Gustavo_Eduardo338 10:5580ae8cbe7e 626 DigitalPwm_Pos |= (uint16_t) (D4_USO << 4);
Gustavo_Eduardo338 10:5580ae8cbe7e 627
Gustavo_Eduardo338 10:5580ae8cbe7e 628 if (D3_USO == 1 && D3_TYPE == PWM)
Gustavo_Eduardo338 10:5580ae8cbe7e 629 DigitalPwm_Pos |= (uint16_t) (D3_USO << 3);
Gustavo_Eduardo338 10:5580ae8cbe7e 630
Gustavo_Eduardo338 10:5580ae8cbe7e 631 if (D2_USO == 1 && D2_TYPE == PWM)
Gustavo_Eduardo338 10:5580ae8cbe7e 632 DigitalPwm_Pos |= (uint16_t) (D2_USO << 2);
Gustavo_Eduardo338 10:5580ae8cbe7e 633
Gustavo_Eduardo338 10:5580ae8cbe7e 634 if (D1_USO == 1 && D1_TYPE == PWM)
Gustavo_Eduardo338 10:5580ae8cbe7e 635 DigitalPwm_Pos |= (uint16_t) (D1_USO << 1);
Gustavo_Eduardo338 10:5580ae8cbe7e 636
Gustavo_Eduardo338 10:5580ae8cbe7e 637 if (D0_USO == 1 && D0_TYPE == PWM)
Gustavo_Eduardo338 10:5580ae8cbe7e 638 DigitalPwm_Pos |= (uint16_t) (D0_USO << 0);
Gustavo_Eduardo338 10:5580ae8cbe7e 639
Gustavo_Eduardo338 10:5580ae8cbe7e 640
Gustavo_Eduardo338 10:5580ae8cbe7e 641 //Digital inputs
Gustavo_Eduardo338 10:5580ae8cbe7e 642 AnalogInput_Pos = (uint16_t) ((A5_USO << 5) | (A4_USO << 4) | (A3_USO << 3) | (A2_USO << 2) | (A1_USO << 1) | (A0_USO << 0));
Gustavo_Eduardo338 10:5580ae8cbe7e 643 //Digital Outputs
Gustavo_Eduardo338 10:5580ae8cbe7e 644
Gustavo_Eduardo338 10:5580ae8cbe7e 645
Gustavo_Eduardo338 10:5580ae8cbe7e 646
Gustavo_Eduardo338 10:5580ae8cbe7e 647 //para probar
Gustavo_Eduardo338 10:5580ae8cbe7e 648 pc.printf("DigitalInput_Pos = %x \r\n", DigitalInput_Pos);
Gustavo_Eduardo338 10:5580ae8cbe7e 649 pc.printf("DigitalOutput_Pos = %x \r\n", DigitalOutput_Pos);
Gustavo_Eduardo338 10:5580ae8cbe7e 650 pc.printf("AnalogInput_Pos = %x \r\n", AnalogInput_Pos);
Gustavo_Eduardo338 10:5580ae8cbe7e 651 pc.printf("AnalogOutput_Pos = %x \r\n", DigitalPwm_Pos);
Gustavo_Eduardo338 10:5580ae8cbe7e 652 pc.printf("---------------------------\r\n");
Gustavo_Eduardo338 10:5580ae8cbe7e 653
Gustavo_Eduardo338 10:5580ae8cbe7e 654 // Definimos la trama de configuracion general
Gustavo_Eduardo338 10:5580ae8cbe7e 655 TRAMA_CONFIG_GENERAL [0] = 0xC1; // Codigo de configuracion general
Gustavo_Eduardo338 10:5580ae8cbe7e 656 TRAMA_CONFIG_GENERAL [1] = 0xA1; // Codigo de entradas analogicas
Gustavo_Eduardo338 10:5580ae8cbe7e 657 TRAMA_CONFIG_GENERAL [2] = AnalogInput_Pos; // Valor de las entradas analogicas
Gustavo_Eduardo338 10:5580ae8cbe7e 658 TRAMA_CONFIG_GENERAL [3] = 0xA0; // Codigo de las salidas analogicas
Gustavo_Eduardo338 10:5580ae8cbe7e 659 TRAMA_CONFIG_GENERAL [4] = (DigitalPwm_Pos >> 8); // Valor de las salidas analogicas
Gustavo_Eduardo338 10:5580ae8cbe7e 660 TRAMA_CONFIG_GENERAL [5] = (DigitalPwm_Pos); // Valor de las salidas analogicas
Gustavo_Eduardo338 10:5580ae8cbe7e 661 TRAMA_CONFIG_GENERAL [6] = 0xD1; // Codigo de las entradas digitales
Gustavo_Eduardo338 10:5580ae8cbe7e 662 TRAMA_CONFIG_GENERAL [7] = (DigitalInput_Pos >> 8);
Gustavo_Eduardo338 10:5580ae8cbe7e 663 TRAMA_CONFIG_GENERAL [8] = DigitalInput_Pos;
Gustavo_Eduardo338 10:5580ae8cbe7e 664 TRAMA_CONFIG_GENERAL [9] = 0xD0; // Codigo de las salidas difitales
Gustavo_Eduardo338 10:5580ae8cbe7e 665 TRAMA_CONFIG_GENERAL [10] = (DigitalOutput_Pos>> 8);
Gustavo_Eduardo338 10:5580ae8cbe7e 666 TRAMA_CONFIG_GENERAL [11] = DigitalOutput_Pos;
Gustavo_Eduardo338 10:5580ae8cbe7e 667
Gustavo_Eduardo338 5:a8c07a29df8a 668 }
Gustavo_Eduardo338 10:5580ae8cbe7e 669
Gustavo_Eduardo338 10:5580ae8cbe7e 670
Gustavo_Eduardo338 10:5580ae8cbe7e 671
Gustavo_Eduardo338 5:a8c07a29df8a 672 // Ingresa por este metdo unicamente la primera vez que se conecta al mote.
Gustavo_Eduardo338 5:a8c07a29df8a 673 // Tomado desde: https://developer.mbed.org/teams/Bluetooth-Low-Energy/code/BLE_LEDBlinker/file/dc392bde2b3c/main.cpp
Gustavo_Eduardo338 5:a8c07a29df8a 674 void connectionCallback(const Gap::ConnectionCallbackParams_t *)
Gustavo_Eduardo338 5:a8c07a29df8a 675 {
Gustavo_Eduardo338 5:a8c07a29df8a 676 pc.printf("connectionCallback \r\n");
Gustavo_Eduardo338 10:5580ae8cbe7e 677
Gustavo_Eduardo338 10:5580ae8cbe7e 678 makeExtraBytes_CONFIG();
Gustavo_Eduardo338 10:5580ae8cbe7e 679 SEND_CONFIG_GENERAL = 1;
dixysleo 0:58e350255405 680 }
dixysleo 0:58e350255405 681
Gustavo_Eduardo338 5:a8c07a29df8a 682 // Recepta las caracteristicas que se desea escribir en el mote.
dixysleo 0:58e350255405 683 void WrittenHandler(const GattWriteCallbackParams *Handler)
Gustavo_Eduardo338 4:a43cbe8aed6a 684 {
Gustavo_Eduardo338 5:a8c07a29df8a 685 pc.printf("WrittenHandler(const GattWriteCallbackParams *Handler) \r\n");
dixysleo 0:58e350255405 686 uint8_t buf[TXRX_BUF_LEN];
dixysleo 0:58e350255405 687 uint16_t bytesRead, index;
Gustavo_Eduardo338 4:a43cbe8aed6a 688
Gustavo_Eduardo338 4:a43cbe8aed6a 689 if (Handler->handle == txCharacteristic.getValueAttribute().getHandle()) {
dixysleo 0:58e350255405 690 ble.readCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(), buf, &bytesRead);
dixysleo 0:58e350255405 691 memset(txPayload, 0, TXRX_BUF_LEN);
Gustavo_Eduardo338 4:a43cbe8aed6a 692 memcpy(txPayload, buf, TXRX_BUF_LEN);
Gustavo_Eduardo338 4:a43cbe8aed6a 693
dixysleo 0:58e350255405 694 for(index=0; index<bytesRead; index++)
dixysleo 0:58e350255405 695 pc.putc(buf[index]);
Gustavo_Eduardo338 4:a43cbe8aed6a 696
Gustavo_Eduardo338 10:5580ae8cbe7e 697 pc.printf("Leemos la trama: \r\n");
Gustavo_Eduardo338 10:5580ae8cbe7e 698 for(index=0; index<bytesRead; index++) {
Gustavo_Eduardo338 10:5580ae8cbe7e 699 pc.printf("buf[%02x]: %02x\r\n", index, buf[index]);
Gustavo_Eduardo338 7:fb4c6c1dd3a9 700 }
Gustavo_Eduardo338 9:501a9e6710d2 701
Gustavo_Eduardo338 10:5580ae8cbe7e 702 // Desde el telefono desactiva el envio de tramas de configuracion general o de cada sensor.
Gustavo_Eduardo338 10:5580ae8cbe7e 703 if (buf[0] == 0xDC) { // Dato Configuracion
Gustavo_Eduardo338 10:5580ae8cbe7e 704 if(buf[1] == 0xC1) { // Hace referencia a la configuración general
Gustavo_Eduardo338 10:5580ae8cbe7e 705 SEND_CONFIG_GENERAL = buf[2]; // Debe ser cero, hace que ya no se vuelva a enviar la conf general del mote
Gustavo_Eduardo338 10:5580ae8cbe7e 706
Gustavo_Eduardo338 10:5580ae8cbe7e 707 // Comprueba si estan habilitados las salidas analogicas, y las
Gustavo_Eduardo338 10:5580ae8cbe7e 708 // inicializa a 1 para que mas adelante envie la configuracion
Gustavo_Eduardo338 10:5580ae8cbe7e 709 // de cada sensor
Gustavo_Eduardo338 10:5580ae8cbe7e 710 SEND_CONFIG_ANALOG_0 = (A0_USO == ON)?1:0;
Gustavo_Eduardo338 10:5580ae8cbe7e 711 SEND_CONFIG_ANALOG_1 = (A1_USO == ON)?1:0;
Gustavo_Eduardo338 10:5580ae8cbe7e 712 SEND_CONFIG_ANALOG_2 = (A2_USO == ON)?1:0;
Gustavo_Eduardo338 10:5580ae8cbe7e 713 SEND_CONFIG_ANALOG_3 = (A3_USO == ON)?1:0;
Gustavo_Eduardo338 10:5580ae8cbe7e 714 SEND_CONFIG_ANALOG_4 = (A4_USO == ON)?1:0;
Gustavo_Eduardo338 10:5580ae8cbe7e 715 SEND_CONFIG_ANALOG_5 = (A5_USO == ON)?1:0;
Gustavo_Eduardo338 10:5580ae8cbe7e 716 }
Gustavo_Eduardo338 9:501a9e6710d2 717
Gustavo_Eduardo338 10:5580ae8cbe7e 718 // Maneja las Tramas de confirmacion de la configuracion detallada de cada senssor analogico
Gustavo_Eduardo338 10:5580ae8cbe7e 719 if(buf[1] == 0xC2) { // Hace referencia a la configuracion detallada por sensor.
Gustavo_Eduardo338 10:5580ae8cbe7e 720 switch (buf[2]) { // Evalua la posición
Gustavo_Eduardo338 10:5580ae8cbe7e 721 case 0x00: // 0xA0
Gustavo_Eduardo338 10:5580ae8cbe7e 722 SEND_CONFIG_ANALOG_0 = buf[3]; // buf[3] debe ser 0, para detenerse el envió SEND_CONFIG_ANALOG_0
Gustavo_Eduardo338 10:5580ae8cbe7e 723 break;
Gustavo_Eduardo338 10:5580ae8cbe7e 724 case 0x01: // 0xA1
Gustavo_Eduardo338 10:5580ae8cbe7e 725 SEND_CONFIG_ANALOG_1 = buf[3]; // buf[3] debe ser 0, para detenerse el envió SEND_CONFIG_ANALOG_1
Gustavo_Eduardo338 10:5580ae8cbe7e 726 break;
Gustavo_Eduardo338 10:5580ae8cbe7e 727 case 0x02: // 0xA2
Gustavo_Eduardo338 10:5580ae8cbe7e 728 SEND_CONFIG_ANALOG_2 = buf[3]; // buf[3] debe ser 0, para detenerse el envió SEND_CONFIG_ANALOG_2
Gustavo_Eduardo338 10:5580ae8cbe7e 729 break;
Gustavo_Eduardo338 10:5580ae8cbe7e 730 case 0x03: // 0xA3
Gustavo_Eduardo338 10:5580ae8cbe7e 731 SEND_CONFIG_ANALOG_3 = buf[3]; // buf[3] debe ser 0, para detenerse el envió SEND_CONFIG_ANALOG_3
Gustavo_Eduardo338 10:5580ae8cbe7e 732 break;
Gustavo_Eduardo338 10:5580ae8cbe7e 733 case 0x04: // 0xA4
Gustavo_Eduardo338 10:5580ae8cbe7e 734 SEND_CONFIG_ANALOG_4 = buf[3]; // buf[3] debe ser 0, para detenerse el envió SEND_CONFIG_ANALOG_4
Gustavo_Eduardo338 10:5580ae8cbe7e 735 break;
Gustavo_Eduardo338 10:5580ae8cbe7e 736 case 0x05: // 0xA5
Gustavo_Eduardo338 10:5580ae8cbe7e 737 SEND_CONFIG_ANALOG_5 = buf[3]; // buf[3] debe ser 0, para detenerse el envió SEND_CONFIG_ANALOG_5
Gustavo_Eduardo338 10:5580ae8cbe7e 738 break;
Gustavo_Eduardo338 10:5580ae8cbe7e 739 }
Gustavo_Eduardo338 10:5580ae8cbe7e 740 }
Gustavo_Eduardo338 7:fb4c6c1dd3a9 741 }
Gustavo_Eduardo338 9:501a9e6710d2 742
Gustavo_Eduardo338 7:fb4c6c1dd3a9 743
Gustavo_Eduardo338 7:fb4c6c1dd3a9 744 // Verifico si es una trama de Escitura.
Gustavo_Eduardo338 7:fb4c6c1dd3a9 745 if(buf[0] == 0xEE) {
Gustavo_Eduardo338 10:5580ae8cbe7e 746 PAQUETE_ID = buf[1];
Gustavo_Eduardo338 7:fb4c6c1dd3a9 747 // Verifico si es un signal Digital Out
Gustavo_Eduardo338 7:fb4c6c1dd3a9 748 if(buf[2] == 0xD0) {
Gustavo_Eduardo338 10:5580ae8cbe7e 749 // Evaluo sobre que pin se debe actuar.
Gustavo_Eduardo338 10:5580ae8cbe7e 750 switch (buf[3]) {
Gustavo_Eduardo338 10:5580ae8cbe7e 751 case 0x02:
Gustavo_Eduardo338 11:965d5afe3a63 752 #ifdef PIN_D2
Gustavo_Eduardo338 11:965d5afe3a63 753 PIN_D2 = (buf[4] == 0x01) ? 1:0;
Gustavo_Eduardo338 11:965d5afe3a63 754 #endif
Gustavo_Eduardo338 10:5580ae8cbe7e 755 break;
Gustavo_Eduardo338 10:5580ae8cbe7e 756 case 0x03:
Gustavo_Eduardo338 11:965d5afe3a63 757 PIN_D3 = (buf[4] == 0x01) ? 1:0; break;
Gustavo_Eduardo338 10:5580ae8cbe7e 758 case 0x04:
Gustavo_Eduardo338 11:965d5afe3a63 759 PIN_D4 = (buf[4] == 0x00) ? 1:0; break;
Gustavo_Eduardo338 10:5580ae8cbe7e 760 case 0x05:
Gustavo_Eduardo338 11:965d5afe3a63 761 PIN_D5 = (buf[4] == 0x00) ? 1:0; break;
Gustavo_Eduardo338 10:5580ae8cbe7e 762 case 0x06:
Gustavo_Eduardo338 11:965d5afe3a63 763 PIN_D6 = (buf[4] == 0x01) ? 1:0; break;
Gustavo_Eduardo338 10:5580ae8cbe7e 764 case 0x07:
Gustavo_Eduardo338 11:965d5afe3a63 765 #ifdef PIN_D7
Gustavo_Eduardo338 11:965d5afe3a63 766 PIN_D7 = (buf[4] == 0x01) ? 1:0;
Gustavo_Eduardo338 11:965d5afe3a63 767 #endif
Gustavo_Eduardo338 10:5580ae8cbe7e 768 break;
Gustavo_Eduardo338 10:5580ae8cbe7e 769 case 0x08:
Gustavo_Eduardo338 11:965d5afe3a63 770 #ifdef PIN_D8
Gustavo_Eduardo338 11:965d5afe3a63 771 PIN_D8 = (buf[4] == 0x01) ? 1:0;
Gustavo_Eduardo338 11:965d5afe3a63 772 #endif
Gustavo_Eduardo338 10:5580ae8cbe7e 773 break;
Gustavo_Eduardo338 10:5580ae8cbe7e 774 case 0x09:
Gustavo_Eduardo338 11:965d5afe3a63 775 #ifdef PIN_D9
Gustavo_Eduardo338 11:965d5afe3a63 776 PIN_D9 = (buf[4] == 0x01) ? 1:0;
Gustavo_Eduardo338 11:965d5afe3a63 777 #endif
Gustavo_Eduardo338 10:5580ae8cbe7e 778 break;
Gustavo_Eduardo338 10:5580ae8cbe7e 779 case 0x10:
Gustavo_Eduardo338 11:965d5afe3a63 780 #ifdef PIN_D10
Gustavo_Eduardo338 11:965d5afe3a63 781 PIN_D10 = (buf[4] == 0x01) ? 1:0;
Gustavo_Eduardo338 11:965d5afe3a63 782 #endif
Gustavo_Eduardo338 10:5580ae8cbe7e 783 break;
Gustavo_Eduardo338 10:5580ae8cbe7e 784 case 0x11:
Gustavo_Eduardo338 11:965d5afe3a63 785 #ifdef PIN_D11
Gustavo_Eduardo338 11:965d5afe3a63 786 PIN_D11 = (buf[4] == 0x01) ? 1:0;
Gustavo_Eduardo338 11:965d5afe3a63 787 #endif
Gustavo_Eduardo338 10:5580ae8cbe7e 788 break;
Gustavo_Eduardo338 10:5580ae8cbe7e 789 case 0x12:
Gustavo_Eduardo338 11:965d5afe3a63 790 #ifdef PIN_D12
Gustavo_Eduardo338 11:965d5afe3a63 791 PIN_D12 = (buf[4] == 0x01) ? 1:0;
Gustavo_Eduardo338 11:965d5afe3a63 792 #endif
Gustavo_Eduardo338 10:5580ae8cbe7e 793 break;
Gustavo_Eduardo338 10:5580ae8cbe7e 794 case 0x13:
Gustavo_Eduardo338 11:965d5afe3a63 795 #ifdef PIN_D13
Gustavo_Eduardo338 11:965d5afe3a63 796 PIN_D13 = (buf[4] == 0x01) ? 1:0;
Gustavo_Eduardo338 11:965d5afe3a63 797 #endif
Gustavo_Eduardo338 10:5580ae8cbe7e 798 break;
Gustavo_Eduardo338 10:5580ae8cbe7e 799 case 0x14:
Gustavo_Eduardo338 11:965d5afe3a63 800 #ifdef PIN_D14
Gustavo_Eduardo338 11:965d5afe3a63 801 PIN_D14 = (buf[4] == 0x01) ? 1:0;
Gustavo_Eduardo338 11:965d5afe3a63 802 #endif
Gustavo_Eduardo338 10:5580ae8cbe7e 803 break;
Gustavo_Eduardo338 10:5580ae8cbe7e 804 case 0x15:
Gustavo_Eduardo338 11:965d5afe3a63 805 #ifdef PIN_D15
Gustavo_Eduardo338 11:965d5afe3a63 806 PIN_D15 = (buf[4] == 0x01) ? 1:0;
Gustavo_Eduardo338 11:965d5afe3a63 807 #endif
Gustavo_Eduardo338 10:5580ae8cbe7e 808 break;
Gustavo_Eduardo338 7:fb4c6c1dd3a9 809 }
Gustavo_Eduardo338 9:501a9e6710d2 810 // Verifico si es un signal Analog out
Gustavo_Eduardo338 7:fb4c6c1dd3a9 811 } else if(buf[2] == 0xA0) {
Gustavo_Eduardo338 10:5580ae8cbe7e 812 float value = (float)buf[4]/255;
Gustavo_Eduardo338 10:5580ae8cbe7e 813 switch (buf[3]) {
Gustavo_Eduardo338 10:5580ae8cbe7e 814 case 0x05:
Gustavo_Eduardo338 11:965d5afe3a63 815 PIN_D5 = value; break;
Gustavo_Eduardo338 10:5580ae8cbe7e 816 case 0x06:
Gustavo_Eduardo338 11:965d5afe3a63 817 PIN_D6 = value; break;
Gustavo_Eduardo338 11:965d5afe3a63 818 case 0x09:
Gustavo_Eduardo338 11:965d5afe3a63 819 #ifdef PIN_D9
Gustavo_Eduardo338 11:965d5afe3a63 820 PIN_D9 = value;
Gustavo_Eduardo338 11:965d5afe3a63 821 #endif
Gustavo_Eduardo338 10:5580ae8cbe7e 822 break;
Gustavo_Eduardo338 7:fb4c6c1dd3a9 823 }
dixysleo 0:58e350255405 824 }
dixysleo 0:58e350255405 825 }
dixysleo 0:58e350255405 826 }
dixysleo 0:58e350255405 827 }
Gustavo_Eduardo338 7:fb4c6c1dd3a9 828
Gustavo_Eduardo338 10:5580ae8cbe7e 829
dixysleo 0:58e350255405 830 /*
Gustavo_Eduardo338 7:fb4c6c1dd3a9 831 * Desde este metodo envia las tramas al Gateway.
dixysleo 0:58e350255405 832 */
dixysleo 0:58e350255405 833 void m_status_check_handle(void)
Gustavo_Eduardo338 4:a43cbe8aed6a 834 {
Gustavo_Eduardo338 5:a8c07a29df8a 835
Gustavo_Eduardo338 10:5580ae8cbe7e 836 uint8_t TRAMA_CONFIG_ANALOG[5];
Gustavo_Eduardo338 10:5580ae8cbe7e 837 uint8_t LECTURA_DIGITAL[6];
Gustavo_Eduardo338 11:965d5afe3a63 838 uint8_t LECTURA_ANALOGICA[6];
Gustavo_Eduardo338 7:fb4c6c1dd3a9 839
Gustavo_Eduardo338 7:fb4c6c1dd3a9 840 //pc.printf("enviar_config %d \r\n", enviar_config_01);
Gustavo_Eduardo338 10:5580ae8cbe7e 841 if (SEND_CONFIG_GENERAL == 1) {
Gustavo_Eduardo338 7:fb4c6c1dd3a9 842 // Envia la configuracion Genaral del Mote.
Gustavo_Eduardo338 10:5580ae8cbe7e 843 pc.printf("TRAMA_CONFIG_GENERAL0 %d \r\n", TRAMA_CONFIG_GENERAL[0]);
Gustavo_Eduardo338 10:5580ae8cbe7e 844 pc.printf("TRAMA_CONFIG_GENERAL1 %d \r\n", TRAMA_CONFIG_GENERAL[1]);
Gustavo_Eduardo338 10:5580ae8cbe7e 845 pc.printf("SEND_CONFIG_GENERAL %d \r\n", SEND_CONFIG_GENERAL);
Gustavo_Eduardo338 10:5580ae8cbe7e 846 ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), TRAMA_CONFIG_GENERAL, 12);
Gustavo_Eduardo338 7:fb4c6c1dd3a9 847 }
Gustavo_Eduardo338 9:501a9e6710d2 848
Gustavo_Eduardo338 10:5580ae8cbe7e 849 // Envio de las tramas de Configuracion del Mote.
Gustavo_Eduardo338 10:5580ae8cbe7e 850 // -- Configuracion detallada de los sensores.
Gustavo_Eduardo338 10:5580ae8cbe7e 851 // Evalua si se encuentra pendiente enviar la configuracion de los sensores.
Gustavo_Eduardo338 10:5580ae8cbe7e 852 if (SEND_CONFIG_ANALOG_0 == ON||SEND_CONFIG_ANALOG_1 == ON||SEND_CONFIG_ANALOG_2 == ON||SEND_CONFIG_ANALOG_3 == ON||SEND_CONFIG_ANALOG_4 == ON||SEND_CONFIG_ANALOG_5 == ON) {
Gustavo_Eduardo338 10:5580ae8cbe7e 853
Gustavo_Eduardo338 10:5580ae8cbe7e 854 TRAMA_CONFIG_ANALOG[0] = (0xC2); // Codigo que indica que la configuracion sera por cada Pin.
Gustavo_Eduardo338 10:5580ae8cbe7e 855 TRAMA_CONFIG_ANALOG[1] = (0x05); // Categoria puede ser: A (Actuador) | 5 (Sensor)
Gustavo_Eduardo338 10:5580ae8cbe7e 856 TRAMA_CONFIG_ANALOG[2] = (0xAA); // Tipo de Signal AA | DD
Gustavo_Eduardo338 7:fb4c6c1dd3a9 857
Gustavo_Eduardo338 10:5580ae8cbe7e 858 if (A0_USO == ON && SEND_CONFIG_ANALOG_0 == ON) {
Gustavo_Eduardo338 10:5580ae8cbe7e 859 TRAMA_CONFIG_ANALOG[3] = 0x00; // Posicion que ocupa en el mote
Gustavo_Eduardo338 11:965d5afe3a63 860 int16_t TED_PF = (int16_t) (256 * A0_TED); // Conversion Punto Fijo
Gustavo_Eduardo338 11:965d5afe3a63 861 TRAMA_CONFIG_ANALOG[4] = (int8_t)(TED_PF >> 8);
Gustavo_Eduardo338 11:965d5afe3a63 862 TRAMA_CONFIG_ANALOG[5] = (int8_t)(TED_PF);
Gustavo_Eduardo338 10:5580ae8cbe7e 863 pc.printf("SEND_CONFIG_ANALOG_0 \r\n");
Gustavo_Eduardo338 11:965d5afe3a63 864 ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), TRAMA_CONFIG_ANALOG, 6);
Gustavo_Eduardo338 10:5580ae8cbe7e 865
Gustavo_Eduardo338 10:5580ae8cbe7e 866 } else if (A1_USO == ON && SEND_CONFIG_ANALOG_1 == ON) {
Gustavo_Eduardo338 10:5580ae8cbe7e 867 TRAMA_CONFIG_ANALOG[3] = 0x01; // Posicion que ocupa en el mote
Gustavo_Eduardo338 11:965d5afe3a63 868 int16_t TED_PF = (int16_t) (256 * A1_TED); // Conversion Punto Fijo
Gustavo_Eduardo338 11:965d5afe3a63 869 TRAMA_CONFIG_ANALOG[4] = (int8_t)(TED_PF >> 8);
Gustavo_Eduardo338 11:965d5afe3a63 870 TRAMA_CONFIG_ANALOG[5] = (int8_t)(TED_PF);
Gustavo_Eduardo338 10:5580ae8cbe7e 871 pc.printf("SEND_CONFIG_ANALOG_1 \r\n");
Gustavo_Eduardo338 11:965d5afe3a63 872 ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), TRAMA_CONFIG_ANALOG, 6);
Gustavo_Eduardo338 9:501a9e6710d2 873
Gustavo_Eduardo338 10:5580ae8cbe7e 874 } else if (A2_USO == ON && SEND_CONFIG_ANALOG_2 == ON) {
Gustavo_Eduardo338 10:5580ae8cbe7e 875 TRAMA_CONFIG_ANALOG[3] = 0x02; // Posicion que ocupa en el mote
Gustavo_Eduardo338 11:965d5afe3a63 876 int16_t TED_PF = (int16_t) (256 * A2_TED); // Conversion Punto Fijo
Gustavo_Eduardo338 11:965d5afe3a63 877 TRAMA_CONFIG_ANALOG[4] = (int8_t)(TED_PF >> 8);
Gustavo_Eduardo338 11:965d5afe3a63 878 TRAMA_CONFIG_ANALOG[5] = (int8_t)(TED_PF);
Gustavo_Eduardo338 10:5580ae8cbe7e 879 pc.printf("SEND_CONFIG_ANALOG_2 \r\n");
Gustavo_Eduardo338 11:965d5afe3a63 880 ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), TRAMA_CONFIG_ANALOG, 6);
Gustavo_Eduardo338 10:5580ae8cbe7e 881
Gustavo_Eduardo338 10:5580ae8cbe7e 882 } else if (A3_USO == ON && SEND_CONFIG_ANALOG_3 == ON) {
Gustavo_Eduardo338 10:5580ae8cbe7e 883 TRAMA_CONFIG_ANALOG[3] = 0x03; // Posicion que ocupa en el mote
Gustavo_Eduardo338 11:965d5afe3a63 884 int16_t TED_PF = (int16_t) (256 * A3_TED); // Conversion Punto Fijo
Gustavo_Eduardo338 11:965d5afe3a63 885 TRAMA_CONFIG_ANALOG[4] = (int8_t)(TED_PF >> 8);
Gustavo_Eduardo338 11:965d5afe3a63 886 TRAMA_CONFIG_ANALOG[5] = (int8_t)(TED_PF);
Gustavo_Eduardo338 10:5580ae8cbe7e 887 pc.printf("SEND_CONFIG_ANALOG_3 \r\n");
Gustavo_Eduardo338 11:965d5afe3a63 888 ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), TRAMA_CONFIG_ANALOG, 6);
Gustavo_Eduardo338 7:fb4c6c1dd3a9 889
Gustavo_Eduardo338 10:5580ae8cbe7e 890 } else if (A4_USO == ON && SEND_CONFIG_ANALOG_4 == ON) {
Gustavo_Eduardo338 10:5580ae8cbe7e 891 TRAMA_CONFIG_ANALOG[3] = 0x04; // Posicion que ocupa en el mote
Gustavo_Eduardo338 11:965d5afe3a63 892 int16_t TED_PF = (int16_t) (256 * A4_TED); // Conversion Punto Fijo
Gustavo_Eduardo338 11:965d5afe3a63 893 TRAMA_CONFIG_ANALOG[4] = (int8_t)(TED_PF >> 8);
Gustavo_Eduardo338 11:965d5afe3a63 894 TRAMA_CONFIG_ANALOG[5] = (int8_t)(TED_PF);
Gustavo_Eduardo338 10:5580ae8cbe7e 895 pc.printf("SEND_CONFIG_ANALOG_4 \r\n");
Gustavo_Eduardo338 11:965d5afe3a63 896 ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), TRAMA_CONFIG_ANALOG, 6);
Gustavo_Eduardo338 9:501a9e6710d2 897
Gustavo_Eduardo338 10:5580ae8cbe7e 898 } else if (A5_USO == ON && SEND_CONFIG_ANALOG_5 == ON) {
Gustavo_Eduardo338 10:5580ae8cbe7e 899 TRAMA_CONFIG_ANALOG[3] = 0x05; // Posicion que ocupa en el mote
Gustavo_Eduardo338 11:965d5afe3a63 900 int16_t TED_PF = (int16_t) (256 * A5_TED); // Conversion Punto Fijo
Gustavo_Eduardo338 11:965d5afe3a63 901 TRAMA_CONFIG_ANALOG[4] = (int8_t)(TED_PF >> 8);
Gustavo_Eduardo338 11:965d5afe3a63 902 TRAMA_CONFIG_ANALOG[5] = (int8_t)(TED_PF);
Gustavo_Eduardo338 11:965d5afe3a63 903 //pc.printf("SEND_CONFIG_ANALOG_5 %x , %x \r\n", TRAMA_CONFIG_ANALOG[4], TRAMA_CONFIG_ANALOG[5]);
Gustavo_Eduardo338 11:965d5afe3a63 904 //pc.printf("SEND_CONFIG_ANALOG_6 %x, %x, %x, %x, %x, %x, %x \r\n", TRAMA_CONFIG_ANALOG[0], TRAMA_CONFIG_ANALOG[1], TRAMA_CONFIG_ANALOG[2], TRAMA_CONFIG_ANALOG[3], TRAMA_CONFIG_ANALOG[4], TRAMA_CONFIG_ANALOG[5], TRAMA_CONFIG_ANALOG[6] );
Gustavo_Eduardo338 11:965d5afe3a63 905 ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), TRAMA_CONFIG_ANALOG, 6);
Gustavo_Eduardo338 10:5580ae8cbe7e 906 }
Gustavo_Eduardo338 7:fb4c6c1dd3a9 907 }
Gustavo_Eduardo338 9:501a9e6710d2 908
Gustavo_Eduardo338 10:5580ae8cbe7e 909 // Envio de las tramas de lecturas del Mote.
Gustavo_Eduardo338 10:5580ae8cbe7e 910 // -- Envio las lecturas digitales
Gustavo_Eduardo338 10:5580ae8cbe7e 911 if (PAQUETE_ID != 0) {
Gustavo_Eduardo338 10:5580ae8cbe7e 912 PAQUETE_ID = 0;
Gustavo_Eduardo338 10:5580ae8cbe7e 913 readDigitalInputs_Value(); // Leemos los estados digitales.
Gustavo_Eduardo338 7:fb4c6c1dd3a9 914
Gustavo_Eduardo338 10:5580ae8cbe7e 915 LECTURA_DIGITAL[0] = (0xDD); // Codigo
Gustavo_Eduardo338 10:5580ae8cbe7e 916 LECTURA_DIGITAL[1] = PAQUETE_ID; // paquete id
Gustavo_Eduardo338 10:5580ae8cbe7e 917 LECTURA_DIGITAL[2] = PAQUETE_ID; // paquete id
Gustavo_Eduardo338 10:5580ae8cbe7e 918 LECTURA_DIGITAL[3] = 0xDD; // A1| A0| D1| D0
Gustavo_Eduardo338 10:5580ae8cbe7e 919 LECTURA_DIGITAL[4] = DigitalInput_DATA; // Posicion
Gustavo_Eduardo338 10:5580ae8cbe7e 920 pc.printf("Envio LECTURA_DIGITAL \r\n"); // Imprimo en terminal lo que esta enviando desde el mote.
Gustavo_Eduardo338 10:5580ae8cbe7e 921
Gustavo_Eduardo338 10:5580ae8cbe7e 922 ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), LECTURA_DIGITAL, 5); // Para el RTD
Gustavo_Eduardo338 7:fb4c6c1dd3a9 923 }
Gustavo_Eduardo338 9:501a9e6710d2 924
Gustavo_Eduardo338 7:fb4c6c1dd3a9 925
Gustavo_Eduardo338 10:5580ae8cbe7e 926 // If digital in changes, report the state
Gustavo_Eduardo338 11:965d5afe3a63 927 // original
Gustavo_Eduardo338 11:965d5afe3a63 928 //if ((BUTTON_2 != state_button_2 && D2_TYPE == IN) || (BUTTON_3 != state_button_3 && D3_TYPE == IN) || (BUTTON_4 != state_button_4 && D4_TYPE == IN) || (BUTTON_5 != state_button_5 && D5_TYPE == IN) || (BUTTON_6 != state_button_6 && D6_TYPE == IN) || (BUTTON_7 != state_button_7 && D7_TYPE == IN) || (BUTTON_8 != state_button_8 && D8_TYPE == IN) || (BUTTON_9 != state_button_9 && D9_TYPE == IN) || (BUTTON_10 != state_button_10 && D10_TYPE == IN) || (BUTTON_11 != state_button_11 && D11_TYPE == IN) || (BUTTON_12 != state_button_12 && D12_TYPE == IN) || (BUTTON_13 != state_button_13 && D13_TYPE == IN) || (BUTTON_14 != state_button_14 && D14_TYPE == IN) || (BUTTON_15 != state_button_15 && D15_TYPE == IN)) {
Gustavo_Eduardo338 11:965d5afe3a63 929 if ((PIN_D2 != state_button_2 && D2_TYPE == IN) || (PIN_D3 != state_button_3 && D3_TYPE == IN) || (PIN_D4 != state_button_4 && D4_TYPE == IN) || (PIN_D5 != state_button_5 && D5_TYPE == IN) || (PIN_D6 != state_button_6 && D6_TYPE == IN) || (PIN_D7 != state_button_7 && D7_TYPE == IN) || (PIN_D8 != state_button_8 && D8_TYPE == IN) || (PIN_D9 != state_button_9 && D9_TYPE == IN) || (PIN_D10 != state_button_10 && D10_TYPE == IN) || (PIN_D11 != state_button_11 && D11_TYPE == IN) || (PIN_D12 != state_button_12 && D12_TYPE == IN) || (PIN_D13 != state_button_13 && D13_TYPE == IN) || (PIN_D14 != state_button_14 && D14_TYPE == IN) || (PIN_D15 != state_button_15 && D15_TYPE == IN)) {
Gustavo_Eduardo338 10:5580ae8cbe7e 930 // Lecturas digitales
Gustavo_Eduardo338 10:5580ae8cbe7e 931 readDigitalInputs_Value();
Gustavo_Eduardo338 10:5580ae8cbe7e 932 // Actualizando estados de las variables auxiliares
Gustavo_Eduardo338 11:965d5afe3a63 933 state_button_2 = (D2_USO == ON && D2_TYPE == IN) ? PIN_D2 : 0;
Gustavo_Eduardo338 11:965d5afe3a63 934 state_button_3 = (D3_USO == ON && D3_TYPE == IN) ? PIN_D3 : 0;
Gustavo_Eduardo338 11:965d5afe3a63 935 state_button_4 = (D4_USO == ON && D4_TYPE == IN) ? PIN_D4 : 0;
Gustavo_Eduardo338 11:965d5afe3a63 936 state_button_5 = (D5_USO == ON && D5_TYPE == IN) ? PIN_D5 : 0;
Gustavo_Eduardo338 11:965d5afe3a63 937 state_button_6 = (D6_USO == ON && D6_TYPE == IN) ? PIN_D6 : 0;
Gustavo_Eduardo338 11:965d5afe3a63 938 state_button_7 = (D7_USO == ON && D7_TYPE == IN) ? PIN_D7 : 0;
Gustavo_Eduardo338 11:965d5afe3a63 939 state_button_8 = (D8_USO == ON && D8_TYPE == IN) ? PIN_D8 : 0;
Gustavo_Eduardo338 11:965d5afe3a63 940 state_button_9 = (D9_USO == ON && D9_TYPE == IN) ? PIN_D9 : 0;
Gustavo_Eduardo338 11:965d5afe3a63 941 state_button_10 = (D10_USO == ON && D10_TYPE == IN) ? PIN_D10:0;
Gustavo_Eduardo338 11:965d5afe3a63 942 state_button_11 = (D11_USO == ON && D11_TYPE == IN) ? PIN_D11:0;
Gustavo_Eduardo338 11:965d5afe3a63 943 state_button_12 = (D12_USO == ON && D12_TYPE == IN) ? PIN_D12:0;
Gustavo_Eduardo338 11:965d5afe3a63 944 state_button_13 = (D13_USO == ON && D13_TYPE == IN) ? PIN_D13:0;
Gustavo_Eduardo338 11:965d5afe3a63 945 state_button_14 = (D14_USO == ON && D14_TYPE == IN) ? PIN_D14:0;
Gustavo_Eduardo338 11:965d5afe3a63 946 state_button_15 = (D15_USO == ON && D15_TYPE == IN) ? PIN_D15:0;
Gustavo_Eduardo338 10:5580ae8cbe7e 947
Gustavo_Eduardo338 10:5580ae8cbe7e 948 PAQUETE_ID = 0x3E8;
Gustavo_Eduardo338 11:965d5afe3a63 949 pc.printf("ESTADO_ENTRADAS_DIGITALES: %d \r\n", ESTADO_ENTRADAS_DIGITALES);
Gustavo_Eduardo338 10:5580ae8cbe7e 950 LECTURA_DIGITAL[0] = 0xDD; // Codigo
Gustavo_Eduardo338 10:5580ae8cbe7e 951 LECTURA_DIGITAL[1] = (PAQUETE_ID >> 8); // primera parte del paquete
Gustavo_Eduardo338 10:5580ae8cbe7e 952 LECTURA_DIGITAL[2] = PAQUETE_ID ; // segunda parte del paquete
Gustavo_Eduardo338 11:965d5afe3a63 953 LECTURA_DIGITAL[3] = 0xD0; // D0 --> Digital Output
Gustavo_Eduardo338 11:965d5afe3a63 954 LECTURA_DIGITAL[4] = (ESTADO_ENTRADAS_DIGITALES >> 8); // Valor de las salidas digitales
Gustavo_Eduardo338 11:965d5afe3a63 955 LECTURA_DIGITAL[5] = (ESTADO_ENTRADAS_DIGITALES); // Valor de las salidas digitales
Gustavo_Eduardo338 10:5580ae8cbe7e 956
Gustavo_Eduardo338 10:5580ae8cbe7e 957 ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), LECTURA_DIGITAL, 6); // Para el RTD
Gustavo_Eduardo338 7:fb4c6c1dd3a9 958 }
Gustavo_Eduardo338 9:501a9e6710d2 959
Gustavo_Eduardo338 11:965d5afe3a63 960 // Envio de las tramas de las lecturas de los sensores habilitados.
Gustavo_Eduardo338 11:965d5afe3a63 961 if (SEND_CONFIG_GENERAL == 0) {
Gustavo_Eduardo338 8:c4130ea78471 962
Gustavo_Eduardo338 11:965d5afe3a63 963 LECTURA_ANALOGICA[0] = 0xDD; // Codigo
Gustavo_Eduardo338 11:965d5afe3a63 964 LECTURA_ANALOGICA[1] = 0x00; // paquete id
Gustavo_Eduardo338 11:965d5afe3a63 965 LECTURA_ANALOGICA[2] = 0x00; // paquete id
Gustavo_Eduardo338 11:965d5afe3a63 966
Gustavo_Eduardo338 11:965d5afe3a63 967
Gustavo_Eduardo338 11:965d5afe3a63 968 // Si la configuracion ha sido enviada, envio las lecturas. Esta para cumplir con una secuencia.
Gustavo_Eduardo338 11:965d5afe3a63 969 if (A5_USO == ON) {
Gustavo_Eduardo338 11:965d5afe3a63 970 float s = ANALOG_A5.read();
Gustavo_Eduardo338 11:965d5afe3a63 971 if ( value_A5 != s) {
Gustavo_Eduardo338 11:965d5afe3a63 972 value_A5 = s;
Gustavo_Eduardo338 11:965d5afe3a63 973
Gustavo_Eduardo338 11:965d5afe3a63 974 uint16_t value = s * 1024;
Gustavo_Eduardo338 11:965d5afe3a63 975
Gustavo_Eduardo338 11:965d5afe3a63 976
Gustavo_Eduardo338 11:965d5afe3a63 977 float Vtemp = value * 0.0032080078125;
Gustavo_Eduardo338 11:965d5afe3a63 978 float Rtemp = (15111 / Vtemp) - 4630;
Gustavo_Eduardo338 11:965d5afe3a63 979 float Tempfinal = ((Rtemp - 1000) / 3.850);
Gustavo_Eduardo338 11:965d5afe3a63 980
Gustavo_Eduardo338 11:965d5afe3a63 981 //2- Conversion flotante a punto fijo
Gustavo_Eduardo338 11:965d5afe3a63 982 int16_t Temperature_PF = (int16_t) (256 * Tempfinal);
Gustavo_Eduardo338 9:501a9e6710d2 983
Gustavo_Eduardo338 11:965d5afe3a63 984 LECTURA_ANALOGICA[3] = 0xA1; // --> Analog Output (A0)
Gustavo_Eduardo338 11:965d5afe3a63 985 LECTURA_ANALOGICA[4] = 0x05; // --> Posicion del sensor
Gustavo_Eduardo338 11:965d5afe3a63 986 LECTURA_ANALOGICA[5] = (int8_t)(Temperature_PF >> 8);
Gustavo_Eduardo338 11:965d5afe3a63 987 LECTURA_ANALOGICA[6] = (int8_t)(Temperature_PF);
Gustavo_Eduardo338 11:965d5afe3a63 988
Gustavo_Eduardo338 11:965d5afe3a63 989 pc.printf("Temperature_PF (Format HEX): %x \r\n", Temperature_PF);
Gustavo_Eduardo338 11:965d5afe3a63 990 ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), LECTURA_ANALOGICA, 7); // Para el RTD
Gustavo_Eduardo338 11:965d5afe3a63 991 }
Gustavo_Eduardo338 11:965d5afe3a63 992
Gustavo_Eduardo338 11:965d5afe3a63 993
Gustavo_Eduardo338 11:965d5afe3a63 994 }
Gustavo_Eduardo338 11:965d5afe3a63 995 }
Gustavo_Eduardo338 11:965d5afe3a63 996 }
Gustavo_Eduardo338 9:501a9e6710d2 997
Gustavo_Eduardo338 11:965d5afe3a63 998 void apagarLeds()
Gustavo_Eduardo338 11:965d5afe3a63 999 {
Gustavo_Eduardo338 11:965d5afe3a63 1000 // SOLO PARA NRF51822
Gustavo_Eduardo338 11:965d5afe3a63 1001 if (D3_TYPE == OUT && D3_USO == ON){
Gustavo_Eduardo338 11:965d5afe3a63 1002 PIN_D3 = 0;
Gustavo_Eduardo338 11:965d5afe3a63 1003 }
Gustavo_Eduardo338 11:965d5afe3a63 1004 if (D4_TYPE == OUT && D4_USO == ON){
Gustavo_Eduardo338 11:965d5afe3a63 1005 PIN_D4 = 1;
Gustavo_Eduardo338 11:965d5afe3a63 1006 }
Gustavo_Eduardo338 11:965d5afe3a63 1007 if (D5_TYPE == OUT && D5_USO == ON){
Gustavo_Eduardo338 11:965d5afe3a63 1008 PIN_D5 = 1;
Gustavo_Eduardo338 11:965d5afe3a63 1009 }
Gustavo_Eduardo338 11:965d5afe3a63 1010 if (D6_TYPE == OUT && D6_USO == ON){
Gustavo_Eduardo338 11:965d5afe3a63 1011 PIN_D6 = 0;
Gustavo_Eduardo338 11:965d5afe3a63 1012 }
dixysleo 0:58e350255405 1013 }
dixysleo 0:58e350255405 1014
dixysleo 0:58e350255405 1015 int main(void)
Gustavo_Eduardo338 4:a43cbe8aed6a 1016 {
dixysleo 0:58e350255405 1017 Ticker ticker;
dixysleo 0:58e350255405 1018 ticker.attach_us(m_status_check_handle, 200000);
Gustavo_Eduardo338 4:a43cbe8aed6a 1019
dixysleo 0:58e350255405 1020 ble.init();
dixysleo 0:58e350255405 1021 ble.onDisconnection(disconnectionCallback);
Gustavo_Eduardo338 5:a8c07a29df8a 1022 ble.onConnection(connectionCallback);
Gustavo_Eduardo338 4:a43cbe8aed6a 1023 ble.onDataWritten(WrittenHandler);
Gustavo_Eduardo338 4:a43cbe8aed6a 1024
dixysleo 0:58e350255405 1025 pc.baud(9600);
dixysleo 0:58e350255405 1026 pc.printf("SimpleChat Init \r\n");
dixysleo 0:58e350255405 1027 //pc.attach( uartCB , pc.RxIrq);
Gustavo_Eduardo338 4:a43cbe8aed6a 1028
Gustavo_Eduardo338 4:a43cbe8aed6a 1029 // setup advertising
dixysleo 0:58e350255405 1030 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
dixysleo 0:58e350255405 1031 ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
Gustavo_Eduardo338 11:965d5afe3a63 1032 ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, (const uint8_t *)"Biscuit2", sizeof("Biscuit2") - 1); // Original: Biscuit
Gustavo_Eduardo338 10:5580ae8cbe7e 1033 ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid));
Gustavo_Eduardo338 10:5580ae8cbe7e 1034
dixysleo 0:58e350255405 1035 ble.setAdvertisingInterval(160);
dixysleo 0:58e350255405 1036
dixysleo 0:58e350255405 1037 ble.addService(uartService);
Gustavo_Eduardo338 4:a43cbe8aed6a 1038
Gustavo_Eduardo338 4:a43cbe8aed6a 1039 ble.startAdvertising();
dixysleo 0:58e350255405 1040 pc.printf("Advertising Start \r\n");
Gustavo_Eduardo338 11:965d5afe3a63 1041 apagarLeds();
dixysleo 0:58e350255405 1042 //por dixys
dixysleo 0:58e350255405 1043 // para probar, luego quitar. Esto hace que cada ticker se envie un dato analogico via BLE
Gustavo_Eduardo338 5:a8c07a29df8a 1044 analog_enabled = 0;
Gustavo_Eduardo338 4:a43cbe8aed6a 1045
Gustavo_Eduardo338 11:965d5afe3a63 1046 // valores refernenciales para los estados de los sensores.
Gustavo_Eduardo338 11:965d5afe3a63 1047 value_A0 = ANALOG_A0;
Gustavo_Eduardo338 11:965d5afe3a63 1048 value_A1 = ANALOG_A1;
Gustavo_Eduardo338 11:965d5afe3a63 1049 value_A2 = ANALOG_A2;
Gustavo_Eduardo338 11:965d5afe3a63 1050 value_A3 = ANALOG_A3;
Gustavo_Eduardo338 11:965d5afe3a63 1051 value_A4 = ANALOG_A4;
Gustavo_Eduardo338 11:965d5afe3a63 1052 value_A5 = ANALOG_A5.read();
Gustavo_Eduardo338 11:965d5afe3a63 1053
Gustavo_Eduardo338 4:a43cbe8aed6a 1054 while(1) {
Gustavo_Eduardo338 4:a43cbe8aed6a 1055 ble.waitForEvent();
dixysleo 0:58e350255405 1056 }
Gustavo_Eduardo338 4:a43cbe8aed6a 1057 }