make gpsd receiver not poll
This commit is contained in:
@ -24,7 +24,7 @@ namespace waybar::modules {
|
|||||||
|
|
||||||
const std::string getFixStatusString() const;
|
const std::string getFixStatusString() const;
|
||||||
|
|
||||||
util::SleeperThread thread_;
|
util::SleeperThread thread_, gps_thread_;
|
||||||
gps_data_t gps_data_;
|
gps_data_t gps_data_;
|
||||||
std::string state_;
|
std::string state_;
|
||||||
|
|
||||||
|
@ -42,7 +42,8 @@ libgps lives in:
|
|||||||
*interval*: ++
|
*interval*: ++
|
||||||
typeof: integer ++
|
typeof: integer ++
|
||||||
default: 5 ++
|
default: 5 ++
|
||||||
The interval in which the GPS information gets polled (e.g. fix status).
|
The interval in which the GPS information gets polled (e.g. current speed).
|
||||||
|
Significant updates (e.g. the current fix mode) are updated immediately.
|
||||||
|
|
||||||
*hide-disconnected*: ++
|
*hide-disconnected*: ++
|
||||||
typeof: bool ++
|
typeof: bool ++
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "modules/gps.hpp"
|
#include "modules/gps.hpp"
|
||||||
|
#include <gps.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@ -38,7 +39,28 @@ waybar::modules::Gps::Gps(const std::string& id, const Json::Value& config)
|
|||||||
hideNoFix = config_["hide-no-fix"].asBool();
|
hideNoFix = config_["hide-no-fix"].asBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
gps_stream(&gps_data_, WATCH_ENABLE, NULL);
|
gps_thread_ = [this] {
|
||||||
|
dp.emit();
|
||||||
|
gps_stream(&gps_data_, WATCH_ENABLE, NULL);
|
||||||
|
int last_gps_mode = 0;
|
||||||
|
|
||||||
|
while (gps_waiting(&gps_data_, 5000000)) {
|
||||||
|
if (gps_read(&gps_data_, NULL, 0) == -1) {
|
||||||
|
throw std::runtime_error("Can't read data from gpsd.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MODE_SET != (MODE_SET & gps_data_.set)) {
|
||||||
|
// did not even get mode, nothing to see here
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gps_data_.fix.mode != last_gps_mode) {
|
||||||
|
// significant update
|
||||||
|
dp.emit();
|
||||||
|
}
|
||||||
|
last_gps_mode = gps_data_.fix.mode;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string waybar::modules::Gps::getFixModeName() const {
|
const std::string waybar::modules::Gps::getFixModeName() const {
|
||||||
@ -93,9 +115,7 @@ const std::string waybar::modules::Gps::getFixStatusString() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto waybar::modules::Gps::update() -> void {
|
auto waybar::modules::Gps::update() -> void {
|
||||||
if (gps_read(&gps_data_, NULL, 0) == -1) {
|
sleep(0); // Wait for gps status change
|
||||||
throw std::runtime_error("Can't read data from gpsd.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((gps_data_.fix.mode == MODE_NOT_SEEN && hideDisconnected) || (gps_data_.fix.mode == MODE_NO_FIX && hideNoFix)) {
|
if ((gps_data_.fix.mode == MODE_NOT_SEEN && hideDisconnected) || (gps_data_.fix.mode == MODE_NO_FIX && hideNoFix)) {
|
||||||
event_box_.set_visible(false);
|
event_box_.set_visible(false);
|
||||||
|
Reference in New Issue
Block a user