mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-31 02:08:26 +02:00
Implementing the remainder of GPS data for the GPS component. (#1676)
This commit is contained in:
@@ -8,34 +8,57 @@ static const char *TAG = "gps";
|
||||
|
||||
TinyGPSPlus &GPSListener::get_tiny_gps() { return this->parent_->get_tiny_gps(); }
|
||||
|
||||
void GPS::update() {
|
||||
if (this->latitude_sensor_ != nullptr)
|
||||
this->latitude_sensor_->publish_state(this->latitude_);
|
||||
|
||||
if (this->longitude_sensor_ != nullptr)
|
||||
this->longitude_sensor_->publish_state(this->longitude_);
|
||||
|
||||
if (this->speed_sensor_ != nullptr)
|
||||
this->speed_sensor_->publish_state(this->speed_);
|
||||
|
||||
if (this->course_sensor_ != nullptr)
|
||||
this->course_sensor_->publish_state(this->course_);
|
||||
|
||||
if (this->altitude_sensor_ != nullptr)
|
||||
this->altitude_sensor_->publish_state(this->altitude_);
|
||||
|
||||
if (this->satellites_sensor_ != nullptr)
|
||||
this->satellites_sensor_->publish_state(this->satellites_);
|
||||
}
|
||||
|
||||
void GPS::loop() {
|
||||
while (this->available() && !this->has_time_) {
|
||||
if (this->tiny_gps_.encode(this->read())) {
|
||||
if (tiny_gps_.location.isUpdated()) {
|
||||
this->latitude_ = tiny_gps_.location.lat();
|
||||
this->longitude_ = tiny_gps_.location.lng();
|
||||
|
||||
ESP_LOGD(TAG, "Location:");
|
||||
ESP_LOGD(TAG, " Lat: %f", tiny_gps_.location.lat());
|
||||
ESP_LOGD(TAG, " Lon: %f", tiny_gps_.location.lng());
|
||||
ESP_LOGD(TAG, " Lat: %f", this->latitude_);
|
||||
ESP_LOGD(TAG, " Lon: %f", this->longitude_);
|
||||
}
|
||||
|
||||
if (tiny_gps_.speed.isUpdated()) {
|
||||
this->speed_ = tiny_gps_.speed.kmph();
|
||||
ESP_LOGD(TAG, "Speed:");
|
||||
ESP_LOGD(TAG, " %f km/h", tiny_gps_.speed.kmph());
|
||||
ESP_LOGD(TAG, " %f km/h", this->speed_);
|
||||
}
|
||||
if (tiny_gps_.course.isUpdated()) {
|
||||
this->course_ = tiny_gps_.course.deg();
|
||||
ESP_LOGD(TAG, "Course:");
|
||||
ESP_LOGD(TAG, " %f °", tiny_gps_.course.deg());
|
||||
ESP_LOGD(TAG, " %f °", this->course_);
|
||||
}
|
||||
if (tiny_gps_.altitude.isUpdated()) {
|
||||
this->altitude_ = tiny_gps_.altitude.meters();
|
||||
ESP_LOGD(TAG, "Altitude:");
|
||||
ESP_LOGD(TAG, " %f m", tiny_gps_.altitude.meters());
|
||||
ESP_LOGD(TAG, " %f m", this->altitude_);
|
||||
}
|
||||
if (tiny_gps_.satellites.isUpdated()) {
|
||||
this->satellites_ = tiny_gps_.satellites.value();
|
||||
ESP_LOGD(TAG, "Satellites:");
|
||||
ESP_LOGD(TAG, " %d", tiny_gps_.satellites.value());
|
||||
}
|
||||
if (tiny_gps_.satellites.isUpdated()) {
|
||||
ESP_LOGD(TAG, "HDOP:");
|
||||
ESP_LOGD(TAG, " %.2f", tiny_gps_.hdop.hdop());
|
||||
ESP_LOGD(TAG, " %d", this->satellites_);
|
||||
}
|
||||
|
||||
for (auto *listener : this->listeners_)
|
||||
|
||||
Reference in New Issue
Block a user