-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
…nto migrate-gauge-library
- Loading branch information
Showing
13 changed files
with
2,644 additions
and
1,949 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: ElasticLib | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
branches: ["main"] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
wpiformat-analyze: | ||
name: "Verify Formatting" | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Fetch all history and metadata | ||
run: | | ||
git checkout -b pr | ||
git branch -f main origin/main | ||
- name: Set up Python 3.8 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.8 | ||
- name: Install wpiformat | ||
run: pip3 install wpiformat==2024.50 | ||
- name: Run wpiformat | ||
run: wpiformat -f Elastic.java elasticlib.h elasticlib.cpp elasticlib.py | ||
working-directory: ./elasticlib | ||
- name: Check output | ||
run: git --no-pager diff --exit-code HEAD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) 2023-2024 Gold87 and other Elastic contributors | ||
// This software can be modified and/or shared under the terms | ||
// defined by the Elastic license: | ||
// https://github.com/Gold872/elastic-dashboard/blob/main/LICENSE | ||
|
||
#include "elasticlib.h" | ||
|
||
#include <exception> | ||
|
||
#include <fmt/core.h> | ||
#include <networktables/NetworkTableInstance.h> | ||
#include <networktables/StringTopic.h> | ||
#include <wpi/json.h> | ||
|
||
namespace elastic { | ||
|
||
void SendNotification(const Notification& notification) { | ||
static nt::StringTopic topic = | ||
nt::NetworkTableInstance::GetDefault().GetStringTopic( | ||
"/Elastic/RobotNotifications"); | ||
static nt::StringPublisher publisher = | ||
topic.Publish({.sendAll = true, .keepDuplicates = true}); | ||
|
||
try { | ||
// Convert Notification to JSON string | ||
wpi::json jsonData; | ||
|
||
if (notification.level == NotificationLevel::INFO) { | ||
jsonData["level"] = "INFO"; | ||
} else if (notification.level == NotificationLevel::WARNING) { | ||
jsonData["level"] = "WARNING"; | ||
} else if (notification.level == NotificationLevel::ERROR) { | ||
jsonData["level"] = "ERROR"; | ||
} else { | ||
jsonData["level"] = "UNKNOWN"; | ||
} | ||
|
||
jsonData["title"] = notification.title; | ||
jsonData["description"] = notification.description; | ||
jsonData["displayTime"] = notification.displayTime.value(); | ||
jsonData["width"] = notification.width; | ||
jsonData["height"] = notification.height; | ||
|
||
// Publish the JSON string | ||
publisher.Set(jsonData.dump()); | ||
} catch (const std::exception& e) { | ||
fmt::println(stderr, "Error processing JSON: {}", e.what()); | ||
} catch (...) { | ||
fmt::println(stderr, "Unknown error occurred while processing JSON."); | ||
} | ||
} | ||
|
||
} // namespace elastic |
Oops, something went wrong.