GPS to Pulga
Diff: source/main.cpp
- Revision:
- 25:ecdee9ef9939
- Parent:
- 24:595155aa83c3
- Child:
- 26:1e1776201716
diff -r 595155aa83c3 -r ecdee9ef9939 source/main.cpp --- a/source/main.cpp Fri Jan 03 09:28:20 2020 +0000 +++ b/source/main.cpp Fri Oct 23 14:42:31 2020 +0000 @@ -5,238 +5,38 @@ #include <events/mbed_events.h> #include <stdio.h> #include "mbed.h" -/***Definições do Arquétipo***/ -int comm=2; // Selecionar: 0 para nenhum, 1 para BLE, 2 para Lora ou 3 para Lorawan -int sensors=0; // Selecionar: 0 para nenhum, 1 para sensor ambiental, 2 para sensor de luz, 3 para sensor de movimento. -int peripherals=0; // Selecionar: 0 para nenhum, 1 para GPS - -/***Global Variables***/ -float sensor_get_0 = 0; -float sensor_get_1 = 0; -float sensor_get_2 = 0; -float sensor_get_3 = 0; -float sensor_get_4 = 0; -uint32_t sens00 = 0; -uint32_t sens01 = 0; -uint32_t sens02 = 0; -int cont=0; -int read_sens=0; +//Global Variables int lat=0; int lon=0; int latitude=0; int longitude=0; - - -/***SPECIFIC INCLUDES***/ - -//BLE Includes - - -#include "platform/Callback.h" -#include "events/EventQueue.h" -#include "platform/NonCopyable.h" +DigitalOut led1(P1_13); -#include "ble/BLE.h" -#include "ble/Gap.h" -#include "ble/GattClient.h" -#include "ble/GapAdvertisingParams.h" -#include "ble/GapAdvertisingData.h" -#include "ble/GattServer.h" -#include "BLEProcess.h" - - - -//Lorawan Includes - -#include "lorawan/LoRaWANInterface.h" -#include "lorawan/system/lorawan_data_structures.h" -#include "trace_helper.h" -#include "lora_radio_helper.h" - -DigitalOut led1(P1_13); -InterruptIn button1(P1_11); - -//Sensors Includes - -#include "BME280.h" -#include "Si1133.h" -#include "BMX160.txt" +//Includes #include "gps.txt" -/***DEFINES***/ - -//Sensors and Peripherals - -BME280 sensor_amb(P0_13, P0_15, 0x77 << 1); -Si1133 sensor_light(P0_13, P0_15); - - - - -/***Functions***/ - - - -void Sensor_Read(int sens){ - - if (sens==1) { - sensor_amb.initialize(); - sensor_get_0 = sensor_amb.getTemperature(); - - //if (comm==1){ - sens00 = sensor_get_0; - sens00 = (sens00 < 0 ? 0 : sens00); - sens00 = (sens00 > 255 ? 255 : sens00); - printf("Temp = %u\n", sens00); - // } - - printf("Temp = %f\n", sensor_get_0); - - - sensor_get_1 = sensor_amb.getPressure(); - - if (comm==1){ - sens01 = sensor_get_1/10; - sens01 = (sens01 < 0 ? 0 : sens01); - sens01 = (sens01 > 255 ? 255 : sens01); - printf("Pres = %u\n", sens01); - } - - printf("Pres = %f\n", sensor_get_1); - - - sensor_get_2 = sensor_amb.getHumidity(); - - - if (comm==1){ - sens02 = sensor_get_2; - sens02 = (sens02 < 0 ? 0 : sens02); - sens02 = (sens02 > 255 ? 255 : sens02); - printf("Hum = %u\n", sens02); - } - - printf("Hum = %f\n", sensor_get_2); - } - - if (sens==2) { - if(sensor_light.open()){ - sensor_get_3 = sensor_light.get_light_level(); - if (comm==1){ - sens00 = sensor_get_3; - sens00 = (sens00 < 0 ? 0 : sens00); - sens00 = (sens00 > 255 ? 255 : sens00); - printf("Light Level = %u\n", sens00); - } - - printf("Light Level = %f\n", sensor_get_3); - } - } - - if (sens==3) { - if(sensor_light.open()){ - sensor_get_4 = sensor_light.get_uv_index(); - if (comm==1){ - sens01 = sensor_get_4/10; - sens01 = (sens01 < 0 ? 0 : sens01); - sens01 = (sens01 > 255 ? 255 : sens01); - printf("UV Index = %u\n", sens01); - } - printf("Uv Index = %f\n", sensor_get_4); - } - } - - if (sens==4) { - - BMX160_print(); - - } - } - - void GPS_Read(void) { gps_print_local(); - // send_nav_pvt(); - //lon= gps_send_long (); printf ("gps longitude=%d \n",lon); - //lat= gps_send_lat (); printf ("gps latitude=%d \n",lat); - //if(lat!=0 && lon!=0){ + if(lat!=0 && lon!=0){ longitude=lon; latitude=lat; - //} + led1 = !led1; + } } - -#include "BLE.txt" -#include "Lorawan.txt" - -int Communication(int comm){ - - if(comm==1){ - - BLE &ble_interface = BLE::Instance(); - events::EventQueue event_queue; - MyService demo_service; - BLEProcess ble_process(event_queue, ble_interface); - ble_process.on_init(callback(&demo_service, &MyService::start)); - ble_process.start(); - event_queue.dispatch_forever(); - } - - if(comm==2){ - - setup_trace(); - lorawan_status_t retcode; +int main() { - if (lorawan.initialize(&ev_queue) != LORAWAN_STATUS_OK) { - printf("\r\n LoRa initialization failed! \r\n"); - return -1;} - callbacks.events = mbed::callback(lora_event_handler); - lorawan.add_app_callbacks(&callbacks); - if (lorawan.set_confirmed_msg_retries(CONFIRMED_MSG_RETRY_COUNTER) - != LORAWAN_STATUS_OK) { - return -1;} - if (lorawan.enable_adaptive_datarate() != LORAWAN_STATUS_OK) { - printf("\r\n enable_adaptive_datarate failed! \r\n"); - return -1;} - retcode = lorawan.connect(); - if (retcode == LORAWAN_STATUS_OK || - retcode == LORAWAN_STATUS_CONNECT_IN_PROGRESS) { - } else { - return -1;} - ev_queue.dispatch_forever(); + gps_config(); + gps_leBootMsg(); + gps_config_gnss (); + + while (1){ + GPS_Read(); + wait (5); } - return 0; -} -void button1_pressed() -{ - printf("Teste dos Periféricos\n"); - Sensor_Read(1); - wait(0.5); - Sensor_Read(2); - wait(0.5); - Sensor_Read(3); - wait(0.5); - } - -void button1_released() -{ - led1=1; - wait(3); - led1=0; - -} - -int main() { - - BMX160_config(); - gps_config(); - gps_config_gnss (); - //button1.fall(&button1_pressed); - //button1.rise(&button1_released); - Communication (comm); - } \ No newline at end of file