[sim] Move WPILib C++ sim implementations out of line (#2598)

This makes the sim classes consistent with the rest of the WPILibC classes.
This commit is contained in:
Peter Johnson
2020-07-15 23:48:09 -07:00
committed by GitHub
parent b9feb81226
commit c2cc90b27d
49 changed files with 3068 additions and 1621 deletions

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -19,8 +19,8 @@ CommandTestBase::CommandTestBase() {
CommandScheduler CommandTestBase::GetScheduler() { return CommandScheduler(); }
void CommandTestBase::SetUp() {
HALSIM_SetDriverStationEnabled(true);
while (!HALSIM_GetDriverStationEnabled()) {
frc::sim::DriverStationSim::SetEnabled(true);
while (!frc::sim::DriverStationSim::GetEnabled()) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
}
@@ -30,8 +30,8 @@ void CommandTestBase::TearDown() {
}
void CommandTestBase::SetDSEnabled(bool enabled) {
HALSIM_SetDriverStationEnabled(enabled);
while (HALSIM_GetDriverStationEnabled() != static_cast<int>(enabled)) {
frc::sim::DriverStationSim::SetEnabled(enabled);
while (frc::sim::DriverStationSim::GetEnabled() != enabled) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
}

View File

@@ -11,7 +11,6 @@
#include <utility>
#include <frc/simulation/DriverStationSim.h>
#include <hal/simulation/MockHooks.h>
#include "ErrorConfirmer.h"
#include "frc2/command/CommandGroupBase.h"

View File

@@ -6,7 +6,7 @@
/*----------------------------------------------------------------------------*/
#include <frc/Joystick.h>
#include <hal/simulation/DriverStationData.h>
#include <frc/simulation/JoystickSim.h>
#include "CommandTestBase.h"
#include "frc2/command/CommandScheduler.h"
@@ -19,11 +19,9 @@ using namespace frc2;
class POVButtonTest : public CommandTestBase {};
TEST_F(POVButtonTest, SetPOVTest) {
HAL_JoystickPOVs povs;
povs.count = 1;
povs.povs[0] = 0;
HALSIM_SetJoystickPOVs(1, &povs);
HALSIM_NotifyDriverStationNewData();
frc::sim::JoystickSim joysim(1);
joysim.SetPOV(0);
joysim.NotifyNewData();
auto& scheduler = CommandScheduler::GetInstance();
bool finished = false;
@@ -35,9 +33,8 @@ TEST_F(POVButtonTest, SetPOVTest) {
scheduler.Run();
EXPECT_FALSE(scheduler.IsScheduled(&command));
povs.povs[0] = 90;
HALSIM_SetJoystickPOVs(1, &povs);
HALSIM_NotifyDriverStationNewData();
joysim.SetPOV(90);
joysim.NotifyNewData();
scheduler.Run();
EXPECT_TRUE(scheduler.IsScheduled(&command));