mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
86 lines
2.5 KiB
C++
86 lines
2.5 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 "callback_helpers/TestCallbackHelpers.hpp"
|
|
|
|
#include <fmt/format.h>
|
|
|
|
namespace wpi::sim {
|
|
|
|
void BooleanCallback::HandleCallback(std::string_view name,
|
|
const HAL_Value* value) {
|
|
if (!value) {
|
|
throw std::invalid_argument("Null value");
|
|
}
|
|
if (value->type != HAL_BOOLEAN) {
|
|
throw std::invalid_argument(fmt::format("Wrong type '{}' for boolean",
|
|
static_cast<int>(value->type))
|
|
.c_str());
|
|
}
|
|
m_wasTriggered = true;
|
|
m_lastValue = value->data.v_boolean;
|
|
}
|
|
|
|
void EnumCallback::HandleCallback(std::string_view name,
|
|
const HAL_Value* value) {
|
|
if (!value) {
|
|
throw std::invalid_argument("Null value");
|
|
}
|
|
if (value->type != HAL_ENUM) {
|
|
throw std::invalid_argument(
|
|
fmt::format("Wrong type '{}' for enum", static_cast<int>(value->type))
|
|
.c_str());
|
|
}
|
|
|
|
m_wasTriggered = true;
|
|
m_lastValue = value->data.v_enum;
|
|
}
|
|
|
|
void IntCallback::HandleCallback(std::string_view name,
|
|
const HAL_Value* value) {
|
|
if (!value) {
|
|
throw std::invalid_argument("Null value");
|
|
}
|
|
if (value->type != HAL_INT) {
|
|
throw std::invalid_argument(fmt::format("Wrong type '{}' for integer",
|
|
static_cast<int>(value->type))
|
|
.c_str());
|
|
}
|
|
|
|
m_wasTriggered = true;
|
|
m_lastValue = value->data.v_int;
|
|
}
|
|
|
|
void LongCallback::HandleCallback(std::string_view name,
|
|
const HAL_Value* value) {
|
|
if (!value) {
|
|
throw std::invalid_argument("Null value");
|
|
}
|
|
if (value->type != HAL_LONG) {
|
|
throw std::invalid_argument(
|
|
fmt::format("Wrong type '{}' for long", static_cast<int>(value->type))
|
|
.c_str());
|
|
}
|
|
|
|
m_wasTriggered = true;
|
|
m_lastValue = value->data.v_long;
|
|
}
|
|
|
|
void DoubleCallback::HandleCallback(std::string_view name,
|
|
const HAL_Value* value) {
|
|
if (!value) {
|
|
throw std::invalid_argument("Null value");
|
|
}
|
|
if (value->type != HAL_DOUBLE) {
|
|
throw std::invalid_argument(
|
|
fmt::format("Wrong type '{}' for double", static_cast<int>(value->type))
|
|
.c_str());
|
|
}
|
|
|
|
m_wasTriggered = true;
|
|
m_lastValue = value->data.v_double;
|
|
}
|
|
|
|
} // namespace wpi::sim
|