[gps] Patches to build on IDF, other optimizations (#9728)

This commit is contained in:
Keith Burzinski 2025-07-24 06:23:42 -05:00 committed by GitHub
parent ba72298a63
commit 729f20d765
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 73 additions and 71 deletions

View File

@ -1 +1 @@
7920671c938a5ea6a11ac4594204b5ec8f38d579c962bf1f185e8d5e3ad879be
8016e9cbe199bf1a65a0c90e7a37d768ec774f4fff70de530a9b55708af71e74

View File

@ -84,7 +84,6 @@ CONFIG_SCHEMA = cv.All(
)
.extend(cv.polling_component_schema("20s"))
.extend(uart.UART_DEVICE_SCHEMA),
cv.only_with_arduino,
)
FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema("gps", require_rx=True)
@ -123,4 +122,9 @@ async def to_code(config):
cg.add(var.set_hdop_sensor(sens))
# https://platformio.org/lib/show/1655/TinyGPSPlus
cg.add_library("mikalhart/TinyGPSPlus", "1.1.0")
# Using fork of TinyGPSPlus patched to build on ESP-IDF
cg.add_library(
"TinyGPSPlus",
None,
"https://github.com/esphome/TinyGPSPlus.git#v1.1.0",
)

View File

@ -1,5 +1,3 @@
#ifdef USE_ARDUINO
#include "gps.h"
#include "esphome/core/log.h"
@ -22,73 +20,76 @@ void GPS::dump_config() {
}
void GPS::update() {
if (this->latitude_sensor_ != nullptr)
if (this->latitude_sensor_ != nullptr) {
this->latitude_sensor_->publish_state(this->latitude_);
}
if (this->longitude_sensor_ != nullptr)
if (this->longitude_sensor_ != nullptr) {
this->longitude_sensor_->publish_state(this->longitude_);
}
if (this->speed_sensor_ != nullptr)
if (this->speed_sensor_ != nullptr) {
this->speed_sensor_->publish_state(this->speed_);
}
if (this->course_sensor_ != nullptr)
if (this->course_sensor_ != nullptr) {
this->course_sensor_->publish_state(this->course_);
}
if (this->altitude_sensor_ != nullptr)
if (this->altitude_sensor_ != nullptr) {
this->altitude_sensor_->publish_state(this->altitude_);
}
if (this->satellites_sensor_ != nullptr)
if (this->satellites_sensor_ != nullptr) {
this->satellites_sensor_->publish_state(this->satellites_);
}
if (this->hdop_sensor_ != nullptr)
if (this->hdop_sensor_ != nullptr) {
this->hdop_sensor_->publish_state(this->hdop_);
}
}
void GPS::loop() {
while (this->available() > 0 && !this->has_time_) {
if (this->tiny_gps_.encode(this->read())) {
if (this->tiny_gps_.location.isUpdated()) {
this->latitude_ = this->tiny_gps_.location.lat();
this->longitude_ = this->tiny_gps_.location.lng();
if (!this->tiny_gps_.encode(this->read())) {
return;
}
if (this->tiny_gps_.location.isUpdated()) {
this->latitude_ = this->tiny_gps_.location.lat();
this->longitude_ = this->tiny_gps_.location.lng();
ESP_LOGV(TAG, "Latitude, Longitude: %.6f°, %.6f°", this->latitude_, this->longitude_);
}
ESP_LOGD(TAG, "Location:");
ESP_LOGD(TAG, " Lat: %.6f °", this->latitude_);
ESP_LOGD(TAG, " Lon: %.6f °", this->longitude_);
}
if (this->tiny_gps_.speed.isUpdated()) {
this->speed_ = this->tiny_gps_.speed.kmph();
ESP_LOGV(TAG, "Speed: %.3f km/h", this->speed_);
}
if (this->tiny_gps_.speed.isUpdated()) {
this->speed_ = this->tiny_gps_.speed.kmph();
ESP_LOGD(TAG, "Speed: %.3f km/h", this->speed_);
}
if (this->tiny_gps_.course.isUpdated()) {
this->course_ = this->tiny_gps_.course.deg();
ESP_LOGV(TAG, "Course: %.2f°", this->course_);
}
if (this->tiny_gps_.course.isUpdated()) {
this->course_ = this->tiny_gps_.course.deg();
ESP_LOGD(TAG, "Course: %.2f °", this->course_);
}
if (this->tiny_gps_.altitude.isUpdated()) {
this->altitude_ = this->tiny_gps_.altitude.meters();
ESP_LOGV(TAG, "Altitude: %.2f m", this->altitude_);
}
if (this->tiny_gps_.altitude.isUpdated()) {
this->altitude_ = this->tiny_gps_.altitude.meters();
ESP_LOGD(TAG, "Altitude: %.2f m", this->altitude_);
}
if (this->tiny_gps_.satellites.isUpdated()) {
this->satellites_ = this->tiny_gps_.satellites.value();
ESP_LOGV(TAG, "Satellites: %d", this->satellites_);
}
if (this->tiny_gps_.satellites.isUpdated()) {
this->satellites_ = this->tiny_gps_.satellites.value();
ESP_LOGD(TAG, "Satellites: %d", this->satellites_);
}
if (this->tiny_gps_.hdop.isUpdated()) {
this->hdop_ = this->tiny_gps_.hdop.hdop();
ESP_LOGV(TAG, "HDOP: %.3f", this->hdop_);
}
if (this->tiny_gps_.hdop.isUpdated()) {
this->hdop_ = this->tiny_gps_.hdop.hdop();
ESP_LOGD(TAG, "HDOP: %.3f", this->hdop_);
}
for (auto *listener : this->listeners_) {
listener->on_update(this->tiny_gps_);
}
for (auto *listener : this->listeners_) {
listener->on_update(this->tiny_gps_);
}
}
}
} // namespace gps
} // namespace esphome
#endif // USE_ARDUINO

