ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
gps.h
Go to the documentation of this file.
1#pragma once
2
7#include <TinyGPSPlus.h>
8
9namespace esphome::gps {
10
11class GPS;
12
14 public:
15 virtual void on_update(TinyGPSPlus &tiny_gps) = 0;
16 TinyGPSPlus &get_tiny_gps();
17
18 protected:
19 friend GPS;
20
22};
23
24class GPS final : public PollingComponent, public uart::UARTDevice {
25 SUB_SENSOR(latitude)
26 SUB_SENSOR(longitude)
27 SUB_SENSOR(speed)
28 SUB_SENSOR(course)
29 SUB_SENSOR(altitude)
30 SUB_SENSOR(satellites)
31 SUB_SENSOR(hdop)
32
33 public:
34#ifdef GPS_LISTENER_COUNT
35 void register_listener(GPSListener *listener) {
36 listener->parent_ = this;
37 this->listeners_.push_back(listener);
38 }
39#endif
40 float get_setup_priority() const override { return setup_priority::HARDWARE; }
41
42 void dump_config() override;
43 void loop() override;
44 void update() override;
45
46 TinyGPSPlus &get_tiny_gps() { return this->tiny_gps_; }
47
48 protected:
49 float latitude_{NAN};
50 float longitude_{NAN};
51 float speed_{NAN};
52 float course_{NAN};
53 float altitude_{NAN};
54 float hdop_{NAN};
55 uint16_t satellites_{0};
56 bool has_time_{false};
57
58 TinyGPSPlus tiny_gps_;
59#ifdef GPS_LISTENER_COUNT
61#endif
62};
63
64} // namespace esphome::gps
This class simplifies creating components that periodically check a state.
Definition component.h:532
Minimal static vector - saves memory by avoiding std::vector overhead.
Definition helpers.h:304
float speed_
Definition gps.h:51
float latitude_
Definition gps.h:49
uint16_t satellites_
Definition gps.h:55
float longitude_
Definition gps.h:50
bool has_time_
Definition gps.h:56
float altitude_
Definition gps.h:53
float hdop_
Definition gps.h:54
TinyGPSPlus tiny_gps_
Definition gps.h:58
float course_
Definition gps.h:52
StaticVector< GPSListener *, GPS_LISTENER_COUNT > listeners_
Definition gps.h:60
TinyGPSPlus & get_tiny_gps()
Definition gps.cpp:8
virtual void on_update(TinyGPSPlus &tiny_gps)=0
int speed
Definition fan.h:3
constexpr float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition component.h:43