mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +00:00
[wpilib] Deprecate getInstance() in favor of static functions (#3440)
Co-authored-by: Noam Zaks <imnoamzaks@gmail.com>
This commit is contained in:
@@ -4,24 +4,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <hal/DriverStationTypes.h>
|
||||
#include <units/time.h>
|
||||
#include <wpi/condition_variable.h>
|
||||
#include <wpi/mutex.h>
|
||||
#include <wpi/deprecated.h>
|
||||
|
||||
namespace frc {
|
||||
|
||||
class MatchDataSender;
|
||||
|
||||
/**
|
||||
* Provide access to the network communication data to / from the Driver
|
||||
* Station.
|
||||
@@ -31,16 +20,13 @@ class DriverStation {
|
||||
enum Alliance { kRed, kBlue, kInvalid };
|
||||
enum MatchType { kNone, kPractice, kQualification, kElimination };
|
||||
|
||||
~DriverStation();
|
||||
|
||||
DriverStation(const DriverStation&) = delete;
|
||||
DriverStation& operator=(const DriverStation&) = delete;
|
||||
|
||||
/**
|
||||
* Return a reference to the singleton DriverStation.
|
||||
*
|
||||
* @return Reference to the DS instance
|
||||
* @deprecated Use the static methods
|
||||
*/
|
||||
WPI_DEPRECATED("Use static methods")
|
||||
static DriverStation& GetInstance();
|
||||
|
||||
static constexpr int kJoystickPorts = 6;
|
||||
@@ -52,7 +38,7 @@ class DriverStation {
|
||||
* @param button The button index, beginning at 1.
|
||||
* @return The state of the joystick button.
|
||||
*/
|
||||
bool GetStickButton(int stick, int button);
|
||||
static bool GetStickButton(int stick, int button);
|
||||
|
||||
/**
|
||||
* Whether one joystick button was pressed since the last check. Button
|
||||
@@ -62,7 +48,7 @@ class DriverStation {
|
||||
* @param button The button index, beginning at 1.
|
||||
* @return Whether the joystick button was pressed since the last check.
|
||||
*/
|
||||
bool GetStickButtonPressed(int stick, int button);
|
||||
static bool GetStickButtonPressed(int stick, int button);
|
||||
|
||||
/**
|
||||
* Whether one joystick button was released since the last check. Button
|
||||
@@ -72,7 +58,7 @@ class DriverStation {
|
||||
* @param button The button index, beginning at 1.
|
||||
* @return Whether the joystick button was released since the last check.
|
||||
*/
|
||||
bool GetStickButtonReleased(int stick, int button);
|
||||
static bool GetStickButtonReleased(int stick, int button);
|
||||
|
||||
/**
|
||||
* Get the value of the axis on a joystick.
|
||||
@@ -84,14 +70,14 @@ class DriverStation {
|
||||
* @param axis The analog axis value to read from the joystick.
|
||||
* @return The value of the axis on the joystick.
|
||||
*/
|
||||
double GetStickAxis(int stick, int axis);
|
||||
static double GetStickAxis(int stick, int axis);
|
||||
|
||||
/**
|
||||
* Get the state of a POV on the joystick.
|
||||
*
|
||||
* @return the angle of the POV in degrees, or -1 if the POV is not pressed.
|
||||
*/
|
||||
int GetStickPOV(int stick, int pov);
|
||||
static int GetStickPOV(int stick, int pov);
|
||||
|
||||
/**
|
||||
* The state of the buttons on the joystick.
|
||||
@@ -99,7 +85,7 @@ class DriverStation {
|
||||
* @param stick The joystick to read.
|
||||
* @return The state of the buttons on the joystick.
|
||||
*/
|
||||
int GetStickButtons(int stick) const;
|
||||
static int GetStickButtons(int stick);
|
||||
|
||||
/**
|
||||
* Returns the number of axes on a given joystick port.
|
||||
@@ -107,7 +93,7 @@ class DriverStation {
|
||||
* @param stick The joystick port number
|
||||
* @return The number of axes on the indicated joystick
|
||||
*/
|
||||
int GetStickAxisCount(int stick) const;
|
||||
static int GetStickAxisCount(int stick);
|
||||
|
||||
/**
|
||||
* Returns the number of POVs on a given joystick port.
|
||||
@@ -115,7 +101,7 @@ class DriverStation {
|
||||
* @param stick The joystick port number
|
||||
* @return The number of POVs on the indicated joystick
|
||||
*/
|
||||
int GetStickPOVCount(int stick) const;
|
||||
static int GetStickPOVCount(int stick);
|
||||
|
||||
/**
|
||||
* Returns the number of buttons on a given joystick port.
|
||||
@@ -123,7 +109,7 @@ class DriverStation {
|
||||
* @param stick The joystick port number
|
||||
* @return The number of buttons on the indicated joystick
|
||||
*/
|
||||
int GetStickButtonCount(int stick) const;
|
||||
static int GetStickButtonCount(int stick);
|
||||
|
||||
/**
|
||||
* Returns a boolean indicating if the controller is an xbox controller.
|
||||
@@ -131,7 +117,7 @@ class DriverStation {
|
||||
* @param stick The joystick port number
|
||||
* @return A boolean that is true if the controller is an xbox controller.
|
||||
*/
|
||||
bool GetJoystickIsXbox(int stick) const;
|
||||
static bool GetJoystickIsXbox(int stick);
|
||||
|
||||
/**
|
||||
* Returns the type of joystick at a given port.
|
||||
@@ -139,7 +125,7 @@ class DriverStation {
|
||||
* @param stick The joystick port number
|
||||
* @return The HID type of joystick at the given port
|
||||
*/
|
||||
int GetJoystickType(int stick) const;
|
||||
static int GetJoystickType(int stick);
|
||||
|
||||
/**
|
||||
* Returns the name of the joystick at the given port.
|
||||
@@ -147,7 +133,7 @@ class DriverStation {
|
||||
* @param stick The joystick port number
|
||||
* @return The name of the joystick at the given port
|
||||
*/
|
||||
std::string GetJoystickName(int stick) const;
|
||||
static std::string GetJoystickName(int stick);
|
||||
|
||||
/**
|
||||
* Returns the types of Axes on a given joystick port.
|
||||
@@ -155,7 +141,7 @@ class DriverStation {
|
||||
* @param stick The joystick port number and the target axis
|
||||
* @return What type of axis the axis is reporting to be
|
||||
*/
|
||||
int GetJoystickAxisType(int stick, int axis) const;
|
||||
static int GetJoystickAxisType(int stick, int axis);
|
||||
|
||||
/**
|
||||
* Returns if a joystick is connected to the Driver Station.
|
||||
@@ -166,35 +152,35 @@ class DriverStation {
|
||||
* @param stick The joystick port number
|
||||
* @return true if a joystick is connected
|
||||
*/
|
||||
bool IsJoystickConnected(int stick) const;
|
||||
static bool IsJoystickConnected(int stick);
|
||||
|
||||
/**
|
||||
* Check if the DS has enabled the robot.
|
||||
*
|
||||
* @return True if the robot is enabled and the DS is connected
|
||||
*/
|
||||
bool IsEnabled() const;
|
||||
static bool IsEnabled();
|
||||
|
||||
/**
|
||||
* Check if the robot is disabled.
|
||||
*
|
||||
* @return True if the robot is explicitly disabled or the DS is not connected
|
||||
*/
|
||||
bool IsDisabled() const;
|
||||
static bool IsDisabled();
|
||||
|
||||
/**
|
||||
* Check if the robot is e-stopped.
|
||||
*
|
||||
* @return True if the robot is e-stopped
|
||||
*/
|
||||
bool IsEStopped() const;
|
||||
static bool IsEStopped();
|
||||
|
||||
/**
|
||||
* Check if the DS is commanding autonomous mode.
|
||||
*
|
||||
* @return True if the robot is being commanded to be in autonomous mode
|
||||
*/
|
||||
bool IsAutonomous() const;
|
||||
static bool IsAutonomous();
|
||||
|
||||
/**
|
||||
* Check if the DS is commanding autonomous mode and if it has enabled the
|
||||
@@ -203,14 +189,14 @@ class DriverStation {
|
||||
* @return True if the robot is being commanded to be in autonomous mode and
|
||||
* enabled.
|
||||
*/
|
||||
bool IsAutonomousEnabled() const;
|
||||
static bool IsAutonomousEnabled();
|
||||
|
||||
/**
|
||||
* Check if the DS is commanding teleop mode.
|
||||
*
|
||||
* @return True if the robot is being commanded to be in teleop mode
|
||||
*/
|
||||
bool IsOperatorControl() const;
|
||||
static bool IsOperatorControl();
|
||||
|
||||
/**
|
||||
* Check if the DS is commanding teleop mode and if it has enabled the robot.
|
||||
@@ -218,21 +204,21 @@ class DriverStation {
|
||||
* @return True if the robot is being commanded to be in teleop mode and
|
||||
* enabled.
|
||||
*/
|
||||
bool IsOperatorControlEnabled() const;
|
||||
static bool IsOperatorControlEnabled();
|
||||
|
||||
/**
|
||||
* Check if the DS is commanding test mode.
|
||||
*
|
||||
* @return True if the robot is being commanded to be in test mode
|
||||
*/
|
||||
bool IsTest() const;
|
||||
static bool IsTest();
|
||||
|
||||
/**
|
||||
* Check if the DS is attached.
|
||||
*
|
||||
* @return True if the DS is connected to the robot
|
||||
*/
|
||||
bool IsDSAttached() const;
|
||||
static bool IsDSAttached();
|
||||
|
||||
/**
|
||||
* Has a new control packet from the driver station arrived since the last
|
||||
@@ -243,7 +229,7 @@ class DriverStation {
|
||||
*
|
||||
* @return True if the control data has been updated since the last call.
|
||||
*/
|
||||
bool IsNewControlData() const;
|
||||
static bool IsNewControlData();
|
||||
|
||||
/**
|
||||
* Is the driver station attached to a Field Management System?
|
||||
@@ -251,21 +237,21 @@ class DriverStation {
|
||||
* @return True if the robot is competing on a field being controlled by a
|
||||
* Field Management System
|
||||
*/
|
||||
bool IsFMSAttached() const;
|
||||
static bool IsFMSAttached();
|
||||
|
||||
/**
|
||||
* Returns the game specific message provided by the FMS.
|
||||
*
|
||||
* @return A string containing the game specific message.
|
||||
*/
|
||||
std::string GetGameSpecificMessage() const;
|
||||
static std::string GetGameSpecificMessage();
|
||||
|
||||
/**
|
||||
* Returns the name of the competition event provided by the FMS.
|
||||
*
|
||||
* @return A string containing the event name
|
||||
*/
|
||||
std::string GetEventName() const;
|
||||
static std::string GetEventName();
|
||||
|
||||
/**
|
||||
* Returns the type of match being played provided by the FMS.
|
||||
@@ -273,14 +259,14 @@ class DriverStation {
|
||||
* @return The match type enum (kNone, kPractice, kQualification,
|
||||
* kElimination)
|
||||
*/
|
||||
MatchType GetMatchType() const;
|
||||
static MatchType GetMatchType();
|
||||
|
||||
/**
|
||||
* Returns the match number provided by the FMS.
|
||||
*
|
||||
* @return The number of the match
|
||||
*/
|
||||
int GetMatchNumber() const;
|
||||
static int GetMatchNumber();
|
||||
|
||||
/**
|
||||
* Returns the number of times the current match has been replayed from the
|
||||
@@ -288,7 +274,7 @@ class DriverStation {
|
||||
*
|
||||
* @return The number of replays
|
||||
*/
|
||||
int GetReplayNumber() const;
|
||||
static int GetReplayNumber();
|
||||
|
||||
/**
|
||||
* Return the alliance that the driver station says it is on.
|
||||
@@ -297,7 +283,7 @@ class DriverStation {
|
||||
*
|
||||
* @return The Alliance enum (kRed, kBlue or kInvalid)
|
||||
*/
|
||||
Alliance GetAlliance() const;
|
||||
static Alliance GetAlliance();
|
||||
|
||||
/**
|
||||
* Return the driver station location on the field.
|
||||
@@ -306,7 +292,7 @@ class DriverStation {
|
||||
*
|
||||
* @return The location of the driver station (1-3, 0 for invalid)
|
||||
*/
|
||||
int GetLocation() const;
|
||||
static int GetLocation();
|
||||
|
||||
/**
|
||||
* Wait until a new packet comes from the driver station.
|
||||
@@ -319,7 +305,7 @@ class DriverStation {
|
||||
* Checks if new control data has arrived since the last waitForData call
|
||||
* on the current thread. If new data has not arrived, returns immediately.
|
||||
*/
|
||||
void WaitForData();
|
||||
static void WaitForData();
|
||||
|
||||
/**
|
||||
* Wait until a new packet comes from the driver station, or wait for a
|
||||
@@ -341,7 +327,7 @@ class DriverStation {
|
||||
*
|
||||
* @return true if new data, otherwise false
|
||||
*/
|
||||
bool WaitForData(units::second_t timeout);
|
||||
static bool WaitForData(units::second_t timeout);
|
||||
|
||||
/**
|
||||
* Return the approximate match time.
|
||||
@@ -358,14 +344,14 @@ class DriverStation {
|
||||
*
|
||||
* @return Time remaining in current match period (auto or teleop)
|
||||
*/
|
||||
double GetMatchTime() const;
|
||||
static double GetMatchTime();
|
||||
|
||||
/**
|
||||
* Read the battery voltage.
|
||||
*
|
||||
* @return The battery voltage in Volts.
|
||||
*/
|
||||
double GetBatteryVoltage() const;
|
||||
static double GetBatteryVoltage();
|
||||
|
||||
/**
|
||||
* Only to be used to tell the Driver Station what code you claim to be
|
||||
@@ -374,7 +360,7 @@ class DriverStation {
|
||||
* @param entering If true, starting disabled code; if false, leaving disabled
|
||||
* code.
|
||||
*/
|
||||
void InDisabled(bool entering) { m_userInDisabled = entering; }
|
||||
static void InDisabled(bool entering);
|
||||
|
||||
/**
|
||||
* Only to be used to tell the Driver Station what code you claim to be
|
||||
@@ -383,7 +369,7 @@ class DriverStation {
|
||||
* @param entering If true, starting autonomous code; if false, leaving
|
||||
* autonomous code.
|
||||
*/
|
||||
void InAutonomous(bool entering) { m_userInAutonomous = entering; }
|
||||
static void InAutonomous(bool entering);
|
||||
|
||||
/**
|
||||
* Only to be used to tell the Driver Station what code you claim to be
|
||||
@@ -392,7 +378,7 @@ class DriverStation {
|
||||
* @param entering If true, starting teleop code; if false, leaving teleop
|
||||
* code.
|
||||
*/
|
||||
void InOperatorControl(bool entering) { m_userInTeleop = entering; }
|
||||
static void InOperatorControl(bool entering);
|
||||
|
||||
/**
|
||||
* Only to be used to tell the Driver Station what code you claim to be
|
||||
@@ -400,12 +386,12 @@ class DriverStation {
|
||||
*
|
||||
* @param entering If true, starting test code; if false, leaving test code.
|
||||
*/
|
||||
void InTest(bool entering) { m_userInTest = entering; }
|
||||
static void InTest(bool entering);
|
||||
|
||||
/**
|
||||
* Forces WaitForData() to return immediately.
|
||||
*/
|
||||
void WakeupWaitForData();
|
||||
static void WakeupWaitForData();
|
||||
|
||||
/**
|
||||
* Allows the user to specify whether they want joystick connection warnings
|
||||
@@ -414,7 +400,7 @@ class DriverStation {
|
||||
*
|
||||
* @param silence Whether warning messages should be silenced.
|
||||
*/
|
||||
void SilenceJoystickConnectionWarning(bool silence);
|
||||
static void SilenceJoystickConnectionWarning(bool silence);
|
||||
|
||||
/**
|
||||
* Returns whether joystick connection warnings are silenced. This will
|
||||
@@ -422,82 +408,10 @@ class DriverStation {
|
||||
*
|
||||
* @return Whether joystick connection warnings are silenced.
|
||||
*/
|
||||
bool IsJoystickConnectionWarningSilenced() const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Copy data from the DS task for the user.
|
||||
*
|
||||
* If no new data exists, it will just be returned, otherwise
|
||||
* the data will be copied from the DS polling loop.
|
||||
*/
|
||||
void GetData();
|
||||
static bool IsJoystickConnectionWarningSilenced();
|
||||
|
||||
private:
|
||||
/**
|
||||
* DriverStation constructor.
|
||||
*
|
||||
* This is only called once the first time GetInstance() is called
|
||||
*/
|
||||
DriverStation();
|
||||
|
||||
/**
|
||||
* Reports errors related to unplugged joysticks.
|
||||
*
|
||||
* Throttles the errors so that they don't overwhelm the DS.
|
||||
*/
|
||||
void ReportJoystickUnpluggedErrorV(fmt::string_view format,
|
||||
fmt::format_args args);
|
||||
|
||||
template <typename S, typename... Args>
|
||||
inline void ReportJoystickUnpluggedError(const S& format, Args&&... args) {
|
||||
ReportJoystickUnpluggedErrorV(
|
||||
format, fmt::make_args_checked<Args...>(format, args...));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reports errors related to unplugged joysticks.
|
||||
*
|
||||
* Throttles the errors so that they don't overwhelm the DS.
|
||||
*/
|
||||
void ReportJoystickUnpluggedWarningV(fmt::string_view format,
|
||||
fmt::format_args args);
|
||||
|
||||
template <typename S, typename... Args>
|
||||
inline void ReportJoystickUnpluggedWarning(const S& format, Args&&... args) {
|
||||
ReportJoystickUnpluggedWarningV(
|
||||
format, fmt::make_args_checked<Args...>(format, args...));
|
||||
}
|
||||
|
||||
void Run();
|
||||
|
||||
void SendMatchData();
|
||||
|
||||
std::unique_ptr<MatchDataSender> m_matchDataSender;
|
||||
|
||||
// Joystick button rising/falling edge flags
|
||||
wpi::mutex m_buttonEdgeMutex;
|
||||
std::array<HAL_JoystickButtons, kJoystickPorts> m_previousButtonStates;
|
||||
std::array<uint32_t, kJoystickPorts> m_joystickButtonsPressed;
|
||||
std::array<uint32_t, kJoystickPorts> m_joystickButtonsReleased;
|
||||
|
||||
// Internal Driver Station thread
|
||||
std::thread m_dsThread;
|
||||
std::atomic<bool> m_isRunning{false};
|
||||
|
||||
mutable wpi::mutex m_waitForDataMutex;
|
||||
wpi::condition_variable m_waitForDataCond;
|
||||
int m_waitForDataCounter;
|
||||
|
||||
bool m_silenceJoystickWarning = false;
|
||||
|
||||
// Robot state status variables
|
||||
bool m_userInDisabled = false;
|
||||
bool m_userInAutonomous = false;
|
||||
bool m_userInTeleop = false;
|
||||
bool m_userInTest = false;
|
||||
|
||||
units::second_t m_nextMessageTime = 0_s;
|
||||
DriverStation() = default;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -192,7 +192,6 @@ class GenericHID {
|
||||
void SetRumble(RumbleType type, double value);
|
||||
|
||||
private:
|
||||
DriverStation* m_ds;
|
||||
int m_port;
|
||||
int m_outputs = 0;
|
||||
uint16_t m_leftRumble = 0;
|
||||
|
||||
@@ -6,12 +6,10 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <networktables/NetworkTable.h>
|
||||
#include <wpi/deprecated.h>
|
||||
|
||||
namespace frc {
|
||||
@@ -36,7 +34,9 @@ class Preferences {
|
||||
* Get the one and only {@link Preferences} object.
|
||||
*
|
||||
* @return pointer to the {@link Preferences}
|
||||
* @deprecated Use the static methods
|
||||
*/
|
||||
WPI_DEPRECATED("Use static methods")
|
||||
static Preferences* GetInstance();
|
||||
|
||||
/**
|
||||
@@ -44,7 +44,7 @@ class Preferences {
|
||||
*
|
||||
* @return a vector of the keys
|
||||
*/
|
||||
std::vector<std::string> GetKeys();
|
||||
static std::vector<std::string> GetKeys();
|
||||
|
||||
/**
|
||||
* Returns the string at the given key. If this table does not have a value
|
||||
@@ -54,8 +54,8 @@ class Preferences {
|
||||
* @param defaultValue the value to return if none exists in the table
|
||||
* @return either the value in the table, or the defaultValue
|
||||
*/
|
||||
std::string GetString(std::string_view key,
|
||||
std::string_view defaultValue = "");
|
||||
static std::string GetString(std::string_view key,
|
||||
std::string_view defaultValue = "");
|
||||
|
||||
/**
|
||||
* Returns the int at the given key. If this table does not have a value for
|
||||
@@ -65,7 +65,7 @@ class Preferences {
|
||||
* @param defaultValue the value to return if none exists in the table
|
||||
* @return either the value in the table, or the defaultValue
|
||||
*/
|
||||
int GetInt(std::string_view key, int defaultValue = 0);
|
||||
static int GetInt(std::string_view key, int defaultValue = 0);
|
||||
|
||||
/**
|
||||
* Returns the double at the given key. If this table does not have a value
|
||||
@@ -75,7 +75,7 @@ class Preferences {
|
||||
* @param defaultValue the value to return if none exists in the table
|
||||
* @return either the value in the table, or the defaultValue
|
||||
*/
|
||||
double GetDouble(std::string_view key, double defaultValue = 0.0);
|
||||
static double GetDouble(std::string_view key, double defaultValue = 0.0);
|
||||
|
||||
/**
|
||||
* Returns the float at the given key. If this table does not have a value
|
||||
@@ -85,7 +85,7 @@ class Preferences {
|
||||
* @param defaultValue the value to return if none exists in the table
|
||||
* @return either the value in the table, or the defaultValue
|
||||
*/
|
||||
float GetFloat(std::string_view key, float defaultValue = 0.0);
|
||||
static float GetFloat(std::string_view key, float defaultValue = 0.0);
|
||||
|
||||
/**
|
||||
* Returns the boolean at the given key. If this table does not have a value
|
||||
@@ -95,7 +95,7 @@ class Preferences {
|
||||
* @param defaultValue the value to return if none exists in the table
|
||||
* @return either the value in the table, or the defaultValue
|
||||
*/
|
||||
bool GetBoolean(std::string_view key, bool defaultValue = false);
|
||||
static bool GetBoolean(std::string_view key, bool defaultValue = false);
|
||||
|
||||
/**
|
||||
* Returns the long (int64_t) at the given key. If this table does not have a
|
||||
@@ -106,7 +106,7 @@ class Preferences {
|
||||
* @param defaultValue the value to return if none exists in the table
|
||||
* @return either the value in the table, or the defaultValue
|
||||
*/
|
||||
int64_t GetLong(std::string_view key, int64_t defaultValue = 0);
|
||||
static int64_t GetLong(std::string_view key, int64_t defaultValue = 0);
|
||||
|
||||
/**
|
||||
* Puts the given string into the preferences table.
|
||||
@@ -117,7 +117,7 @@ class Preferences {
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
*/
|
||||
void SetString(std::string_view key, std::string_view value);
|
||||
static void SetString(std::string_view key, std::string_view value);
|
||||
|
||||
/**
|
||||
* Puts the given string into the preferences table.
|
||||
@@ -129,13 +129,13 @@ class Preferences {
|
||||
* @param value the value
|
||||
*/
|
||||
WPI_DEPRECATED("Use SetString instead.")
|
||||
void PutString(std::string_view key, std::string_view value);
|
||||
static void PutString(std::string_view key, std::string_view value);
|
||||
|
||||
/**
|
||||
* Puts the given string into the preferences table if it doesn't
|
||||
* already exist.
|
||||
*/
|
||||
void InitString(std::string_view key, std::string_view value);
|
||||
static void InitString(std::string_view key, std::string_view value);
|
||||
|
||||
/**
|
||||
* Puts the given int into the preferences table.
|
||||
@@ -145,7 +145,7 @@ class Preferences {
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
*/
|
||||
void SetInt(std::string_view key, int value);
|
||||
static void SetInt(std::string_view key, int value);
|
||||
|
||||
/**
|
||||
* Puts the given int into the preferences table.
|
||||
@@ -156,13 +156,13 @@ class Preferences {
|
||||
* @param value the value
|
||||
*/
|
||||
WPI_DEPRECATED("Use SetInt instead.")
|
||||
void PutInt(std::string_view key, int value);
|
||||
static void PutInt(std::string_view key, int value);
|
||||
|
||||
/**
|
||||
* Puts the given int into the preferences table if it doesn't
|
||||
* already exist.
|
||||
*/
|
||||
void InitInt(std::string_view key, int value);
|
||||
static void InitInt(std::string_view key, int value);
|
||||
|
||||
/**
|
||||
* Puts the given double into the preferences table.
|
||||
@@ -172,7 +172,7 @@ class Preferences {
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
*/
|
||||
void SetDouble(std::string_view key, double value);
|
||||
static void SetDouble(std::string_view key, double value);
|
||||
|
||||
/**
|
||||
* Puts the given double into the preferences table.
|
||||
@@ -183,13 +183,13 @@ class Preferences {
|
||||
* @param value the value
|
||||
*/
|
||||
WPI_DEPRECATED("Use SetDouble instead.")
|
||||
void PutDouble(std::string_view key, double value);
|
||||
static void PutDouble(std::string_view key, double value);
|
||||
|
||||
/**
|
||||
* Puts the given double into the preferences table if it doesn't
|
||||
* already exist.
|
||||
*/
|
||||
void InitDouble(std::string_view key, double value);
|
||||
static void InitDouble(std::string_view key, double value);
|
||||
|
||||
/**
|
||||
* Puts the given float into the preferences table.
|
||||
@@ -199,7 +199,7 @@ class Preferences {
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
*/
|
||||
void SetFloat(std::string_view key, float value);
|
||||
static void SetFloat(std::string_view key, float value);
|
||||
|
||||
/**
|
||||
* Puts the given float into the preferences table.
|
||||
@@ -210,13 +210,13 @@ class Preferences {
|
||||
* @param value the value
|
||||
*/
|
||||
WPI_DEPRECATED("Use SetFloat instead.")
|
||||
void PutFloat(std::string_view key, float value);
|
||||
static void PutFloat(std::string_view key, float value);
|
||||
|
||||
/**
|
||||
* Puts the given float into the preferences table if it doesn't
|
||||
* already exist.
|
||||
*/
|
||||
void InitFloat(std::string_view key, float value);
|
||||
static void InitFloat(std::string_view key, float value);
|
||||
|
||||
/**
|
||||
* Puts the given boolean into the preferences table.
|
||||
@@ -226,7 +226,7 @@ class Preferences {
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
*/
|
||||
void SetBoolean(std::string_view key, bool value);
|
||||
static void SetBoolean(std::string_view key, bool value);
|
||||
|
||||
/**
|
||||
* Puts the given boolean into the preferences table.
|
||||
@@ -237,13 +237,13 @@ class Preferences {
|
||||
* @param value the value
|
||||
*/
|
||||
WPI_DEPRECATED("Use SetBoolean instead.")
|
||||
void PutBoolean(std::string_view key, bool value);
|
||||
static void PutBoolean(std::string_view key, bool value);
|
||||
|
||||
/**
|
||||
* Puts the given boolean into the preferences table if it doesn't
|
||||
* already exist.
|
||||
*/
|
||||
void InitBoolean(std::string_view key, bool value);
|
||||
static void InitBoolean(std::string_view key, bool value);
|
||||
|
||||
/**
|
||||
* Puts the given long (int64_t) into the preferences table.
|
||||
@@ -253,7 +253,7 @@ class Preferences {
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
*/
|
||||
void SetLong(std::string_view key, int64_t value);
|
||||
static void SetLong(std::string_view key, int64_t value);
|
||||
|
||||
/**
|
||||
* Puts the given long (int64_t) into the preferences table.
|
||||
@@ -264,13 +264,13 @@ class Preferences {
|
||||
* @param value the value
|
||||
*/
|
||||
WPI_DEPRECATED("Use SetLong instead.")
|
||||
void PutLong(std::string_view key, int64_t value);
|
||||
static void PutLong(std::string_view key, int64_t value);
|
||||
|
||||
/**
|
||||
* Puts the given long into the preferences table if it doesn't
|
||||
* already exist.
|
||||
*/
|
||||
void InitLong(std::string_view key, int64_t value);
|
||||
static void InitLong(std::string_view key, int64_t value);
|
||||
|
||||
/**
|
||||
* Returns whether or not there is a key with the given name.
|
||||
@@ -278,29 +278,22 @@ class Preferences {
|
||||
* @param key the key
|
||||
* @return if there is a value at the given key
|
||||
*/
|
||||
bool ContainsKey(std::string_view key);
|
||||
static bool ContainsKey(std::string_view key);
|
||||
|
||||
/**
|
||||
* Remove a preference.
|
||||
*
|
||||
* @param key the key
|
||||
*/
|
||||
void Remove(std::string_view key);
|
||||
static void Remove(std::string_view key);
|
||||
|
||||
/**
|
||||
* Remove all preferences.
|
||||
*/
|
||||
void RemoveAll();
|
||||
|
||||
protected:
|
||||
Preferences();
|
||||
|
||||
Preferences(Preferences&&) = default;
|
||||
Preferences& operator=(Preferences&&) = default;
|
||||
static void RemoveAll();
|
||||
|
||||
private:
|
||||
std::shared_ptr<nt::NetworkTable> m_table;
|
||||
NT_EntryListener m_listener;
|
||||
Preferences() = default;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -215,15 +215,11 @@ class RobotBase {
|
||||
*/
|
||||
RobotBase();
|
||||
|
||||
virtual ~RobotBase();
|
||||
virtual ~RobotBase() = default;
|
||||
|
||||
protected:
|
||||
// m_ds isn't moved in these because DriverStation is a singleton; every
|
||||
// instance of RobotBase has a reference to the same object.
|
||||
RobotBase(RobotBase&&) noexcept;
|
||||
RobotBase& operator=(RobotBase&&) noexcept;
|
||||
|
||||
DriverStation& m_ds;
|
||||
RobotBase(RobotBase&&) = default;
|
||||
RobotBase& operator=(RobotBase&&) = default;
|
||||
|
||||
static std::thread::id m_threadId;
|
||||
};
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include <wpi/deprecated.h>
|
||||
|
||||
namespace wpi {
|
||||
class Sendable;
|
||||
@@ -19,47 +20,58 @@ namespace frc {
|
||||
*/
|
||||
class LiveWindow {
|
||||
public:
|
||||
LiveWindow(const LiveWindow&) = delete;
|
||||
LiveWindow& operator=(const LiveWindow&) = delete;
|
||||
|
||||
std::function<void()> enabled;
|
||||
std::function<void()> disabled;
|
||||
|
||||
/**
|
||||
* Get an instance of the LiveWindow main class.
|
||||
*
|
||||
* This is a singleton to guarantee that there is only a single instance
|
||||
* regardless of how many times GetInstance is called.
|
||||
* @deprecated Use the static methods unless guaranteeing LiveWindow is
|
||||
* instantiated
|
||||
*/
|
||||
WPI_DEPRECATED("Use static methods")
|
||||
static LiveWindow* GetInstance();
|
||||
|
||||
/**
|
||||
* Set function to be called when LiveWindow is enabled.
|
||||
*
|
||||
* @param func function (or nullptr for none)
|
||||
*/
|
||||
static void SetEnabledCallback(std::function<void()> func);
|
||||
|
||||
/**
|
||||
* Set function to be called when LiveWindow is disabled.
|
||||
*
|
||||
* @param func function (or nullptr for none)
|
||||
*/
|
||||
static void SetDisabledCallback(std::function<void()> func);
|
||||
|
||||
/**
|
||||
* Enable telemetry for a single component.
|
||||
*
|
||||
* @param sendable component
|
||||
*/
|
||||
void EnableTelemetry(wpi::Sendable* component);
|
||||
static void EnableTelemetry(wpi::Sendable* component);
|
||||
|
||||
/**
|
||||
* Disable telemetry for a single component.
|
||||
*
|
||||
* @param sendable component
|
||||
*/
|
||||
void DisableTelemetry(wpi::Sendable* component);
|
||||
static void DisableTelemetry(wpi::Sendable* component);
|
||||
|
||||
/**
|
||||
* Disable ALL telemetry.
|
||||
*/
|
||||
void DisableAllTelemetry();
|
||||
static void DisableAllTelemetry();
|
||||
|
||||
bool IsEnabled() const;
|
||||
static bool IsEnabled();
|
||||
|
||||
/**
|
||||
* Change the enabled status of LiveWindow.
|
||||
*
|
||||
* If it changes to enabled, start livewindow running otherwise stop it
|
||||
*/
|
||||
void SetEnabled(bool enabled);
|
||||
static void SetEnabled(bool enabled);
|
||||
|
||||
/**
|
||||
* Tell all the sensors to update (send) their values.
|
||||
@@ -67,18 +79,15 @@ class LiveWindow {
|
||||
* Actuators are handled through callbacks on their value changing from the
|
||||
* SmartDashboard widgets.
|
||||
*/
|
||||
void UpdateValues();
|
||||
static void UpdateValues();
|
||||
|
||||
private:
|
||||
LiveWindow();
|
||||
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> m_impl;
|
||||
LiveWindow() = default;
|
||||
|
||||
/**
|
||||
* Updates the entries, without using a mutex or lock.
|
||||
*/
|
||||
void UpdateValuesUnsafe();
|
||||
static void UpdateValuesUnsafe();
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -11,17 +11,18 @@
|
||||
|
||||
#include <networktables/NetworkTableEntry.h>
|
||||
#include <networktables/NetworkTableValue.h>
|
||||
#include <wpi/sendable/Sendable.h>
|
||||
#include <wpi/sendable/SendableHelper.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "frc/smartdashboard/ListenerExecutor.h"
|
||||
namespace wpi {
|
||||
class Sendable;
|
||||
} // namespace wpi
|
||||
|
||||
namespace frc {
|
||||
|
||||
class SmartDashboard : public wpi::Sendable,
|
||||
public wpi::SendableHelper<SmartDashboard> {
|
||||
class SmartDashboard {
|
||||
public:
|
||||
SmartDashboard() = delete;
|
||||
|
||||
static void init();
|
||||
|
||||
/**
|
||||
@@ -433,11 +434,6 @@ class SmartDashboard : public wpi::Sendable,
|
||||
* Puts all sendable data to the dashboard.
|
||||
*/
|
||||
static void UpdateValues();
|
||||
|
||||
private:
|
||||
~SmartDashboard() override = default;
|
||||
|
||||
static detail::ListenerExecutor listenerExecutor;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
Reference in New Issue
Block a user