2018-05-11 12:38:23 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2020-06-27 22:11:24 -07:00
|
|
|
/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
|
2018-05-11 12:38:23 -07:00
|
|
|
/* 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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2020-06-27 22:11:24 -07:00
|
|
|
#include "frc/simulation/AccelerometerSim.h" // NOLINT(build/include_order)
|
|
|
|
|
|
|
|
|
|
#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);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|