2026-03-23 11:01:23 +00:00
|
|
|
|
|
|
|
|
#include "esp32-hal.h"
|
2026-03-18 21:43:28 +00:00
|
|
|
#include "esp_log.h"
|
2026-03-18 15:49:09 +00:00
|
|
|
#include <cmath>
|
2026-03-26 23:01:20 +00:00
|
|
|
#include <cstdio>
|
2026-03-16 00:49:02 +00:00
|
|
|
|
2026-03-26 23:01:20 +00:00
|
|
|
#include "freertos/idf_additions.h"
|
|
|
|
|
#include "freertos/projdefs.h"
|
|
|
|
|
#include "gps.h"
|
2026-03-16 00:49:02 +00:00
|
|
|
|
2026-03-18 21:43:28 +00:00
|
|
|
static const constexpr char *TAG = "Main";
|
2026-03-23 11:01:23 +00:00
|
|
|
|
2026-03-26 23:01:20 +00:00
|
|
|
SemaphoreHandle_t gps_mutex;
|
|
|
|
|
GPS *gps = nullptr;
|
2026-03-18 15:49:09 +00:00
|
|
|
|
2026-03-26 23:01:20 +00:00
|
|
|
void gps_poll_task(void *_) {
|
|
|
|
|
while (true) {
|
|
|
|
|
if (xSemaphoreTake(gps_mutex, (TickType_t)10) == pdTRUE) {
|
|
|
|
|
gps->poll();
|
|
|
|
|
xSemaphoreGive(gps_mutex);
|
|
|
|
|
}
|
|
|
|
|
vTaskDelay(pdMS_TO_TICKS(50));
|
2026-03-16 14:25:49 +00:00
|
|
|
}
|
2026-03-26 23:01:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gps_poll_init() {
|
|
|
|
|
gps_mutex = xSemaphoreCreateMutex();
|
|
|
|
|
if (gps_mutex != NULL) {
|
|
|
|
|
xTaskCreate(gps_poll_task, "Writer", 2048, NULL, 1, NULL);
|
2026-03-16 00:49:02 +00:00
|
|
|
}
|
2026-03-26 23:01:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "C" void app_main(void) {
|
|
|
|
|
initArduino();
|
|
|
|
|
gps = new GPS();
|
2026-03-29 18:09:54 +01:00
|
|
|
gps_poll_init();
|
2026-03-26 23:01:20 +00:00
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
if (xSemaphoreTake(gps_mutex, (TickType_t)10) == pdTRUE) {
|
|
|
|
|
ESP_LOGI(TAG, "loc -> lat: %f, long: %f, height: %f",
|
|
|
|
|
gps->gps.latitudeDegrees, gps->gps.longitudeDegrees,
|
|
|
|
|
gps->gps.altitude);
|
|
|
|
|
if (gps->gps_avaliable()) {
|
|
|
|
|
|
|
|
|
|
auto D_pos = gps->get_coordinates().value();
|
|
|
|
|
ESP_LOGI(TAG, " -> D(pos): (%f, %f, %f)", D_pos[0], D_pos[1],
|
|
|
|
|
D_pos[2]);
|
|
|
|
|
}
|
|
|
|
|
xSemaphoreGive(gps_mutex);
|
|
|
|
|
}
|
|
|
|
|
vTaskDelay(pdMS_TO_TICKS(250));
|
|
|
|
|
}
|
2026-03-16 00:49:02 +00:00
|
|
|
}
|