mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[glass] Add glass: an application for display of robot data
This reuses many pieces of the current simulation GUI. The common pieces have been refactored into the libglass library. The libglass library is designed to be usable for other standalone data visualization applications (e.g. viewing data logs). The name "glass" comes from "glass cockpit", as the application features several multi-function displays that can be adjusted to display robot information as needed.
This commit is contained in:
121
simulation/halsim_gui/src/main/native/include/HALDataSource.h
Normal file
121
simulation/halsim_gui/src/main/native/include/HALDataSource.h
Normal file
@@ -0,0 +1,121 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <glass/DataSource.h>
|
||||
|
||||
#define HALSIMGUI_DATASOURCE(cbname, id, TYPE, vtype) \
|
||||
class cbname##Source : public ::glass::DataSource { \
|
||||
public: \
|
||||
cbname##Source() \
|
||||
: DataSource(id), \
|
||||
m_callback{ \
|
||||
HALSIM_Register##cbname##Callback(CallbackFunc, this, true)} { \
|
||||
SetDigital(HAL_##TYPE == HAL_BOOLEAN); \
|
||||
} \
|
||||
\
|
||||
~cbname##Source() { \
|
||||
if (m_callback != 0) HALSIM_Cancel##cbname##Callback(m_callback); \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
static void CallbackFunc(const char*, void* param, \
|
||||
const HAL_Value* value) { \
|
||||
if (value->type == HAL_##TYPE) \
|
||||
static_cast<cbname##Source*>(param)->SetValue(value->data.v_##vtype); \
|
||||
} \
|
||||
\
|
||||
int32_t m_callback; \
|
||||
}
|
||||
|
||||
#define HALSIMGUI_DATASOURCE_BOOLEAN(cbname, id) \
|
||||
HALSIMGUI_DATASOURCE(cbname, id, BOOLEAN, boolean)
|
||||
|
||||
#define HALSIMGUI_DATASOURCE_DOUBLE(cbname, id) \
|
||||
HALSIMGUI_DATASOURCE(cbname, id, DOUBLE, double)
|
||||
|
||||
#define HALSIMGUI_DATASOURCE_INT(cbname, id) \
|
||||
HALSIMGUI_DATASOURCE(cbname, id, INT, int)
|
||||
|
||||
#define HALSIMGUI_DATASOURCE_INDEXED(cbname, id, TYPE, vtype) \
|
||||
class cbname##Source : public ::glass::DataSource { \
|
||||
public: \
|
||||
explicit cbname##Source(int32_t index, int channel = -1) \
|
||||
: DataSource(id, channel < 0 ? index : channel), \
|
||||
m_index{index}, \
|
||||
m_channel{channel < 0 ? index : channel}, \
|
||||
m_callback{HALSIM_Register##cbname##Callback(index, CallbackFunc, \
|
||||
this, true)} { \
|
||||
SetDigital(HAL_##TYPE == HAL_BOOLEAN); \
|
||||
} \
|
||||
\
|
||||
~cbname##Source() { \
|
||||
if (m_callback != 0) \
|
||||
HALSIM_Cancel##cbname##Callback(m_index, m_callback); \
|
||||
} \
|
||||
\
|
||||
int32_t GetIndex() const { return m_index; } \
|
||||
\
|
||||
int GetChannel() const { return m_channel; } \
|
||||
\
|
||||
private: \
|
||||
static void CallbackFunc(const char*, void* param, \
|
||||
const HAL_Value* value) { \
|
||||
if (value->type == HAL_##TYPE) \
|
||||
static_cast<cbname##Source*>(param)->SetValue(value->data.v_##vtype); \
|
||||
} \
|
||||
\
|
||||
int32_t m_index; \
|
||||
int m_channel; \
|
||||
int32_t m_callback; \
|
||||
}
|
||||
|
||||
#define HALSIMGUI_DATASOURCE_BOOLEAN_INDEXED(cbname, id) \
|
||||
HALSIMGUI_DATASOURCE_INDEXED(cbname, id, BOOLEAN, boolean)
|
||||
|
||||
#define HALSIMGUI_DATASOURCE_DOUBLE_INDEXED(cbname, id) \
|
||||
HALSIMGUI_DATASOURCE_INDEXED(cbname, id, DOUBLE, double)
|
||||
|
||||
#define HALSIMGUI_DATASOURCE_INDEXED2(cbname, id, TYPE, vtype) \
|
||||
class cbname##Source : public ::glass::DataSource { \
|
||||
public: \
|
||||
explicit cbname##Source(int32_t index, int32_t channel) \
|
||||
: DataSource(id, index, channel), \
|
||||
m_index{index}, \
|
||||
m_channel{channel}, \
|
||||
m_callback{HALSIM_Register##cbname##Callback( \
|
||||
index, channel, CallbackFunc, this, true)} { \
|
||||
SetDigital(HAL_##TYPE == HAL_BOOLEAN); \
|
||||
} \
|
||||
\
|
||||
~cbname##Source() { \
|
||||
if (m_callback != 0) \
|
||||
HALSIM_Cancel##cbname##Callback(m_index, m_channel, m_callback); \
|
||||
} \
|
||||
\
|
||||
int32_t GetIndex() const { return m_index; } \
|
||||
\
|
||||
int32_t GetChannel() const { return m_channel; } \
|
||||
\
|
||||
private: \
|
||||
static void CallbackFunc(const char*, void* param, \
|
||||
const HAL_Value* value) { \
|
||||
if (value->type == HAL_##TYPE) \
|
||||
static_cast<cbname##Source*>(param)->SetValue(value->data.v_##vtype); \
|
||||
} \
|
||||
\
|
||||
int32_t m_index; \
|
||||
int32_t m_channel; \
|
||||
int32_t m_callback; \
|
||||
}
|
||||
|
||||
#define HALSIMGUI_DATASOURCE_BOOLEAN_INDEXED2(cbname, id) \
|
||||
HALSIMGUI_DATASOURCE_INDEXED2(cbname, id, BOOLEAN, boolean)
|
||||
|
||||
#define HALSIMGUI_DATASOURCE_DOUBLE_INDEXED2(cbname, id) \
|
||||
HALSIMGUI_DATASOURCE_INDEXED2(cbname, id, DOUBLE, double)
|
||||
Reference in New Issue
Block a user