mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[hal,wpilib] Move Alert to HAL (#8646)
SystemCore implementation is not yet connected to MRCComm.
This commit is contained in:
52
wpilibc/src/main/native/cpp/driverstation/Alert.cpp
Normal file
52
wpilibc/src/main/native/cpp/driverstation/Alert.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
// 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 "wpi/driverstation/Alert.hpp"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "wpi/util/string.h"
|
||||
|
||||
using namespace wpi;
|
||||
|
||||
static HAL_AlertHandle CreateAlert(std::string_view group,
|
||||
std::string_view text, Alert::Level level) {
|
||||
WPI_String wpiGroup = wpi::util::make_string(group);
|
||||
WPI_String wpiText = wpi::util::make_string(text);
|
||||
int32_t status = 0;
|
||||
return HAL_CreateAlert(&wpiGroup, &wpiText, static_cast<int32_t>(level),
|
||||
&status);
|
||||
}
|
||||
|
||||
Alert::Alert(std::string_view text, Level type) : Alert("Alerts", text, type) {}
|
||||
|
||||
Alert::Alert(std::string_view group, std::string_view text, Level type)
|
||||
: m_handle{CreateAlert(group, text, type)} {}
|
||||
|
||||
void Alert::Set(bool active) {
|
||||
int32_t status = 0;
|
||||
HAL_SetAlertActive(m_handle, active, &status);
|
||||
}
|
||||
|
||||
bool Alert::Get() const {
|
||||
int32_t status = 0;
|
||||
return HAL_IsAlertActive(m_handle, &status);
|
||||
}
|
||||
|
||||
void Alert::SetText(std::string_view text) {
|
||||
WPI_String wpiText = wpi::util::make_string(text);
|
||||
int32_t status = 0;
|
||||
HAL_SetAlertText(m_handle, &wpiText, &status);
|
||||
}
|
||||
|
||||
std::string Alert::GetText() const {
|
||||
WPI_String wpiText;
|
||||
int32_t status = 0;
|
||||
HAL_GetAlertText(m_handle, &wpiText, &status);
|
||||
std::string rv{wpiText.str, wpiText.len};
|
||||
WPI_FreeString(&wpiText);
|
||||
return rv;
|
||||
}
|
||||
Reference in New Issue
Block a user