mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Fix SmartDashboard PutData to hook setters. (#851)
* Fix SmartDashboard PutData to hook setters. Also update all PutData values in main periodic loop (same as LiveWindow). * Improve SmartDashboard.putData() repeat call handling.
This commit is contained in:
committed by
bradamiller
parent
a3e5378d14
commit
40eb6dfc9b
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "Commands/Scheduler.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "SmartDashboard/SmartDashboard.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
@@ -192,5 +193,6 @@ void IterativeRobotBase::LoopFunc() {
|
||||
TestPeriodic();
|
||||
}
|
||||
RobotPeriodic();
|
||||
SmartDashboard::UpdateValues();
|
||||
LiveWindow::GetInstance()->UpdateValues();
|
||||
}
|
||||
|
||||
@@ -29,16 +29,24 @@ void SendableBuilderImpl::UpdateTable() {
|
||||
if (m_updateTable) m_updateTable();
|
||||
}
|
||||
|
||||
void SendableBuilderImpl::StartLiveWindowMode() {
|
||||
if (m_safeState) m_safeState();
|
||||
void SendableBuilderImpl::StartListeners() {
|
||||
for (auto& property : m_properties) property.StartListener();
|
||||
}
|
||||
|
||||
void SendableBuilderImpl::StopLiveWindowMode() {
|
||||
if (m_safeState) m_safeState();
|
||||
void SendableBuilderImpl::StopListeners() {
|
||||
for (auto& property : m_properties) property.StopListener();
|
||||
}
|
||||
|
||||
void SendableBuilderImpl::StartLiveWindowMode() {
|
||||
if (m_safeState) m_safeState();
|
||||
StartListeners();
|
||||
}
|
||||
|
||||
void SendableBuilderImpl::StopLiveWindowMode() {
|
||||
StopListeners();
|
||||
if (m_safeState) m_safeState();
|
||||
}
|
||||
|
||||
void SendableBuilderImpl::SetSmartDashboardType(const llvm::Twine& type) {
|
||||
m_table->GetEntry(".type").SetString(type);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,11 @@
|
||||
using namespace frc;
|
||||
|
||||
namespace {
|
||||
struct SmartDashboardData {
|
||||
class SmartDashboardData {
|
||||
public:
|
||||
SmartDashboardData() = default;
|
||||
explicit SmartDashboardData(Sendable* sendable_) : sendable(sendable_) {}
|
||||
|
||||
Sendable* sendable = nullptr;
|
||||
SendableBuilderImpl builder;
|
||||
};
|
||||
@@ -157,11 +161,12 @@ void SmartDashboard::PutData(llvm::StringRef key, Sendable* data) {
|
||||
std::lock_guard<wpi::mutex> lock(inst.tablesToDataMutex);
|
||||
auto& sddata = inst.tablesToData[key];
|
||||
if (!sddata.sendable || sddata.sendable != data) {
|
||||
sddata.sendable = data;
|
||||
sddata = SmartDashboardData(data);
|
||||
sddata.builder.SetTable(inst.table->GetSubTable(key));
|
||||
data->InitSendable(sddata.builder);
|
||||
sddata.builder.UpdateTable();
|
||||
sddata.builder.StartListeners();
|
||||
}
|
||||
sddata.builder.UpdateTable();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -541,3 +546,14 @@ std::string SmartDashboard::GetRaw(llvm::StringRef key,
|
||||
llvm::StringRef defaultValue) {
|
||||
return Singleton::GetInstance().table->GetEntry(key).GetRaw(defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts all sendable data to the dashboard.
|
||||
*/
|
||||
void SmartDashboard::UpdateValues() {
|
||||
auto& inst = Singleton::GetInstance();
|
||||
std::lock_guard<wpi::mutex> lock(inst.tablesToDataMutex);
|
||||
for (auto& i : inst.tablesToData) {
|
||||
i.getValue().builder.UpdateTable();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user