mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpilib] MechanismLigament2d: Add getters for color and line weight (#3947)
Also add missing locking in C++.
This commit is contained in:
@@ -49,7 +49,20 @@ void MechanismLigament2d::SetLineWeight(double lineWidth) {
|
||||
Flush();
|
||||
}
|
||||
|
||||
Color8Bit MechanismLigament2d::GetColor() {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
if (m_colorEntry) {
|
||||
auto color = m_colorEntry.GetString("");
|
||||
std::strncpy(m_color, color.c_str(), sizeof(m_color));
|
||||
m_color[sizeof(m_color) - 1] = '\0';
|
||||
}
|
||||
unsigned int r = 0, g = 0, b = 0;
|
||||
std::sscanf(m_color, "#%02X%02X%02X", &r, &g, &b);
|
||||
return {static_cast<int>(r), static_cast<int>(g), static_cast<int>(b)};
|
||||
}
|
||||
|
||||
double MechanismLigament2d::GetAngle() {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
if (m_angleEntry) {
|
||||
m_angle = m_angleEntry.GetDouble(0.0);
|
||||
}
|
||||
@@ -57,12 +70,21 @@ double MechanismLigament2d::GetAngle() {
|
||||
}
|
||||
|
||||
double MechanismLigament2d::GetLength() {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
if (m_lengthEntry) {
|
||||
m_length = m_lengthEntry.GetDouble(0.0);
|
||||
}
|
||||
return m_length;
|
||||
}
|
||||
|
||||
double MechanismLigament2d::GetLineWeight() {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
if (m_weightEntry) {
|
||||
m_weight = m_weightEntry.GetDouble(0.0);
|
||||
}
|
||||
return m_weight;
|
||||
}
|
||||
|
||||
void MechanismLigament2d::SetLength(double length) {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
m_length = length;
|
||||
|
||||
Reference in New Issue
Block a user