9 static const char *
const TAG =
"gps";
14 if (this->latitude_sensor_ !=
nullptr)
15 this->latitude_sensor_->publish_state(this->latitude_);
17 if (this->longitude_sensor_ !=
nullptr)
18 this->longitude_sensor_->publish_state(this->longitude_);
20 if (this->speed_sensor_ !=
nullptr)
21 this->speed_sensor_->publish_state(this->speed_);
23 if (this->course_sensor_ !=
nullptr)
24 this->course_sensor_->publish_state(this->course_);
26 if (this->altitude_sensor_ !=
nullptr)
27 this->altitude_sensor_->publish_state(this->altitude_);
29 if (this->satellites_sensor_ !=
nullptr)
30 this->satellites_sensor_->publish_state(this->satellites_);
34 while (this->available() && !this->has_time_) {
35 if (this->tiny_gps_.encode(this->read())) {
36 if (tiny_gps_.location.isUpdated()) {
37 this->latitude_ = tiny_gps_.location.lat();
38 this->longitude_ = tiny_gps_.location.lng();
40 ESP_LOGD(TAG,
"Location:");
41 ESP_LOGD(TAG,
" Lat: %f", this->latitude_);
42 ESP_LOGD(TAG,
" Lon: %f", this->longitude_);
45 if (tiny_gps_.speed.isUpdated()) {
46 this->speed_ = tiny_gps_.speed.kmph();
47 ESP_LOGD(TAG,
"Speed:");
48 ESP_LOGD(TAG,
" %f km/h", this->speed_);
50 if (tiny_gps_.course.isUpdated()) {
51 this->course_ = tiny_gps_.course.deg();
52 ESP_LOGD(TAG,
"Course:");
53 ESP_LOGD(TAG,
" %f °", this->course_);
55 if (tiny_gps_.altitude.isUpdated()) {
56 this->altitude_ = tiny_gps_.altitude.meters();
57 ESP_LOGD(TAG,
"Altitude:");
58 ESP_LOGD(TAG,
" %f m", this->altitude_);
60 if (tiny_gps_.satellites.isUpdated()) {
61 this->satellites_ = tiny_gps_.satellites.value();
62 ESP_LOGD(TAG,
"Satellites:");
63 ESP_LOGD(TAG,
" %d", this->satellites_);
66 for (
auto *listener : this->listeners_)
67 listener->on_update(this->tiny_gps_);
TinyGPSPlus & get_tiny_gps()
TinyGPSPlus & get_tiny_gps()
Implementation of SPI Controller mode.