Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions akit/src/main/native/include/akit/LogTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ class LogTable {
put(key, LogValue(value, ""));
}

void put(std::string key, std::string value) {
put(key, LogValue { value, "" });
}

LogValue get(std::string key) {
return data.at(prefix + key);
}
Expand All @@ -290,6 +294,13 @@ class LogTable {
return get(key).getDouble(defaultValue);
}

std::string get(std::string key, std::string defaultValue) {
auto value = data.find(prefix + key);
if (value == data.end())
return defaultValue;
return get(key).getString(defaultValue);
}

private:
LogTable(std::string prefix, int depth, std::shared_ptr<long> timestamp,
std::unordered_map<std::string, LogValue> data) : prefix { prefix }, depth {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (c) 2021-2026 Littleton Robotics
// http://github.com/Mechanical-Advantage
//
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file
// at the root directory of this project.

#pragma once
#include <frc/smartdashboard/SendableChooser.h>
#include <frc/smartdashboard/SmartDashboard.h>
#include "akit/networktables/LoggedNetworkInput.h"
#include "akit/inputs/LoggableInputs.h"
#include "akit/LogTable.h"

namespace akit {

namespace nt {

template<typename T>
class LoggedDashboardChooser: public LoggedNetworkInput,
public inputs::LoggableInputs {
public:
void toLog(LogTable table) {
table.put(key, selectedValue);
}

void fromLog(LogTable table) {
selectedValue = table.get(key, selectedValue);
}

LoggedDashboardChooser(std::string key) : key { key } {
frc::SmartDashboard::PutData(key, &sendableChooser);
periodic();
// Logger.registerDashboardInput(this);
}

void addOption(std::string key, T value) {
sendableChooser.AddOption(key, key);
options.emplace(key, value);
}

void addDefaultOption(std::string key, T value) {
sendableChooser.SetDefaultOption(key, key)
options.emplace(key, value);
}

T get() {
return options.at(selectedValue);
}

void onChange(std::function<T()> listener) {
this->listener = listener;
}

frc::SendableChooser<std::string> getSendableChooser() {
return sendableChooser;
}

void periodic() override {
// if (!Logger.hasReplaySource()) {
// selectedValue = sendableChooser.getSelected();
// }
// Logger.processInputs(prefix + "/SmartDashboard", inputs);
// if (previousValue != selectedValue) {
// if (listener != null) listener.accept(get());
// previousValue = selectedValue;
// }
}

private:
std::string key;
std::string selectedValue;
std::string previousValue;
frc::SendableChooser<std::string> sendableChooser;
std::unordered_map<std::string, T> options;
std::function<T()> listener;
};

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class LoggedNetworkBoolean: public LoggedNetworkInput,
value = table.get(removeSlash(key), defaultValue);
}

void periodic() {
void periodic() override {
/*
if (!Logger.hasReplaySource()) {
value = entry.get(defaultValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class LoggedNetworkNumber: public LoggedNetworkInput,
value = table.get(removeSlash(key), defaultValue);
}

void periodic() {
void periodic() override {
// if (!Logger.hasReplaySource()) {
// value = entry.get(defaultValue);
// }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) 2021-2026 Littleton Robotics
// http://github.com/Mechanical-Advantage
//
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file
// at the root directory of this project.

#pragma once
#include <networktables/StringTopic.h>
#include <networktables/NetworkTableInstance.h>
#include "akit/networktables/LoggedNetworkInput.h"
#include "akit/inputs/LoggableInputs.h"
#include "akit/LogTable.h"

namespace akit {

namespace nt {

class LoggedNetworkString: public LoggedNetworkInput,
public inputs::LoggableInputs {
public:
LoggedNetworkString(std::string key) : key { key }, entry {
::nt::NetworkTableInstance::GetDefault().GetStringTopic(key).GetEntry(
"") } {
// Logger.registerDashboardInput(this)
}

LoggedNetworkString(std::string key, std::string defaultValue) : LoggedNetworkString {
key } {
setDefault(defaultValue);
value = defaultValue;
}

void setDefault(std::string defaultValue) {
this->defaultValue = defaultValue;
entry.Set(entry.Get(defaultValue));
}

void set(std::string value) {
entry.Set(value);
}

std::string get() {
return value;
}

void toLog(LogTable table) override {
table.put(removeSlash(key), value);
}

void fromLog(LogTable table) override {
value = table.get(removeSlash(key), defaultValue);
}

void periodic() override {
// if (!Logger.hasReplaySource()) {
// value = entry.get(defaultValue);
// }
// Logger.processInputs(prefix, inputs);
}

private:
std::string key;
::nt::StringEntry entry;
std::string defaultValue;
std::string value;
};

}

}