mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[ntcore] NetworkTables 4 (#3217)
This commit is contained in:
@@ -4,9 +4,10 @@
|
||||
|
||||
#include "frc/livewindow/LiveWindow.h"
|
||||
|
||||
#include <networktables/BooleanTopic.h>
|
||||
#include <networktables/NetworkTable.h>
|
||||
#include <networktables/NetworkTableEntry.h>
|
||||
#include <networktables/NetworkTableInstance.h>
|
||||
#include <networktables/StringTopic.h>
|
||||
#include <wpi/mutex.h>
|
||||
#include <wpi/sendable/Sendable.h>
|
||||
#include <wpi/sendable/SendableRegistry.h>
|
||||
@@ -19,12 +20,15 @@ namespace {
|
||||
struct Component {
|
||||
bool firstTime = true;
|
||||
bool telemetryEnabled = false;
|
||||
nt::StringPublisher namePub;
|
||||
nt::StringPublisher typePub;
|
||||
};
|
||||
|
||||
struct Instance {
|
||||
Instance() {
|
||||
wpi::SendableRegistry::SetLiveWindowBuilderFactory(
|
||||
[] { return std::make_unique<SendableBuilderImpl>(); });
|
||||
enabledPub.Set(false);
|
||||
}
|
||||
|
||||
wpi::mutex mutex;
|
||||
@@ -35,7 +39,8 @@ struct Instance {
|
||||
nt::NetworkTableInstance::GetDefault().GetTable("LiveWindow");
|
||||
std::shared_ptr<nt::NetworkTable> statusTable =
|
||||
liveWindowTable->GetSubTable(".status");
|
||||
nt::NetworkTableEntry enabledEntry = statusTable->GetEntry("LW Enabled");
|
||||
nt::BooleanPublisher enabledPub =
|
||||
statusTable->GetBooleanTopic("LW Enabled").Publish();
|
||||
|
||||
bool startLiveWindow = false;
|
||||
bool liveWindowEnabled = false;
|
||||
@@ -139,7 +144,7 @@ void LiveWindow::SetEnabled(bool enabled) {
|
||||
inst.disabled();
|
||||
}
|
||||
}
|
||||
inst.enabledEntry.SetBoolean(enabled);
|
||||
inst.enabledPub.Set(enabled);
|
||||
}
|
||||
|
||||
void LiveWindow::UpdateValues() {
|
||||
@@ -186,10 +191,12 @@ void LiveWindow::UpdateValuesUnsafe() {
|
||||
} else {
|
||||
table = ssTable->GetSubTable(cbdata.name);
|
||||
}
|
||||
table->GetEntry(".name").SetString(cbdata.name);
|
||||
comp.namePub = nt::StringTopic{table->GetTopic(".name")}.Publish();
|
||||
comp.namePub.Set(cbdata.name);
|
||||
static_cast<SendableBuilderImpl&>(cbdata.builder).SetTable(table);
|
||||
cbdata.sendable->InitSendable(cbdata.builder);
|
||||
ssTable->GetEntry(".type").SetString("LW Subsystem");
|
||||
comp.typePub = nt::StringTopic{ssTable->GetTopic(".type")}.Publish();
|
||||
comp.typePub.Set("LW Subsystem");
|
||||
|
||||
comp.firstTime = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user