mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
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
52 lines
1.7 KiB
C++
52 lines
1.7 KiB
C++
/*----------------------------------------------------------------------------*/
|
|
/* 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 "AccelerometerGui.h"
|
|
|
|
#include <cstdio>
|
|
|
|
#include <hal/Value.h>
|
|
#include <hal/simulation/AccelerometerData.h>
|
|
#include <imgui.h>
|
|
|
|
#include "SimDeviceGui.h"
|
|
|
|
using namespace halsimgui;
|
|
|
|
static void DisplayAccelerometers() {
|
|
if (!HALSIM_GetAccelerometerActive(0)) return;
|
|
if (SimDeviceGui::StartDevice("BuiltInAccel")) {
|
|
HAL_Value value;
|
|
|
|
// Range
|
|
value = HAL_MakeEnum(HALSIM_GetAccelerometerRange(0));
|
|
static const char* rangeOptions[] = {"2G", "4G", "8G"};
|
|
SimDeviceGui::DisplayValue("Range", true, &value, rangeOptions, 3);
|
|
|
|
// X Accel
|
|
value = HAL_MakeDouble(HALSIM_GetAccelerometerX(0));
|
|
if (SimDeviceGui::DisplayValue("X Accel", false, &value))
|
|
HALSIM_SetAccelerometerX(0, value.data.v_double);
|
|
|
|
// Y Accel
|
|
value = HAL_MakeDouble(HALSIM_GetAccelerometerY(0));
|
|
if (SimDeviceGui::DisplayValue("Y Accel", false, &value))
|
|
HALSIM_SetAccelerometerY(0, value.data.v_double);
|
|
|
|
// Z Accel
|
|
value = HAL_MakeDouble(HALSIM_GetAccelerometerZ(0));
|
|
if (SimDeviceGui::DisplayValue("Z Accel", false, &value))
|
|
HALSIM_SetAccelerometerZ(0, value.data.v_double);
|
|
|
|
SimDeviceGui::FinishDevice();
|
|
}
|
|
}
|
|
|
|
void AccelerometerGui::Initialize() {
|
|
SimDeviceGui::Add(DisplayAccelerometers);
|
|
}
|