2020-12-26 14:31:24 -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.
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
#include "glass/hardware/AnalogOutput.h"
|
|
|
|
|
|
|
|
|
|
#include "glass/Context.h"
|
|
|
|
|
#include "glass/DataSource.h"
|
|
|
|
|
#include "glass/other/DeviceTree.h"
|
|
|
|
|
|
|
|
|
|
using namespace glass;
|
|
|
|
|
|
|
|
|
|
void glass::DisplayAnalogOutputsDevice(AnalogOutputsModel* model) {
|
|
|
|
|
int count = 0;
|
|
|
|
|
model->ForEachAnalogOutput([&](auto&, int) { ++count; });
|
2020-12-28 12:58:06 -08:00
|
|
|
if (count == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
|
|
|
|
|
if (BeginDevice("Analog Outputs")) {
|
|
|
|
|
model->ForEachAnalogOutput([&](auto& analogOut, int i) {
|
|
|
|
|
auto analogOutData = analogOut.GetVoltageData();
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!analogOutData) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
PushID(i);
|
|
|
|
|
|
|
|
|
|
// build label
|
|
|
|
|
std::string* name = GetStorage().GetStringRef("name");
|
|
|
|
|
char label[128];
|
|
|
|
|
if (!name->empty()) {
|
|
|
|
|
std::snprintf(label, sizeof(label), "%s [%d]###name", name->c_str(), i);
|
|
|
|
|
} else {
|
|
|
|
|
std::snprintf(label, sizeof(label), "Out[%d]###name", i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double value = analogOutData->GetValue();
|
|
|
|
|
DeviceDouble(label, true, &value, analogOutData);
|
|
|
|
|
|
|
|
|
|
if (PopupEditName("name", name)) {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (analogOutData) {
|
|
|
|
|
analogOutData->SetName(name->c_str());
|
|
|
|
|
}
|
2020-09-12 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
PopID();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
EndDevice();
|
|
|
|
|
}
|
|
|
|
|
}
|