View File

@ -1,10 +1,8 @@
#pragma once
#ifdef USE_ARDUINO
#include "esphome/core/component.h"
#include "esphome/components/uart/uart.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/uart/uart.h"
#include "esphome/core/component.h"
#include <TinyGPSPlus.h>
#include <vector>
@ -53,8 +51,9 @@ class GPS : public PollingComponent, public uart::UARTDevice {
float speed_{NAN};
float course_{NAN};
float altitude_{NAN};
uint16_t satellites_{0};
float hdop_{NAN};
uint16_t satellites_{0};
bool has_time_{false};
sensor::Sensor *latitude_sensor_{nullptr};
sensor::Sensor *longitude_sensor_{nullptr};
@ -64,12 +63,9 @@ class GPS : public PollingComponent, public uart::UARTDevice {
sensor::Sensor *satellites_sensor_{nullptr};
sensor::Sensor *hdop_sensor_{nullptr};
bool has_time_{false};
TinyGPSPlus tiny_gps_;
std::vector<GPSListener *> listeners_{};
};
} // namespace gps
} // namespace esphome
#endif // USE_ARDUINO

View File

@ -1,5 +1,3 @@
#ifdef USE_ARDUINO
#include "gps_time.h"
#include "esphome/core/log.h"
@ -9,12 +7,10 @@ namespace gps {
static const char *const TAG = "gps.time";
void GPSTime::from_tiny_gps_(TinyGPSPlus &tiny_gps) {
if (!tiny_gps.time.isValid() || !tiny_gps.date.isValid())
return;
if (!tiny_gps.time.isUpdated() || !tiny_gps.date.isUpdated())
return;
if (tiny_gps.date.year() < 2019)
if (!tiny_gps.time.isValid() || !tiny_gps.date.isValid() || !tiny_gps.time.isUpdated() ||
!tiny_gps.date.isUpdated() || tiny_gps.date.year() < 2025) {
return;
}
ESPTime val{};
val.year = tiny_gps.date.year();
@ -34,5 +30,3 @@ void GPSTime::from_tiny_gps_(TinyGPSPlus &tiny_gps) {
} // namespace gps
} // namespace esphome
#endif // USE_ARDUINO

View File

@ -1,10 +1,8 @@
#pragma once
#ifdef USE_ARDUINO
#include "esphome/core/component.h"
#include "esphome/components/time/real_time_clock.h"
#include "esphome/components/gps/gps.h"
#include "esphome/components/time/real_time_clock.h"
#include "esphome/core/component.h"
namespace esphome {
namespace gps {
@ -13,8 +11,9 @@ class GPSTime : public time::RealTimeClock, public GPSListener {
public:
void update() override { this->from_tiny_gps_(this->get_tiny_gps()); };
void on_update(TinyGPSPlus &tiny_gps) override {
if (!this->has_time_)
if (!this->has_time_) {
this->from_tiny_gps_(tiny_gps);
}
}
protected:
@ -24,5 +23,3 @@ class GPSTime : public time::RealTimeClock, public GPSListener {
} // namespace gps
} // namespace esphome
#endif // USE_ARDUINO

View File

@ -73,7 +73,7 @@ lib_deps =
heman/AsyncMqttClient-esphome@1.0.0 ; mqtt
ESP32Async/ESPAsyncWebServer@3.7.8 ; web_server_base
fastled/FastLED@3.9.16 ; fastled_base
mikalhart/TinyGPSPlus@1.1.0 ; gps
https://github.com/esphome/TinyGPSPlus.git#v1.1.0 ; gps
freekode/TM1651@1.0.1 ; tm1651
glmnet/Dsmr@0.7 ; dsmr
rweather/Crypto@0.4.0 ; dsmr

View File

@ -0,0 +1,5 @@
substitutions:
tx_pin: GPIO4
rx_pin: GPIO5
<<: !include common.yaml

View File

@ -0,0 +1,5 @@
substitutions:
tx_pin: GPIO12
rx_pin: GPIO14
<<: !include common.yaml