[ntcore] NetworkTables 4 (#3217)

This commit is contained in:
Peter Johnson
2022-10-08 10:01:31 -07:00
committed by GitHub
parent 90cfa00115
commit 77301b126c
380 changed files with 34573 additions and 22095 deletions

View File

@@ -21,38 +21,48 @@ MechanismLigament2d::MechanismLigament2d(std::string_view name, double length,
void MechanismLigament2d::UpdateEntries(
std::shared_ptr<nt::NetworkTable> table) {
table->GetEntry(".type").SetString("line");
m_typePub = table->GetStringTopic(".type").Publish();
m_typePub.Set("line");
m_colorEntry = table->GetEntry("color");
m_angleEntry = table->GetEntry("angle");
m_weightEntry = table->GetEntry("weight");
m_lengthEntry = table->GetEntry("length");
Flush();
m_colorEntry = table->GetStringTopic("color").GetEntry("");
m_colorEntry.Set(m_color);
m_angleEntry = table->GetDoubleTopic("angle").GetEntry(0.0);
m_angleEntry.Set(m_angle);
m_weightEntry = table->GetDoubleTopic("weight").GetEntry(0.0);
m_weightEntry.Set(m_weight);
m_lengthEntry = table->GetDoubleTopic("length").GetEntry(0.0);
m_lengthEntry.Set(m_length);
}
void MechanismLigament2d::SetColor(const Color8Bit& color) {
std::scoped_lock lock(m_mutex);
std::snprintf(m_color, sizeof(m_color), "#%02X%02X%02X", color.red,
color.green, color.blue);
Flush();
if (m_colorEntry) {
m_colorEntry.Set(m_color);
}
}
void MechanismLigament2d::SetAngle(units::degree_t angle) {
std::scoped_lock lock(m_mutex);
m_angle = angle.value();
Flush();
if (m_angleEntry) {
m_angleEntry.Set(m_angle);
}
}
void MechanismLigament2d::SetLineWeight(double lineWidth) {
std::scoped_lock lock(m_mutex);
m_weight = lineWidth;
Flush();
if (m_weightEntry) {
m_weightEntry.Set(m_weight);
}
}
Color8Bit MechanismLigament2d::GetColor() {
std::scoped_lock lock(m_mutex);
if (m_colorEntry) {
auto color = m_colorEntry.GetString("");
auto color = m_colorEntry.Get();
std::strncpy(m_color, color.c_str(), sizeof(m_color));
m_color[sizeof(m_color) - 1] = '\0';
}
@@ -64,7 +74,7 @@ Color8Bit MechanismLigament2d::GetColor() {
double MechanismLigament2d::GetAngle() {
std::scoped_lock lock(m_mutex);
if (m_angleEntry) {
m_angle = m_angleEntry.GetDouble(0.0);
m_angle = m_angleEntry.Get();
}
return m_angle;
}
@@ -72,7 +82,7 @@ double MechanismLigament2d::GetAngle() {
double MechanismLigament2d::GetLength() {
std::scoped_lock lock(m_mutex);
if (m_lengthEntry) {
m_length = m_lengthEntry.GetDouble(0.0);
m_length = m_lengthEntry.Get();
}
return m_length;
}
@@ -80,7 +90,7 @@ double MechanismLigament2d::GetLength() {
double MechanismLigament2d::GetLineWeight() {
std::scoped_lock lock(m_mutex);
if (m_weightEntry) {
m_weight = m_weightEntry.GetDouble(0.0);
m_weight = m_weightEntry.Get();
}
return m_weight;
}
@@ -88,16 +98,7 @@ double MechanismLigament2d::GetLineWeight() {
void MechanismLigament2d::SetLength(double length) {
std::scoped_lock lock(m_mutex);
m_length = length;
Flush();
}
#define SAFE_WRITE(data, Type) \
if (m_##data##Entry) { \
m_##data##Entry.Set##Type(m_##data); \
if (m_lengthEntry) {
m_lengthEntry.Set(length);
}
void MechanismLigament2d::Flush() {
SAFE_WRITE(color, String)
SAFE_WRITE(angle, Double)
SAFE_WRITE(length, Double)
SAFE_WRITE(weight, Double)
}