Proyecto ABInBev para la tarjeta Guaria 1/2.

Committer:
fmanzano_dtk
Date:
Fri Jul 01 21:49:26 2022 -0600
Revision:
4:9b1a4a9b2cdf
Parent:
3:6e55713bc91d
Child:
5:07720e3f99d2
Se agrega libreria para nuevo sensor

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fmanzano_dtk 2:1ef167d1b7b8 1 /**
fmanzano_dtk 2:1ef167d1b7b8 2 * @file main.cpp
fmanzano_dtk 2:1ef167d1b7b8 3 * @author Felícito Manzano (felicito.manzano@detektor.com.sv)
fmanzano_dtk 2:1ef167d1b7b8 4 * @brief
fmanzano_dtk 2:1ef167d1b7b8 5 * Proyecto para ABInBev Cervecería Nacional de Panamá, incluye el soporte
fmanzano_dtk 2:1ef167d1b7b8 6 * para para 5 entradas digitales, conexión vía Bluetooth SPP con equipo
fmanzano_dtk 2:1ef167d1b7b8 7 * Teltonika FMU130 para el envío y recepción de mensajes al servidor
fmanzano_dtk 2:1ef167d1b7b8 8 * del ecosistema Detektor, también incluye un puerto serial TTL para
fmanzano_dtk 2:1ef167d1b7b8 9 * controlar el módulo de voz JQ8400, puerto serial para el lector de
fmanzano_dtk 2:1ef167d1b7b8 10 * huellas GT521Fx y puerto serial RS232 con el sensor de lluvia RG9.
fmanzano_dtk 2:1ef167d1b7b8 11 * @version 0.1
fmanzano_dtk 2:1ef167d1b7b8 12 * @date 2020-09-26
fmanzano_dtk 2:1ef167d1b7b8 13 *
fmanzano_dtk 2:1ef167d1b7b8 14 * @copyright Copyright (c) 2020
fmanzano_dtk 2:1ef167d1b7b8 15 *
fmanzano_dtk 0:2d7ac38345d8 16 */
fmanzano_dtk 0:2d7ac38345d8 17
fmanzano_dtk 0:2d7ac38345d8 18 #include "mbed.h"
fmanzano_dtk 0:2d7ac38345d8 19 #include "platform/mbed_thread.h"
fmanzano_dtk 2:1ef167d1b7b8 20 #include "stm32f4xx_hal_iwdg.h"
fmanzano_dtk 2:1ef167d1b7b8 21 #include "BufferedSerial.h"
fmanzano_dtk 2:1ef167d1b7b8 22 #include "ics5_pinout.hpp"
fmanzano_dtk 2:1ef167d1b7b8 23 #include "jq8400_voice.hpp"
fmanzano_dtk 2:1ef167d1b7b8 24 #include "voice_cn_pa.hpp"
fmanzano_dtk 2:1ef167d1b7b8 25 #include "New_GT521Fx.hpp"
fmanzano_dtk 2:1ef167d1b7b8 26 #include "gpio_exe.hpp"
fmanzano_dtk 2:1ef167d1b7b8 27 #include "fmu130_exe.hpp"
fmanzano_dtk 2:1ef167d1b7b8 28 #include "fingerprint_exe.hpp"
fmanzano_dtk 2:1ef167d1b7b8 29 #include "playlist_exe.hpp"
fmanzano_dtk 2:1ef167d1b7b8 30 #include "playlist.hpp"
fmanzano_dtk 2:1ef167d1b7b8 31 #include "teltonika_fmu130.hpp"
fmanzano_dtk 2:1ef167d1b7b8 32 #include "fireup_exe.hpp"
fmanzano_dtk 2:1ef167d1b7b8 33 #include "safety_tip_exe.hpp"
fmanzano_dtk 2:1ef167d1b7b8 34 #include "eeprom.h"
fmanzano_dtk 3:6e55713bc91d 35 #include "flash_exe.hpp"
fmanzano_dtk 2:1ef167d1b7b8 36 #include "USBSerial.h"
fmanzano_dtk 2:1ef167d1b7b8 37 #include <ctype.h>
fmanzano_dtk 2:1ef167d1b7b8 38
fmanzano_dtk 2:1ef167d1b7b8 39 /**
fmanzano_dtk 2:1ef167d1b7b8 40 * INTERFACES:
fmanzano_dtk 2:1ef167d1b7b8 41 * Se utiliza la librería ICS5_Pinout para hacer el cambio de pines
fmanzano_dtk 2:1ef167d1b7b8 42 * en base a la tarjeta para la que se compilará. Se tiene soporte para
fmanzano_dtk 2:1ef167d1b7b8 43 * las tarjetas NUCLEO F303K8, NUCLEO F091RC, ICS3 e ICS5.
fmanzano_dtk 2:1ef167d1b7b8 44 */
fmanzano_dtk 3:6e55713bc91d 45 #define M_DEBUG 1
fmanzano_dtk 2:1ef167d1b7b8 46
fmanzano_dtk 2:1ef167d1b7b8 47 #if (ICS_BOARD_ID == 11)
fmanzano_dtk 2:1ef167d1b7b8 48 // Serial
fmanzano_dtk 2:1ef167d1b7b8 49 BufferedSerial avl_uart(BLE_TX, BLE_RX, 1024, 2); //! UART TTL para enlace con el equipo Teltonika FMU130.
fmanzano_dtk 2:1ef167d1b7b8 50 BufferedSerial voice_uart(TTL_VOICE_TX, TTL_VOICE_RX); //! UART TTL para comunicación con el módulo de voz JQ8400.
fmanzano_dtk 2:1ef167d1b7b8 51 BufferedSerial fingerprint(TTL_TX, TTL_RX);
fmanzano_dtk 3:6e55713bc91d 52 #ifdef M_DEBUG
fmanzano_dtk 2:1ef167d1b7b8 53 USBSerial myPC_debug;
fmanzano_dtk 2:1ef167d1b7b8 54 #endif
fmanzano_dtk 2:1ef167d1b7b8 55
fmanzano_dtk 2:1ef167d1b7b8 56 // PCB Support
fmanzano_dtk 2:1ef167d1b7b8 57 InterruptIn mybutton(USER_BUTTON);
fmanzano_dtk 2:1ef167d1b7b8 58 DigitalIn bluetooth_state(BT_STATE);
fmanzano_dtk 2:1ef167d1b7b8 59 DigitalOut myled(USER_LED1);
fmanzano_dtk 2:1ef167d1b7b8 60 DigitalOut flashLED(USER_LED2);
fmanzano_dtk 2:1ef167d1b7b8 61 DigitalOut out2_ble_reset(BT_RESET);
fmanzano_dtk 2:1ef167d1b7b8 62
fmanzano_dtk 2:1ef167d1b7b8 63 // Outputs
fmanzano_dtk 2:1ef167d1b7b8 64 DigitalOut out1_fingerprint(OUTPUT1_NEGATIVE);
fmanzano_dtk 2:1ef167d1b7b8 65 DigitalOut out3_gt521fx(OUTPUT2_NEGATIVE);
fmanzano_dtk 2:1ef167d1b7b8 66 DigitalOut out4_gt521fx(OUTPUT3_NEGATIVE);
fmanzano_dtk 2:1ef167d1b7b8 67
fmanzano_dtk 2:1ef167d1b7b8 68 // Inputs
fmanzano_dtk 2:1ef167d1b7b8 69 DigitalIn in1_ignition(INPUT1_POSITIVE);
fmanzano_dtk 2:1ef167d1b7b8 70 DigitalIn in2_pilot(INPUT2_NEGATIVE);
fmanzano_dtk 2:1ef167d1b7b8 71 DigitalIn in3_copilot(INPUT3_NEGATIVE);
fmanzano_dtk 2:1ef167d1b7b8 72 DigitalIn in4_crew(INPUT4_NEGATIVE);
fmanzano_dtk 2:1ef167d1b7b8 73 DigitalIn in5_rain_sensor(INPUT5_NEGATIVE);
fmanzano_dtk 2:1ef167d1b7b8 74 #endif
fmanzano_dtk 2:1ef167d1b7b8 75
fmanzano_dtk 2:1ef167d1b7b8 76 // EEPROM
fmanzano_dtk 2:1ef167d1b7b8 77 EEPROM ep(I2C_SDA_EE, I2C_SCL_EE, 0x0, EEPROM::T24C32);
fmanzano_dtk 2:1ef167d1b7b8 78 int32_t eeprom_size,max_size;
fmanzano_dtk 2:1ef167d1b7b8 79 #define EEPROM_ADDR 0x0
fmanzano_dtk 2:1ef167d1b7b8 80 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
fmanzano_dtk 2:1ef167d1b7b8 81 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
fmanzano_dtk 2:1ef167d1b7b8 82 typedef struct _MyData {
fmanzano_dtk 2:1ef167d1b7b8 83 int16_t sdata;
fmanzano_dtk 2:1ef167d1b7b8 84 int32_t idata;
fmanzano_dtk 2:1ef167d1b7b8 85 float fdata;
fmanzano_dtk 2:1ef167d1b7b8 86 } MyData;
fmanzano_dtk 2:1ef167d1b7b8 87 static void myerror(std::string msg) {
fmanzano_dtk 2:1ef167d1b7b8 88 printf("Error %s\n",msg.c_str());
fmanzano_dtk 2:1ef167d1b7b8 89 exit(1);
fmanzano_dtk 2:1ef167d1b7b8 90 }
fmanzano_dtk 2:1ef167d1b7b8 91
fmanzano_dtk 2:1ef167d1b7b8 92
fmanzano_dtk 2:1ef167d1b7b8 93 // VOICE
fmanzano_dtk 2:1ef167d1b7b8 94 queue colaPlaylist(10);
fmanzano_dtk 2:1ef167d1b7b8 95
fmanzano_dtk 2:1ef167d1b7b8 96 // HAL BASED
fmanzano_dtk 2:1ef167d1b7b8 97 static IWDG_HandleTypeDef my_iwdg;
fmanzano_dtk 0:2d7ac38345d8 98
fmanzano_dtk 0:2d7ac38345d8 99
fmanzano_dtk 2:1ef167d1b7b8 100 // FUNCIONALIDADES
fmanzano_dtk 2:1ef167d1b7b8 101 // Nuevas banderas para habilitar/deshabilitar funciones.
fmanzano_dtk 2:1ef167d1b7b8 102 bool functionality_idle_shutdown;
fmanzano_dtk 2:1ef167d1b7b8 103 bool functionality_idle_reminder;
fmanzano_dtk 2:1ef167d1b7b8 104 bool functionality_seatbelt_reading;
fmanzano_dtk 2:1ef167d1b7b8 105 bool functionality_force_driver_buclke;
fmanzano_dtk 2:1ef167d1b7b8 106 bool functionality_rain_sensor;
fmanzano_dtk 2:1ef167d1b7b8 107 bool functionality_rainSensor_silentMode;
fmanzano_dtk 2:1ef167d1b7b8 108 bool functionality_fingerprint_reader;
fmanzano_dtk 2:1ef167d1b7b8 109 bool functionality_safety_tip;
fmanzano_dtk 2:1ef167d1b7b8 110 bool functionality_geo_warning;
fmanzano_dtk 2:1ef167d1b7b8 111 bool functionality_ble_autoreset;
fmanzano_dtk 2:1ef167d1b7b8 112 bool fingerprint_remotly_disable;
fmanzano_dtk 2:1ef167d1b7b8 113 bool fingerprint_override;
fmanzano_dtk 2:1ef167d1b7b8 114 bool finterprint_flag_working = false;
fmanzano_dtk 2:1ef167d1b7b8 115 bool fingerprint_flag_poweroff = false;
fmanzano_dtk 2:1ef167d1b7b8 116
fmanzano_dtk 2:1ef167d1b7b8 117 /**
fmanzano_dtk 2:1ef167d1b7b8 118 * BANDERAS:
fmanzano_dtk 2:1ef167d1b7b8 119 * Se utiliza un esquema de banderas para indicar el cambio de un estado
fmanzano_dtk 2:1ef167d1b7b8 120 * y que se debe realizar un procesamiento especial (transmitir un
fmanzano_dtk 2:1ef167d1b7b8 121 * evento, activar un accesorio, etc.)
fmanzano_dtk 2:1ef167d1b7b8 122 */
fmanzano_dtk 2:1ef167d1b7b8 123
fmanzano_dtk 2:1ef167d1b7b8 124 float time_safety_tip; // 15 minutos = 900
fmanzano_dtk 2:1ef167d1b7b8 125 float time_sample_rain; // muestras a 9 equivalen a 90 segundos o minuto y medio.
fmanzano_dtk 2:1ef167d1b7b8 126 float time_ble_autoreset;
fmanzano_dtk 2:1ef167d1b7b8 127 bool flag_rain_no_answer = false;
fmanzano_dtk 2:1ef167d1b7b8 128 bool flag_idle_force_shutdown = false;
fmanzano_dtk 2:1ef167d1b7b8 129 bool flag_idle_reminder = false;
fmanzano_dtk 2:1ef167d1b7b8 130 bool flag_fingerprint_Sleep = false;
fmanzano_dtk 2:1ef167d1b7b8 131 bool flag_driver_loggin = false;
fmanzano_dtk 2:1ef167d1b7b8 132 bool flag_playingSound = false;
fmanzano_dtk 2:1ef167d1b7b8 133 bool flag_safety_tip = false;
fmanzano_dtk 2:1ef167d1b7b8 134 bool rain_sensor_type = false; // True = RS232, False = DIN
fmanzano_dtk 2:1ef167d1b7b8 135 bool flag_query_rain_sensor;
fmanzano_dtk 2:1ef167d1b7b8 136 bool flag_notify_rain_sensor;
fmanzano_dtk 2:1ef167d1b7b8 137 bool flag_read_inputs;
fmanzano_dtk 2:1ef167d1b7b8 138 bool flag_fingerprint_turOn;
fmanzano_dtk 2:1ef167d1b7b8 139 bool flag_fri_ics;
fmanzano_dtk 2:1ef167d1b7b8 140 int flag_fingerprint_query;
fmanzano_dtk 2:1ef167d1b7b8 141 int flag_ignition;
fmanzano_dtk 2:1ef167d1b7b8 142 int flag_pilot_seatbelt;
fmanzano_dtk 2:1ef167d1b7b8 143 int flag_copilot_seatbelt;
fmanzano_dtk 2:1ef167d1b7b8 144 int flag_crew_pilot_seatbelt;
fmanzano_dtk 2:1ef167d1b7b8 145 int flag_ble_connection_state;
fmanzano_dtk 2:1ef167d1b7b8 146 int flag_rainsensorDigInput;
fmanzano_dtk 2:1ef167d1b7b8 147
fmanzano_dtk 2:1ef167d1b7b8 148 /**
fmanzano_dtk 2:1ef167d1b7b8 149 * ENTRADAS:
fmanzano_dtk 2:1ef167d1b7b8 150 * Para la lectura de entradas digitales se utiliza un estructura de 4
fmanzano_dtk 2:1ef167d1b7b8 151 * variables que incluyen el estado actual de la entrada, el estado previo
fmanzano_dtk 2:1ef167d1b7b8 152 * de la entrada, un arreglo de cuatro posiciones para tomar muestras y
fmanzano_dtk 2:1ef167d1b7b8 153 * realizar la función de debug y un contador para indicar la posición en
fmanzano_dtk 2:1ef167d1b7b8 154 * el arreglo para capturar la muestra de la entrada.
fmanzano_dtk 2:1ef167d1b7b8 155 */
fmanzano_dtk 2:1ef167d1b7b8 156 bool ignition;
fmanzano_dtk 2:1ef167d1b7b8 157 bool estado_actual_ignicion;
fmanzano_dtk 2:1ef167d1b7b8 158 bool ignition_prev;
fmanzano_dtk 2:1ef167d1b7b8 159 bool ignition_samples[4];
fmanzano_dtk 2:1ef167d1b7b8 160 int ignition_counter;
fmanzano_dtk 2:1ef167d1b7b8 161
fmanzano_dtk 2:1ef167d1b7b8 162 bool pilot_seatbelt;
fmanzano_dtk 2:1ef167d1b7b8 163 bool pilot_seatbelt_prev;
fmanzano_dtk 2:1ef167d1b7b8 164 bool pilot_seatbelt_samples[4];
fmanzano_dtk 2:1ef167d1b7b8 165 int pilot_seatbelt_c;
fmanzano_dtk 2:1ef167d1b7b8 166
fmanzano_dtk 2:1ef167d1b7b8 167 bool copilot_seatbelt;
fmanzano_dtk 2:1ef167d1b7b8 168 bool copilot_seatbelt_prev;
fmanzano_dtk 2:1ef167d1b7b8 169 bool copilot_seatbelt_samples[4];
fmanzano_dtk 2:1ef167d1b7b8 170 int copilot_seatbelt_c;
fmanzano_dtk 2:1ef167d1b7b8 171
fmanzano_dtk 2:1ef167d1b7b8 172 bool crew_seatbelt;
fmanzano_dtk 2:1ef167d1b7b8 173 bool crew_seatbelt_prev;
fmanzano_dtk 2:1ef167d1b7b8 174 bool crew_seatbelt_samples[4];
fmanzano_dtk 2:1ef167d1b7b8 175 int crew_seatbelt_c;
fmanzano_dtk 2:1ef167d1b7b8 176
fmanzano_dtk 2:1ef167d1b7b8 177 bool ble_connection_state;
fmanzano_dtk 2:1ef167d1b7b8 178 bool ble_connection_state_prev;
fmanzano_dtk 2:1ef167d1b7b8 179 bool ble_connection_state_samples[4];
fmanzano_dtk 2:1ef167d1b7b8 180 int ble_connection_state_samples_c;
fmanzano_dtk 2:1ef167d1b7b8 181
fmanzano_dtk 2:1ef167d1b7b8 182 bool rg9_raining;
fmanzano_dtk 2:1ef167d1b7b8 183 bool rg9_raining_prev;
fmanzano_dtk 2:1ef167d1b7b8 184 bool rg9_raining_samples[10];
fmanzano_dtk 2:1ef167d1b7b8 185 int rg9_raining_samples_c;
fmanzano_dtk 2:1ef167d1b7b8 186
fmanzano_dtk 2:1ef167d1b7b8 187
fmanzano_dtk 2:1ef167d1b7b8 188 /**
fmanzano_dtk 2:1ef167d1b7b8 189 * FMU130:
fmanzano_dtk 2:1ef167d1b7b8 190 * Se definen las variables para recepción de datos del equipo FMU130 vía
fmanzano_dtk 2:1ef167d1b7b8 191 * enlace Bluetooth SPP
fmanzano_dtk 2:1ef167d1b7b8 192 */
fmanzano_dtk 2:1ef167d1b7b8 193 char fmu130_payload[1024];
fmanzano_dtk 2:1ef167d1b7b8 194 int fmu130_payload_type;
fmanzano_dtk 2:1ef167d1b7b8 195 int incoming_bytes;
fmanzano_dtk 2:1ef167d1b7b8 196 int temp_JQ8400_Volume;
fmanzano_dtk 2:1ef167d1b7b8 197
fmanzano_dtk 2:1ef167d1b7b8 198
fmanzano_dtk 2:1ef167d1b7b8 199 /**
fmanzano_dtk 2:1ef167d1b7b8 200 * HUELLAS:
fmanzano_dtk 2:1ef167d1b7b8 201 * Se definen las variables para el procesamiento del módulo lector de
fmanzano_dtk 2:1ef167d1b7b8 202 * huellas conectado a un UART-TTL
fmanzano_dtk 2:1ef167d1b7b8 203 */
fmanzano_dtk 2:1ef167d1b7b8 204 int bluetooth_cmd_id;
fmanzano_dtk 2:1ef167d1b7b8 205 int fingerprint_id;
fmanzano_dtk 2:1ef167d1b7b8 206 int fingerprint_login;
fmanzano_dtk 2:1ef167d1b7b8 207 char fingerprint_hex[997];
fmanzano_dtk 2:1ef167d1b7b8 208 char fingerprint_asc[499];
fmanzano_dtk 2:1ef167d1b7b8 209 char fingerprint_cmd[4];
fmanzano_dtk 0:2d7ac38345d8 210
fmanzano_dtk 0:2d7ac38345d8 211
fmanzano_dtk 2:1ef167d1b7b8 212 /**
fmanzano_dtk 2:1ef167d1b7b8 213 * EVENTOS_TELTONIKA:
fmanzano_dtk 2:1ef167d1b7b8 214 * Se definen las variables para el procesamiento de Tramas del equipo
fmanzano_dtk 2:1ef167d1b7b8 215 * Teltonika FMU130 con eventos como los hábitos de manejo.
fmanzano_dtk 2:1ef167d1b7b8 216 */
fmanzano_dtk 2:1ef167d1b7b8 217 char avl_fmu130_header[2];
fmanzano_dtk 2:1ef167d1b7b8 218 char avl_fmu130_imei[16];
fmanzano_dtk 2:1ef167d1b7b8 219 int avl_fmu130_id;
fmanzano_dtk 2:1ef167d1b7b8 220 int avl_fmu130_status;
fmanzano_dtk 2:1ef167d1b7b8 221
fmanzano_dtk 2:1ef167d1b7b8 222 /**
fmanzano_dtk 2:1ef167d1b7b8 223 * SENSOR DE LLUVIA RG9:
fmanzano_dtk 2:1ef167d1b7b8 224 * Se definen las variables para el procesamiento de tramas del sensor
fmanzano_dtk 2:1ef167d1b7b8 225 * de lluvia HYDREON RG9.
fmanzano_dtk 2:1ef167d1b7b8 226
fmanzano_dtk 2:1ef167d1b7b8 227 bool rg9_raining;
fmanzano_dtk 2:1ef167d1b7b8 228 char rg9_payload[64];
fmanzano_dtk 2:1ef167d1b7b8 229 int rg9_weather_id;
fmanzano_dtk 2:1ef167d1b7b8 230 int rg9_weather_id_prev;
fmanzano_dtk 2:1ef167d1b7b8 231 int rg9_count_noAnser = 0;
fmanzano_dtk 2:1ef167d1b7b8 232 */
fmanzano_dtk 2:1ef167d1b7b8 233
fmanzano_dtk 2:1ef167d1b7b8 234 // Inicialización de variables de Velocidad
fmanzano_dtk 2:1ef167d1b7b8 235 int wet_Speed_Warning;
fmanzano_dtk 2:1ef167d1b7b8 236 int wet_Speed_Limit;
fmanzano_dtk 2:1ef167d1b7b8 237 int dry_Speed_Warning;
fmanzano_dtk 2:1ef167d1b7b8 238 int dry_Speed_Limit;
fmanzano_dtk 2:1ef167d1b7b8 239 char wet_Speed_CMD[30];
fmanzano_dtk 2:1ef167d1b7b8 240 char dry_Speed_CMD[30];
fmanzano_dtk 2:1ef167d1b7b8 241
fmanzano_dtk 2:1ef167d1b7b8 242
fmanzano_dtk 2:1ef167d1b7b8 243 // Fingerprint Override
fmanzano_dtk 2:1ef167d1b7b8 244 int fp_override_limit; // Limite de lecturas fallidas antes de autorizar
fmanzano_dtk 2:1ef167d1b7b8 245 int fp_unauthorized_count = 0;
fmanzano_dtk 2:1ef167d1b7b8 246 int items_queue = 0;
fmanzano_dtk 2:1ef167d1b7b8 247
fmanzano_dtk 2:1ef167d1b7b8 248 // Inicialización de Entradas Digitales para Cinturón de Seguridad
fmanzano_dtk 2:1ef167d1b7b8 249 // Detalle de entradas por cada cinturon
fmanzano_dtk 2:1ef167d1b7b8 250 bool pilot_buckle_type;
fmanzano_dtk 2:1ef167d1b7b8 251 int pilot_buckleUp;
fmanzano_dtk 2:1ef167d1b7b8 252 int pilot_unfasten;
fmanzano_dtk 2:1ef167d1b7b8 253 bool copilot_buckle_type;
fmanzano_dtk 2:1ef167d1b7b8 254 int copilot_buckleUp;
fmanzano_dtk 2:1ef167d1b7b8 255 int copilot_unfasten;
fmanzano_dtk 2:1ef167d1b7b8 256 bool crew_buckle_type;
fmanzano_dtk 2:1ef167d1b7b8 257 int crew_buckleUp;
fmanzano_dtk 2:1ef167d1b7b8 258 int crew_unfasten;
fmanzano_dtk 2:1ef167d1b7b8 259
fmanzano_dtk 2:1ef167d1b7b8 260 /**
fmanzano_dtk 2:1ef167d1b7b8 261 * TICKER DE mbed:
fmanzano_dtk 2:1ef167d1b7b8 262 * Definición de eventos gestionados por eventos temporizados.
fmanzano_dtk 2:1ef167d1b7b8 263 */
fmanzano_dtk 2:1ef167d1b7b8 264 Ticker tick_blink;
fmanzano_dtk 2:1ef167d1b7b8 265 Ticker tick_rain_sensor; // para comunicación vía UART
fmanzano_dtk 2:1ef167d1b7b8 266 Ticker tick_readInputs;
fmanzano_dtk 2:1ef167d1b7b8 267 Ticker tick_fingerprint;
fmanzano_dtk 2:1ef167d1b7b8 268 Ticker tick_idle_shutdown;
fmanzano_dtk 2:1ef167d1b7b8 269 Ticker tick_idle_reminder;
fmanzano_dtk 2:1ef167d1b7b8 270 Ticker tick_safety_tip;
fmanzano_dtk 2:1ef167d1b7b8 271 Ticker tick_playingAudio;
fmanzano_dtk 2:1ef167d1b7b8 272 Ticker tick_fri_ics;
fmanzano_dtk 2:1ef167d1b7b8 273 Ticker tick_autoreset_ble;
fmanzano_dtk 2:1ef167d1b7b8 274
fmanzano_dtk 2:1ef167d1b7b8 275 /**
fmanzano_dtk 2:1ef167d1b7b8 276 * @brief Función para hacer titilar el LED de usuario.
fmanzano_dtk 2:1ef167d1b7b8 277 *
fmanzano_dtk 2:1ef167d1b7b8 278 */
fmanzano_dtk 2:1ef167d1b7b8 279 void blink_led() {
fmanzano_dtk 2:1ef167d1b7b8 280 myled = !myled;
fmanzano_dtk 2:1ef167d1b7b8 281 }
fmanzano_dtk 2:1ef167d1b7b8 282
fmanzano_dtk 2:1ef167d1b7b8 283 /**
fmanzano_dtk 2:1ef167d1b7b8 284 * @brief Activación de la bandera para leer entradas digitales.
fmanzano_dtk 2:1ef167d1b7b8 285 *
fmanzano_dtk 2:1ef167d1b7b8 286 */
fmanzano_dtk 2:1ef167d1b7b8 287 void readInputs() {
fmanzano_dtk 2:1ef167d1b7b8 288 flag_read_inputs = true;
fmanzano_dtk 2:1ef167d1b7b8 289 }
fmanzano_dtk 2:1ef167d1b7b8 290
fmanzano_dtk 2:1ef167d1b7b8 291 // Función al presionar boton
fmanzano_dtk 2:1ef167d1b7b8 292 void pressed() {
fmanzano_dtk 2:1ef167d1b7b8 293 eeprom_Default();
fmanzano_dtk 2:1ef167d1b7b8 294 wait_ms(100);
fmanzano_dtk 2:1ef167d1b7b8 295 NVIC_SystemReset();
fmanzano_dtk 2:1ef167d1b7b8 296 }
fmanzano_dtk 0:2d7ac38345d8 297
fmanzano_dtk 2:1ef167d1b7b8 298 int main() {
fmanzano_dtk 2:1ef167d1b7b8 299
fmanzano_dtk 2:1ef167d1b7b8 300 /**
fmanzano_dtk 2:1ef167d1b7b8 301 * @brief INICIAR INTERFACES
fmanzano_dtk 2:1ef167d1b7b8 302 * Se define el baudrate para las interfaces USART, y el modo para
fmanzano_dtk 2:1ef167d1b7b8 303 * las entradas digitales. También se envía a tierra el pin para la
fmanzano_dtk 2:1ef167d1b7b8 304 * interface Bluetooth.
fmanzano_dtk 2:1ef167d1b7b8 305 */
fmanzano_dtk 2:1ef167d1b7b8 306 avl_uart.baud(115200);
fmanzano_dtk 2:1ef167d1b7b8 307 fingerprint.baud(9600);
fmanzano_dtk 2:1ef167d1b7b8 308 voice_uart.baud(9600);
fmanzano_dtk 2:1ef167d1b7b8 309 in1_ignition.mode(PullDown);
fmanzano_dtk 2:1ef167d1b7b8 310 in2_pilot.mode(PullDown);
fmanzano_dtk 2:1ef167d1b7b8 311 in3_copilot.mode(PullDown);
fmanzano_dtk 2:1ef167d1b7b8 312 in4_crew.mode(PullDown);
fmanzano_dtk 2:1ef167d1b7b8 313 in5_rain_sensor.mode(PullDown);
fmanzano_dtk 2:1ef167d1b7b8 314 wait_us(1000000);
fmanzano_dtk 2:1ef167d1b7b8 315 out1_fingerprint = 0;
fmanzano_dtk 2:1ef167d1b7b8 316 out2_ble_reset = 0;
fmanzano_dtk 2:1ef167d1b7b8 317 out3_gt521fx = 0;
fmanzano_dtk 2:1ef167d1b7b8 318 out4_gt521fx = 0;
fmanzano_dtk 2:1ef167d1b7b8 319 mybutton.fall(&pressed);
fmanzano_dtk 2:1ef167d1b7b8 320
fmanzano_dtk 2:1ef167d1b7b8 321 //Flash
fmanzano_dtk 2:1ef167d1b7b8 322 boot_message();
fmanzano_dtk 3:6e55713bc91d 323 load_eepromVar();
fmanzano_dtk 2:1ef167d1b7b8 324
fmanzano_dtk 2:1ef167d1b7b8 325
fmanzano_dtk 2:1ef167d1b7b8 326 // Configuración Inicial de Nivel de volumen.
fmanzano_dtk 2:1ef167d1b7b8 327 jq8400_iniVol(temp_JQ8400_Volume, &voice_uart);
fmanzano_dtk 2:1ef167d1b7b8 328
fmanzano_dtk 2:1ef167d1b7b8 329 // Iniciar comandos variables de cambio de velocidad
fmanzano_dtk 2:1ef167d1b7b8 330 sprintf(dry_Speed_CMD, "setparam 11104:%d;50092:%d", dry_Speed_Warning, dry_Speed_Limit);
fmanzano_dtk 2:1ef167d1b7b8 331 sprintf(wet_Speed_CMD, "setparam 11104:%d;50092:%d", wet_Speed_Warning, wet_Speed_Limit);
fmanzano_dtk 2:1ef167d1b7b8 332
fmanzano_dtk 2:1ef167d1b7b8 333 /**
fmanzano_dtk 2:1ef167d1b7b8 334 * @brief Se asignan las funciones para los eventos temporizados de titilar
fmanzano_dtk 2:1ef167d1b7b8 335 * el LED de usuario, realizar el muestreo de las entradas digitales
fmanzano_dtk 2:1ef167d1b7b8 336 * y la consulta al sensor de lluvia.
fmanzano_dtk 2:1ef167d1b7b8 337 */
fmanzano_dtk 2:1ef167d1b7b8 338 tick_blink.attach(&blink_led, 2.0);
fmanzano_dtk 2:1ef167d1b7b8 339 tick_readInputs.attach(&readInputs, 0.250);
fmanzano_dtk 2:1ef167d1b7b8 340 if (functionality_rain_sensor) {
fmanzano_dtk 2:1ef167d1b7b8 341 tick_rain_sensor.attach(&queryRG9, time_sample_rain);
fmanzano_dtk 2:1ef167d1b7b8 342 }
fmanzano_dtk 2:1ef167d1b7b8 343 if (functionality_ble_autoreset) {
fmanzano_dtk 2:1ef167d1b7b8 344 tick_autoreset_ble.attach(&BLE_reset, time_ble_autoreset);
fmanzano_dtk 2:1ef167d1b7b8 345 }
fmanzano_dtk 2:1ef167d1b7b8 346
fmanzano_dtk 2:1ef167d1b7b8 347 /**
fmanzano_dtk 2:1ef167d1b7b8 348 * @brief INICIAR WATCHDOG
fmanzano_dtk 2:1ef167d1b7b8 349 * Se crea una instancia para el Watchdog, se define el pre-escaler
fmanzano_dtk 2:1ef167d1b7b8 350 * y el valor máximo en caso que no se actualice se genera el reinicio.
fmanzano_dtk 2:1ef167d1b7b8 351 */
fmanzano_dtk 2:1ef167d1b7b8 352 my_iwdg.Instance = IWDG;
fmanzano_dtk 4:9b1a4a9b2cdf 353 my_iwdg.Init.Prescaler = IWDG_PRESCALER_32;
fmanzano_dtk 2:1ef167d1b7b8 354 my_iwdg.Init.Reload = 0x0FFF;
fmanzano_dtk 2:1ef167d1b7b8 355 HAL_IWDG_Init(&my_iwdg);
fmanzano_dtk 4:9b1a4a9b2cdf 356
fmanzano_dtk 4:9b1a4a9b2cdf 357 // Inicializar la EEPROM
fmanzano_dtk 2:1ef167d1b7b8 358 eeprom_size = ep.getSize();
fmanzano_dtk 2:1ef167d1b7b8 359
fmanzano_dtk 0:2d7ac38345d8 360 while (true) {
fmanzano_dtk 2:1ef167d1b7b8 361
fmanzano_dtk 2:1ef167d1b7b8 362 //! Procesamiento del puerto serial vinculado al FMU130 vía Bluetooth.
fmanzano_dtk 2:1ef167d1b7b8 363 process_FMU130();
fmanzano_dtk 2:1ef167d1b7b8 364
fmanzano_dtk 2:1ef167d1b7b8 365 //! Verificar si deben efectuarse la lectura de entradas digitales.
fmanzano_dtk 2:1ef167d1b7b8 366 if(flag_read_inputs) {
fmanzano_dtk 2:1ef167d1b7b8 367 process_Inputs();
fmanzano_dtk 2:1ef167d1b7b8 368 }
fmanzano_dtk 2:1ef167d1b7b8 369
fmanzano_dtk 2:1ef167d1b7b8 370 //! Verificar si debe activarse el lector de huellas.
fmanzano_dtk 2:1ef167d1b7b8 371 if (flag_fingerprint_query) {
fmanzano_dtk 2:1ef167d1b7b8 372 HAL_IWDG_Refresh(&my_iwdg);
fmanzano_dtk 2:1ef167d1b7b8 373 identify_fingerPrint();
fmanzano_dtk 2:1ef167d1b7b8 374 }
fmanzano_dtk 2:1ef167d1b7b8 375
fmanzano_dtk 2:1ef167d1b7b8 376 //! Verificar si se debe apagar el lector de huellas.
fmanzano_dtk 2:1ef167d1b7b8 377 if (fingerprint_flag_poweroff) {
fmanzano_dtk 2:1ef167d1b7b8 378 out3_gt521fx = out4_gt521fx = finterprint_flag_working = fingerprint_flag_poweroff = false;
fmanzano_dtk 3:6e55713bc91d 379 #ifdef M_DEBUG
fmanzano_dtk 2:1ef167d1b7b8 380 myPC_debug.printf("[MAIN] - OUT3:FALSE\r\n");
fmanzano_dtk 2:1ef167d1b7b8 381 #endif
fmanzano_dtk 2:1ef167d1b7b8 382 }
fmanzano_dtk 2:1ef167d1b7b8 383
fmanzano_dtk 2:1ef167d1b7b8 384 //! Verificar si debe consultarse el estado del sensor de lluvia.
fmanzano_dtk 2:1ef167d1b7b8 385 if (flag_query_rain_sensor) {
fmanzano_dtk 2:1ef167d1b7b8 386 //process_rainSensor();
fmanzano_dtk 2:1ef167d1b7b8 387 process_inputRainSensor();
fmanzano_dtk 2:1ef167d1b7b8 388 }
fmanzano_dtk 2:1ef167d1b7b8 389
fmanzano_dtk 2:1ef167d1b7b8 390 //! verificar si debe ejecutarse un evento de apagado por ralentí.
fmanzano_dtk 2:1ef167d1b7b8 391 if (flag_idle_force_shutdown) {
fmanzano_dtk 2:1ef167d1b7b8 392 exe_idle_shutdown();
fmanzano_dtk 2:1ef167d1b7b8 393 }
fmanzano_dtk 2:1ef167d1b7b8 394
fmanzano_dtk 2:1ef167d1b7b8 395 if (flag_idle_reminder) {
fmanzano_dtk 2:1ef167d1b7b8 396 exe_idle_reminder();
fmanzano_dtk 2:1ef167d1b7b8 397 }
fmanzano_dtk 2:1ef167d1b7b8 398
fmanzano_dtk 2:1ef167d1b7b8 399 if (flag_safety_tip) {
fmanzano_dtk 2:1ef167d1b7b8 400 exe_SafetyTip();
fmanzano_dtk 2:1ef167d1b7b8 401 }
fmanzano_dtk 2:1ef167d1b7b8 402
fmanzano_dtk 2:1ef167d1b7b8 403 if (flag_fri_ics) {
fmanzano_dtk 2:1ef167d1b7b8 404 tx_fri_ics();
fmanzano_dtk 2:1ef167d1b7b8 405 }
fmanzano_dtk 2:1ef167d1b7b8 406
fmanzano_dtk 2:1ef167d1b7b8 407 if (!(flag_playingSound)) {
fmanzano_dtk 2:1ef167d1b7b8 408 processPlaylist();
fmanzano_dtk 2:1ef167d1b7b8 409 }
fmanzano_dtk 2:1ef167d1b7b8 410
fmanzano_dtk 2:1ef167d1b7b8 411 //! Actualizar Watchdog
fmanzano_dtk 2:1ef167d1b7b8 412 HAL_IWDG_Refresh(&my_iwdg);
fmanzano_dtk 0:2d7ac38345d8 413 }
fmanzano_dtk 2:1ef167d1b7b8 414 }