diff --git a/TactilityC/Include/tt_gps.h b/TactilityC/Include/tt_gps.h new file mode 100644 index 00000000..9a686cae --- /dev/null +++ b/TactilityC/Include/tt_gps.h @@ -0,0 +1,21 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +bool tt_gps_has_coordinates(); + +bool tt_gps_get_coordinates( + float& longitude, + float& latitude, + float& speed, + float& course, + int& day, + int& month, + int& year +); + +#ifdef __cplusplus +} +#endif diff --git a/TactilityC/Source/tt_gps.cpp b/TactilityC/Source/tt_gps.cpp new file mode 100644 index 00000000..2ba12344 --- /dev/null +++ b/TactilityC/Source/tt_gps.cpp @@ -0,0 +1,45 @@ +#include "tt_gps.h" +#include + +using namespace tt::service; + +extern "C" { + +bool tt_gps_has_coordinates() { + auto service = gps::findGpsService(); + return service != nullptr && service->hasCoordinates(); +} + +bool tt_gps_get_coordinates( + float& longitude, + float& latitude, + float& speed, + float& course, + int& day, + int& month, + int& year +) { + auto service = gps::findGpsService(); + + if (service == nullptr) { + return false; + } + + minmea_sentence_rmc rmc; + + if (!service->getCoordinates(rmc)) { + return false; + } + + longitude = minmea_tocoord(&rmc.longitude); + latitude = minmea_tocoord(&rmc.latitude); + speed = minmea_tocoord(&rmc.speed); + course = minmea_tocoord(&rmc.course); + day = rmc.date.day; + month = rmc.date.month; + year = rmc.date.year; + + return true; +} + +} \ No newline at end of file diff --git a/TactilityC/Source/tt_init.cpp b/TactilityC/Source/tt_init.cpp index 85e0eeaf..42e72bf1 100644 --- a/TactilityC/Source/tt_init.cpp +++ b/TactilityC/Source/tt_init.cpp @@ -5,6 +5,7 @@ #include "tt_app_manifest.h" #include "tt_app_selectiondialog.h" #include "tt_bundle.h" +#include "tt_gps.h" #include "tt_hal_i2c.h" #include "tt_lvgl_keyboard.h" #include "tt_lvgl_spinner.h" @@ -42,6 +43,8 @@ const struct esp_elfsym elf_symbols[] { ESP_ELFSYM_EXPORT(tt_bundle_put_bool), ESP_ELFSYM_EXPORT(tt_bundle_put_int32), ESP_ELFSYM_EXPORT(tt_bundle_put_string), + ESP_ELFSYM_EXPORT(tt_gps_has_coordinates), + ESP_ELFSYM_EXPORT(tt_gps_get_coordinates), ESP_ELFSYM_EXPORT(tt_hal_i2c_start), ESP_ELFSYM_EXPORT(tt_hal_i2c_stop), ESP_ELFSYM_EXPORT(tt_hal_i2c_is_started),