Files
allwpilib/glass/src/lib/native/cpp/hardware/AnalogOutput.cpp
Tyler Veness 17f1062885 Replace std::snprintf() with wpi::format_to_n_c_str() (#5645)
fmtlib uses consteval format string processing, which makes it more
efficient than std::snprintf().

snprintf()s in libuv, mpack, processstarter, and wpigui were left alone.
processstarter uses stdlib only, and wpigui only depends on imgui.

fmt::format_to_n() is analogous to std::format_to_n()
(https://en.cppreference.com/w/cpp/utility/format/format_to_n)

wpi::format_to_n_c_str() is a wrapper which adds the trailing NUL.
2023-09-17 20:00:16 -07:00

54 lines
1.4 KiB
C++

// 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.
#include "glass/hardware/AnalogOutput.h"
#include <wpi/StringExtras.h>
#include "glass/Context.h"
#include "glass/DataSource.h"
#include "glass/Storage.h"
#include "glass/other/DeviceTree.h"
using namespace glass;
void glass::DisplayAnalogOutputsDevice(AnalogOutputsModel* model) {
int count = 0;
model->ForEachAnalogOutput([&](auto&, int) { ++count; });
if (count == 0) {
return;
}
if (BeginDevice("Analog Outputs")) {
model->ForEachAnalogOutput([&](auto& analogOut, int i) {
auto analogOutData = analogOut.GetVoltageData();
if (!analogOutData) {
return;
}
PushID(i);
// build label
std::string& name = GetStorage().GetString("name");
char label[128];
if (!name.empty()) {
wpi::format_to_n_c_str(label, sizeof(label), "{} [{}]###name", name, i);
} else {
wpi::format_to_n_c_str(label, sizeof(label), "Out[{}]###name", i);
}
double value = analogOutData->GetValue();
DeviceDouble(label, true, &value, analogOutData);
if (PopupEditName("name", &name)) {
if (analogOutData) {
analogOutData->SetName(name);
}
}
PopID();
});
EndDevice();
}
}