add all arguments
This commit is contained in:
@ -19,9 +19,10 @@ namespace waybar::modules {
|
|||||||
auto update() -> void override;
|
auto update() -> void override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const int getFixState() const;
|
const std::string getFixModeName() const;
|
||||||
const std::string getFixStateName() const;
|
const std::string getFixModeString() const;
|
||||||
const std::string getFixStateString() const;
|
|
||||||
|
const std::string getFixStatusString() const;
|
||||||
|
|
||||||
util::SleeperThread thread_;
|
util::SleeperThread thread_;
|
||||||
gps_data_t gps_data_;
|
gps_data_t gps_data_;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include "modules/gps.hpp"
|
#include "modules/gps.hpp"
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
// In the 80000 version of fmt library authors decided to optimize imports
|
// In the 80000 version of fmt library authors decided to optimize imports
|
||||||
// and moved declarations required for fmt::dynamic_format_arg_store in new
|
// and moved declarations required for fmt::dynamic_format_arg_store in new
|
||||||
@ -13,56 +15,84 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
using namespace waybar::util;
|
using namespace waybar::util;
|
||||||
constexpr const char *DEFAULT_FORMAT = "{status}";
|
constexpr const char *DEFAULT_FORMAT = "{mode}";
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
waybar::modules::Gps::Gps(const std::string& id, const Json::Value& config)
|
waybar::modules::Gps::Gps(const std::string& id, const Json::Value& config)
|
||||||
: ALabel(config, "gps", id, "{}", 30) {
|
: ALabel(config, "gps", id, "{}", 1) {
|
||||||
thread_ = [this] {
|
thread_ = [this] {
|
||||||
dp.emit();
|
dp.emit();
|
||||||
thread_.sleep_for(interval_);
|
thread_.sleep_for(interval_);
|
||||||
};
|
};
|
||||||
// TODO: connect to gpsd socket
|
|
||||||
|
|
||||||
if (0 != gps_open("localhost", "2947", &gps_data_)) {
|
if (0 != gps_open("localhost", "2947", &gps_data_)) {
|
||||||
throw std::runtime_error("Can't open gpsd socket");
|
throw std::runtime_error("Can't open gpsd socket");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gps_stream(&gps_data_, WATCH_ENABLE, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int waybar::modules::Gps::getFixState() const {
|
const std::string waybar::modules::Gps::getFixModeName() const {
|
||||||
0
|
switch (gps_data_.fix.mode) {
|
||||||
}
|
case MODE_NO_FIX:
|
||||||
|
return "fix-none";
|
||||||
const std::string waybar::modules::Gps::getFixStateName() const {
|
case MODE_2D:
|
||||||
switch (getFixState()) {
|
|
||||||
case 1:
|
|
||||||
return "fix-2d";
|
return "fix-2d";
|
||||||
case 2:
|
case MODE_3D:
|
||||||
return "fix-3d";
|
return "fix-3d";
|
||||||
default:
|
default:
|
||||||
return "fix-none";
|
return "disconnected";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string waybar::modules::Gps::getFixStateString() const {
|
const std::string waybar::modules::Gps::getFixModeString() const {
|
||||||
switch (getFixState()) {
|
switch (gps_data_.fix.mode) {
|
||||||
case 1:
|
case MODE_NO_FIX:
|
||||||
|
return "No fix";
|
||||||
|
case MODE_2D:
|
||||||
return "2D Fix";
|
return "2D Fix";
|
||||||
case 2:
|
case MODE_3D:
|
||||||
return "3D Fix";
|
return "3D Fix";
|
||||||
default:
|
default:
|
||||||
return "No fix";
|
return "Disconnected";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string waybar::modules::Gps::getFixStatusString() const {
|
||||||
|
switch (gps_data_.fix.status) {
|
||||||
|
case STATUS_UNK:
|
||||||
|
return "Unknown";
|
||||||
|
case STATUS_GPS:
|
||||||
|
return "GPS";
|
||||||
|
case STATUS_DGPS:
|
||||||
|
return "DGPS";
|
||||||
|
case STATUS_RTK_FIX:
|
||||||
|
return "RTK Fixed";
|
||||||
|
case STATUS_RTK_FLT:
|
||||||
|
return "RTK Float";
|
||||||
|
case STATUS_DR:
|
||||||
|
return "Dead Reckoning";
|
||||||
|
case STATUS_GNSSDR:
|
||||||
|
return "GNSS + Dead Reckoning";
|
||||||
|
case STATUS_TIME:
|
||||||
|
return "Time Only";
|
||||||
|
case STATUS_PPS_FIX:
|
||||||
|
return "PPS Fix";
|
||||||
|
default:
|
||||||
|
return "Unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto waybar::modules::Gps::update() -> void {
|
auto waybar::modules::Gps::update() -> void {
|
||||||
|
if (gps_read(&gps_data_, NULL, 0) == -1) {
|
||||||
|
throw std::runtime_error("Can't read data from gpsd.");
|
||||||
|
}
|
||||||
|
|
||||||
std::string tooltip_format;
|
std::string tooltip_format;
|
||||||
|
|
||||||
if (!alt_) {
|
if (!alt_) {
|
||||||
auto state = getFixStateName();
|
auto state = getFixModeName();
|
||||||
if (!state_.empty() && label_.get_style_context()->has_class(state_)) {
|
if (!state_.empty() && label_.get_style_context()->has_class(state_)) {
|
||||||
label_.get_style_context()->remove_class(state_);
|
label_.get_style_context()->remove_class(state_);
|
||||||
}
|
}
|
||||||
@ -87,14 +117,50 @@ auto waybar::modules::Gps::update() -> void {
|
|||||||
auto format = format_;
|
auto format = format_;
|
||||||
|
|
||||||
fmt::dynamic_format_arg_store<fmt::format_context> store;
|
fmt::dynamic_format_arg_store<fmt::format_context> store;
|
||||||
store.push_back(fmt::arg("status", getFixStateString()));
|
store.push_back(fmt::arg("mode", getFixModeString()));
|
||||||
|
store.push_back(fmt::arg("status", getFixStatusString()));
|
||||||
|
|
||||||
label_.set_markup(fmt::vformat(format, store));
|
store.push_back(fmt::arg("latitude", gps_data_.fix.latitude));
|
||||||
|
store.push_back(fmt::arg("latitude_error", gps_data_.fix.epy));
|
||||||
|
|
||||||
|
store.push_back(fmt::arg("longitude", gps_data_.fix.longitude));
|
||||||
|
store.push_back(fmt::arg("longitude_error", gps_data_.fix.epx));
|
||||||
|
|
||||||
|
store.push_back(fmt::arg("altitude_hae", gps_data_.fix.altHAE));
|
||||||
|
store.push_back(fmt::arg("altitude_msl", gps_data_.fix.altMSL));
|
||||||
|
store.push_back(fmt::arg("altitude_error", gps_data_.fix.epv));
|
||||||
|
|
||||||
|
store.push_back(fmt::arg("speed", gps_data_.fix.speed));
|
||||||
|
store.push_back(fmt::arg("speed_error", gps_data_.fix.eps));
|
||||||
|
|
||||||
|
store.push_back(fmt::arg("climb", gps_data_.fix.climb));
|
||||||
|
store.push_back(fmt::arg("climb_error", gps_data_.fix.epc));
|
||||||
|
|
||||||
|
store.push_back(fmt::arg("satellites_used", gps_data_.satellites_used));
|
||||||
|
store.push_back(fmt::arg("satellites_visible", gps_data_.satellites_visible));
|
||||||
|
|
||||||
|
auto text = fmt::vformat(format, store);
|
||||||
|
|
||||||
|
if (tooltipEnabled()) {
|
||||||
|
if (tooltip_format.empty() && config_["tooltip-format"].isString()) {
|
||||||
|
tooltip_format = config_["tooltip-format"].asString();
|
||||||
|
}
|
||||||
|
if (!tooltip_format.empty()) {
|
||||||
|
auto tooltip_text = fmt::vformat(tooltip_format, store);
|
||||||
|
if (label_.get_tooltip_text() != tooltip_text) {
|
||||||
|
label_.set_tooltip_markup(tooltip_text);
|
||||||
|
}
|
||||||
|
} else if (label_.get_tooltip_text() != text) {
|
||||||
|
label_.set_tooltip_markup(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
label_.set_markup(text);
|
||||||
// Call parent update
|
// Call parent update
|
||||||
ALabel::update();
|
ALabel::update();
|
||||||
}
|
}
|
||||||
|
|
||||||
waybar::modules::Gps::~Gps() {
|
waybar::modules::Gps::~Gps() {
|
||||||
|
gps_stream(&gps_data_, WATCH_DISABLE, NULL);
|
||||||
gps_close(&gps_data_);
|
gps_close(&gps_data_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user