2019-09-23 00:24:10 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2020-01-20 22:47:36 -08:00
|
|
|
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
2019-09-23 00:24:10 -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. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "AnalogOutGui.h"
|
|
|
|
|
|
|
|
|
|
#include <hal/Ports.h>
|
|
|
|
|
#include <imgui.h>
|
|
|
|
|
#include <mockdata/AnalogOutData.h>
|
|
|
|
|
|
2020-01-20 22:47:36 -08:00
|
|
|
#include "IniSaver.h"
|
|
|
|
|
#include "IniSaverInfo.h"
|
2019-09-23 00:24:10 -07:00
|
|
|
#include "SimDeviceGui.h"
|
|
|
|
|
|
|
|
|
|
using namespace halsimgui;
|
|
|
|
|
|
2020-01-20 22:47:36 -08:00
|
|
|
static IniSaver<NameInfo> gAnalogOuts{"AnalogOut"}; // indexed by channel
|
|
|
|
|
|
2019-09-23 00:24:10 -07:00
|
|
|
static void DisplayAnalogOutputs() {
|
|
|
|
|
static const int numAnalog = HAL_GetNumAnalogOutputs();
|
|
|
|
|
static auto init = std::make_unique<bool[]>(numAnalog);
|
|
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
for (int i = 0; i < numAnalog; ++i) {
|
|
|
|
|
init[i] = HALSIM_GetAnalogOutInitialized(i);
|
|
|
|
|
if (init[i]) ++count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (count == 0) return;
|
|
|
|
|
|
|
|
|
|
if (SimDeviceGui::StartDevice("Analog Outputs")) {
|
|
|
|
|
for (int i = 0; i < numAnalog; ++i) {
|
|
|
|
|
if (!init[i]) continue;
|
2020-01-20 22:47:36 -08:00
|
|
|
|
|
|
|
|
auto& info = gAnalogOuts[i];
|
|
|
|
|
char name[128];
|
|
|
|
|
info.GetName(name, sizeof(name), "Out", i);
|
2019-09-23 00:24:10 -07:00
|
|
|
HAL_Value value = HAL_MakeDouble(HALSIM_GetAnalogOutVoltage(i));
|
|
|
|
|
SimDeviceGui::DisplayValue(name, true, &value);
|
2020-01-20 22:47:36 -08:00
|
|
|
info.PopupEditName(i);
|
2019-09-23 00:24:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SimDeviceGui::FinishDevice();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-20 22:47:36 -08:00
|
|
|
void AnalogOutGui::Initialize() {
|
|
|
|
|
gAnalogOuts.Initialize();
|
|
|
|
|
SimDeviceGui::Add(DisplayAnalogOutputs);
|
|
|
|
|
}
|