2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2018-05-11 12:38:23 -07:00
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
#include "frc/simulation/BuiltInAccelerometerSim.h" // NOLINT(build/include_order)
|
2020-06-27 22:11:24 -07:00
|
|
|
|
|
|
|
|
#include <hal/Accelerometer.h>
|
|
|
|
|
#include <hal/HAL.h>
|
|
|
|
|
|
2018-05-11 12:38:23 -07:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
using namespace frc::sim;
|
|
|
|
|
|
|
|
|
|
TEST(AcclerometerSimTests, TestActiveCallback) {
|
|
|
|
|
HAL_Initialize(500, 0);
|
|
|
|
|
|
2020-07-04 10:10:43 -07:00
|
|
|
BuiltInAccelerometerSim sim;
|
2018-05-11 12:38:23 -07:00
|
|
|
|
|
|
|
|
sim.ResetData();
|
|
|
|
|
|
|
|
|
|
bool wasTriggered = false;
|
|
|
|
|
bool lastValue = false;
|
|
|
|
|
|
|
|
|
|
auto cb = sim.RegisterActiveCallback(
|
2021-06-06 16:13:58 -07:00
|
|
|
[&](std::string_view name, const HAL_Value* value) {
|
2018-05-11 12:38:23 -07:00
|
|
|
wasTriggered = true;
|
|
|
|
|
lastValue = value->data.v_boolean;
|
|
|
|
|
},
|
|
|
|
|
false);
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(wasTriggered);
|
|
|
|
|
|
|
|
|
|
HAL_SetAccelerometerActive(true);
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(wasTriggered);
|
|
|
|
|
EXPECT_TRUE(lastValue);
|
|
|
|
|
}
|