Add confirmation to SendableChooser (#1217)

This echos back the "selected" value to the "active" key to enable dashboards
to display positive feedback to the user that the value is actually set on
the robot side.

Also fixes SendableChooser so it can be safely added to multiple tables.
Changes to "selected" in any table will result in all "active" values being
updated.

Now that adding SendableChooser to multiple tables is supported, an ".instance"
key enables dashboards to treat the same SendableChooser as a common instance
if desired.
This commit is contained in:
Peter Johnson
2018-07-28 10:43:47 -07:00
committed by GitHub
parent 397a296e25
commit 5fafaf6272
4 changed files with 99 additions and 12 deletions

View File

@@ -7,9 +7,12 @@
#pragma once
#include <atomic>
#include <string>
#include <networktables/NetworkTableEntry.h>
#include <wpi/SmallVector.h>
#include <wpi/mutex.h>
#include "frc/smartdashboard/SendableBase.h"
@@ -30,9 +33,16 @@ class SendableChooserBase : public SendableBase {
static constexpr const char* kDefault = "default";
static constexpr const char* kOptions = "options";
static constexpr const char* kSelected = "selected";
static constexpr const char* kActive = "active";
static constexpr const char* kInstance = ".instance";
std::string m_defaultChoice;
nt::NetworkTableEntry m_selectedEntry;
std::string m_selected;
bool m_haveSelected = false;
wpi::SmallVector<nt::NetworkTableEntry, 2> m_activeEntries;
wpi::mutex m_mutex;
int m_instance;
static std::atomic_int s_instances;
};
} // namespace frc