This repository has been archived by the owner on Nov 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #688 from robotpy/keep-putdata
Keep a reference to Sendable objects when passed to SmartDashboard::putData
- Loading branch information
Showing
5 changed files
with
100 additions
and
4 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
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,33 @@ | ||
|
||
#include "SmartDashboardData.h" | ||
|
||
namespace rpy { | ||
|
||
// | ||
// Ensures that python objects added to the SmartDashboard have at least one | ||
// reference to them | ||
// | ||
// All functions here must be called with the GIL held | ||
// | ||
|
||
static py::dict &getSmartDashboardData() { | ||
static py::dict data; | ||
return data; | ||
} | ||
|
||
void addSmartDashboardData(py::str &key, std::shared_ptr<frc::Sendable> data) { | ||
auto &sdData = getSmartDashboardData(); | ||
sdData[key] = py::cast(data); | ||
} | ||
|
||
void clearSmartDashboardData() { | ||
auto &sdData = getSmartDashboardData(); | ||
if (sdData) { | ||
sdData.clear(); | ||
// force the dictionary to be deleted otherwise it'll crash when libc++ | ||
// is unwinding static objects after interpreter destruction | ||
sdData.dec_ref(); | ||
} | ||
} | ||
|
||
} // namespace rpy |
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,16 @@ | ||
|
||
#pragma once | ||
|
||
#include <frc/smartdashboard/Sendable.h> | ||
#include <robotpy_build.h> | ||
|
||
namespace rpy { | ||
|
||
// | ||
// These functions must be called with the GIL held | ||
// | ||
|
||
void addSmartDashboardData(py::str &key, std::shared_ptr<frc::Sendable> data); | ||
void clearSmartDashboardData(); | ||
|
||
} // namespace rpy |