mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[sim] Move Sim classes from HAL to wpilibc/j (#2549)
Also move some things in HAL for consistency. WAS: C++: - C APIs: #include "mockdata/AccelerometerData.h" - User side class: #include "simulation/AccelerometerSim.h" Java: - JNI APIs: hal.sim.mockdata.AccelerometerData (and a few classes in hal.sim) - User side classes: hal.sim.AccelerometerSim IS: C++: - C APIs: #include "hal/simulation/AccelerometerData.h" - C++ class: #include "frc/simulation/AccelerometerSim.h" Java: - JNI APIs: hal.simulation.AccelerometerData - User side class: wpilibj.simulation.AccelerometerSim
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018-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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "frc/simulation/AccelerometerSim.h" // NOLINT(build/include_order)
|
||||
|
||||
#include <hal/Accelerometer.h>
|
||||
#include <hal/HAL.h>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace frc::sim;
|
||||
|
||||
TEST(AcclerometerSimTests, TestActiveCallback) {
|
||||
HAL_Initialize(500, 0);
|
||||
|
||||
AccelerometerSim sim{0};
|
||||
|
||||
sim.ResetData();
|
||||
|
||||
bool wasTriggered = false;
|
||||
bool lastValue = false;
|
||||
|
||||
auto cb = sim.RegisterActiveCallback(
|
||||
[&](wpi::StringRef name, const HAL_Value* value) {
|
||||
wasTriggered = true;
|
||||
lastValue = value->data.v_boolean;
|
||||
},
|
||||
false);
|
||||
|
||||
EXPECT_FALSE(wasTriggered);
|
||||
|
||||
HAL_SetAccelerometerActive(true);
|
||||
|
||||
EXPECT_TRUE(wasTriggered);
|
||||
EXPECT_TRUE(lastValue);
|
||||
}
|
||||
36
wpilibc/src/test/native/cpp/simulation/SimDeviceSimTest.cpp
Normal file
36
wpilibc/src/test/native/cpp/simulation/SimDeviceSimTest.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include <hal/SimDevice.h>
|
||||
#include <wpi/StringRef.h>
|
||||
|
||||
#include "frc/simulation/SimDeviceSim.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace frc::sim;
|
||||
|
||||
TEST(SimDeviceSimTests, TestBasic) {
|
||||
hal::SimDevice dev{"test"};
|
||||
hal::SimBoolean devBool = dev.CreateBoolean("bool", false, false);
|
||||
|
||||
SimDeviceSim sim{"test"};
|
||||
hal::SimBoolean simBool = sim.GetBoolean("bool");
|
||||
EXPECT_FALSE(simBool.Get());
|
||||
simBool.Set(true);
|
||||
EXPECT_TRUE(devBool.Get());
|
||||
}
|
||||
|
||||
TEST(SimDeviceSimTests, TestEnumerateDevices) {
|
||||
hal::SimDevice dev{"test"};
|
||||
|
||||
bool foundit = false;
|
||||
SimDeviceSim::EnumerateDevices(
|
||||
"te", [&](const char* name, HAL_SimDeviceHandle handle) {
|
||||
if (wpi::StringRef(name) == "test") foundit = true;
|
||||
});
|
||||
EXPECT_TRUE(foundit);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018-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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include <hal/HAL.h>
|
||||
|
||||
#include "frc/simulation/AccelerometerSim.h"
|
||||
#include "frc/simulation/AnalogGyroSim.h"
|
||||
#include "frc/simulation/AnalogInSim.h"
|
||||
#include "frc/simulation/AnalogOutSim.h"
|
||||
#include "frc/simulation/AnalogTriggerSim.h"
|
||||
#include "frc/simulation/DIOSim.h"
|
||||
#include "frc/simulation/DigitalPWMSim.h"
|
||||
#include "frc/simulation/DriverStationSim.h"
|
||||
#include "frc/simulation/EncoderSim.h"
|
||||
#include "frc/simulation/PCMSim.h"
|
||||
#include "frc/simulation/PDPSim.h"
|
||||
#include "frc/simulation/PWMSim.h"
|
||||
#include "frc/simulation/RelaySim.h"
|
||||
#include "frc/simulation/RoboRioSim.h"
|
||||
#include "frc/simulation/SPIAccelerometerSim.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace frc::sim;
|
||||
|
||||
TEST(SimInitializationTests, TestAllInitialize) {
|
||||
HAL_Initialize(500, 0);
|
||||
AccelerometerSim acsim{0};
|
||||
AnalogGyroSim agsim{0};
|
||||
AnalogInSim aisim{0};
|
||||
AnalogOutSim aosim{0};
|
||||
AnalogTriggerSim atsim{0};
|
||||
DigitalPWMSim dpsim{0};
|
||||
DIOSim diosim{0};
|
||||
DriverStationSim dssim;
|
||||
(void)dssim;
|
||||
EncoderSim esim{0};
|
||||
PCMSim pcmsim{0};
|
||||
PDPSim pdpsim{0};
|
||||
PWMSim pwmsim{0};
|
||||
RelaySim rsim{0};
|
||||
RoboRioSim rrsim{0};
|
||||
SPIAccelerometerSim sasim{0};
|
||||
}
|
||||
Reference in New Issue
Block a user