ESP32-CAN/main/main.cpp

55 lines
1.2 KiB
C++
Raw Normal View History

#include "esp32-hal.h"
#include "esp_log.h"
#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
static const constexpr char *TAG = "Main";
2026-03-26 23:01:20 +00:00
SemaphoreHandle_t gps_mutex;
GPS *gps = nullptr;
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();
while (true) {
2026-03-26 23:01:20 +00:00
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
}