创建一个插件
概述
插件提供了创建自定义小部件、布局、数据源/类型和自定义主题的能力。 Shuffleboard 提供以下:ref:内置插件<docs/software/dashboards/shuffleboard/custom-widgets/builtin-plugins:Built-in Plugins>。
NetworkTables Plugin: 用于连接通过网络传输的数据
Base Plugin: 用于展示自定义的FRC® 在自定义小配件里的数据分类
CameraServer Plugin: 用于观察从照相服务器传来的数据
小技巧
创建自定义数据类型的示例自定义 Shuffleboard 插件和用于显示它的简单小部件可以在这里找到 <https://github.com/wpilibsuite/shuffleboard/tree/main/example-plugins/custom-data-and-widget>`__。
创建一个自定义插件
为了定义插件,插件类必须是`edu.wpi.first.shuffleboard.api.Plugin <https://github.com/wpilibsuite/shuffleboard/blob/main/api/src/main/java/edu/wpi/first/shuffleboard/api/plugin/Plugin.java>`_ 或其子类之一。插件类的示例如下。
import edu.wpi.first.shuffleboard.api.plugin.Description;
import edu.wpi.first.shuffleboard.api.plugin.Plugin;
@Description(group = "com.example", name = "MyPlugin", version = "1.2.3", summary = "An example plugin")
public class MyPlugin extends Plugin {
}
有关如何使用这些属性(包括版本号)的其他说明,请参见“此处<https://semver.org/>” _。
请注意,需要@Description注释来告知插件加载程序自定义插件类的属性。允许插件类具有默认构造函数,但不能接受任何参数。
建筑插件
The easiest way to build plugins is to utlize the example-plugins folder in the shufflebloard source tree. Clone Shuffleboard with git clone https://github.com/wpilibsuite/shuffleboard.git
, and checkout the version that corresponds to the WPILib version you have installed (e.g. 2023.2.1). git checkout v2023.2.1
Put your plugin in the example-plugins\PLUGIN-NAME
directory.
Copy the custom-data-and-widget.gradle
from example-plugins\custom-data-and-widget
and rename to match your plugin name.
Edit settings.gradle
in the shuffleboard root directory to add include "example-plugins:PLUGIN-NAME"
允许插件依赖于其他插件和库,但是,它们必须正确包含在maven或gradle构建文件中。当一个插件依赖于其他插件时,最好定义这些依赖项,以便在依赖项也未加载时不加载该插件。这可以使用@Requires注释完成,如下所示:
@Requires(group = "com.example", name = "Good Plugin", minVersion = "1.2.3")
@Requires(group = "edu.wpi.first.shuffleboard", name = "Base", minVersion = "1.0.0")
@Description(group = "com.example", name = "MyPlugin", version = "1.2.3", summary = "An example plugin")
public class MyPlugin extends Plugin {
}
minVersion指定可加载的插件的最低允许版本。例如,如果“ minVersion”为1.4.5,并且加载了版本为1.4.7的插件,则将允许这样做。但是,如果加载了版本1.2.4的插件,由于它小于``minVersion``,因此将不允许这样做。
将插件部署到沙狐球
In order to load a plugin in Shuffleboard, you will need to generate a jar file of the plugin and put it in the ~/Shuffleboard/plugins
folder. This can be done automatically
by running from the shuffleboard root gradlew :example-plugins:PLUGIN-NAME:installPlugin
部署后,Shuffleboard将缓存插件的路径,以便下次Shuffleboard加载时可以自动加载。可能需要单击插件菜单下的``清除缓存’’以删除插件或将插件重新加载到Shuffleboard中。
手动添加插件
The other way to add a plugin to Shuffleboard is to compile it to a jar file and add it from Shuffleboard. The jar file is located in example-plugins\PLUGIN-NAME\build\libs
after running gradlew build
in the shuffleboard root
Open Shuffleboard, click on the file tab in the top left, and choose Plugins from the drop down menu.
在插件窗口中,选择右下角的“加载插件”按钮,然后选择您的jar文件。