-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Adrian Suciu <[email protected]> # Conflicts: # plugins/CMakeLists.txt
- Loading branch information
Showing
11 changed files
with
696 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include/hockeypucktempsensorplugin/scopy-hockeypucktempsensorplugin_export.h |
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,65 @@ | ||
cmake_minimum_required(VERSION 3.9) | ||
|
||
set(SCOPY_MODULE hockeypucktempsensorplugin) | ||
|
||
message(STATUS "building plugin: " ${SCOPY_MODULE}) | ||
|
||
project(scopy-${SCOPY_MODULE} VERSION 0.1 LANGUAGES CXX) | ||
|
||
include(GenerateExportHeader) | ||
|
||
# TODO: split stylesheet/resources and add here TODO: export header files correctly | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
set(CMAKE_AUTOUIC_SEARCH_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/ui) | ||
set(CMAKE_AUTOUIC ON) | ||
set(CMAKE_AUTOMOC ON) | ||
set(CMAKE_AUTORCC ON) | ||
|
||
set(CMAKE_INCLUDE_CURRENT_DIR ON) | ||
|
||
set(CMAKE_CXX_VISIBILITY_PRESET hidden) | ||
set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE) | ||
|
||
file(GLOB SRC_LIST src/*.cpp src/*.cc) | ||
file(GLOB HEADER_LIST include/${SCOPY_MODULE}/*.h include/${SCOPY_MODULE}/*.hpp) | ||
file(GLOB UI_LIST ui/*.ui) | ||
|
||
set(ENABLE_TESTING ON) | ||
if(ENABLE_TESTING) | ||
add_subdirectory(test) | ||
endif() | ||
|
||
set(PROJECT_SOURCES ${SRC_LIST} ${HEADER_LIST} ${UI_LIST}) | ||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS REQUIRED Widgets Core) | ||
|
||
if(NOT "${SCOPY_PLUGIN_BUILD_PATH}" STREQUAL "") | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${SCOPY_PLUGIN_BUILD_PATH}) | ||
endif() | ||
|
||
qt_add_resources(PROJECT_RESOURCES res/resources.qrc) | ||
add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCES} ${PROJECT_RESOURCES}) | ||
|
||
generate_export_header( | ||
${PROJECT_NAME} EXPORT_FILE_NAME ${CMAKE_CURRENT_SOURCE_DIR}/include/${SCOPY_MODULE}/${PROJECT_NAME}_export.h | ||
) | ||
|
||
target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/${SCOPY_MODULE}) | ||
|
||
target_include_directories(${PROJECT_NAME} PUBLIC scopy-pluginbase scopy-gui) | ||
|
||
target_link_libraries( | ||
${PROJECT_NAME} | ||
PUBLIC Qt::Widgets | ||
Qt::Core | ||
scopy-pluginbase | ||
scopy-gui | ||
scopy-iioutil | ||
) | ||
|
||
set(PLUGIN_NAME ${PROJECT_NAME} PARENT_SCOPE) | ||
|
||
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${SCOPY_PLUGIN_INSTALL_DIR}) |
35 changes: 35 additions & 0 deletions
35
plugins/hpts/include/hockeypucktempsensorplugin/hockeypucktempsensorplugin.h
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,35 @@ | ||
#ifndef HOCKEYPUCKTEMPSENSORPLUGIN_H | ||
#define HOCKEYPUCKTEMPSENSORPLUGIN_H | ||
|
||
#define SCOPY_PLUGIN_NAME HockeyPuckTempSensorPlugin | ||
|
||
#include "scopy-hockeypucktempsensorplugin_export.h" | ||
#include <QObject> | ||
#include <pluginbase/plugin.h> | ||
#include <pluginbase/pluginbase.h> | ||
#include <iioutil/connectionprovider.h> | ||
|
||
namespace scopy::HockeyPuckTempSensor { | ||
class SCOPY_HOCKEYPUCKTEMPSENSORPLUGIN_EXPORT HockeyPuckTempSensorPlugin : public QObject, public PluginBase | ||
{ | ||
Q_OBJECT | ||
SCOPY_PLUGIN; | ||
|
||
public: | ||
bool compatible(QString m_param, QString category) override; | ||
bool loadPage() override; | ||
bool loadIcon() override; | ||
void loadToolList() override; | ||
void unload() override; | ||
void initMetadata() override; | ||
QString description() override; | ||
QString displayName() override; | ||
|
||
public Q_SLOTS: | ||
bool onConnect() override; | ||
bool onDisconnect() override; | ||
private: | ||
iio_context *m_ctx; | ||
}; | ||
} // namespace scopy::HockeyPuckTempSensor | ||
#endif // HOCKEYPUCKTEMPSENSORPLUGIN_H |
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,79 @@ | ||
#ifndef HOCKEYPUCKTEMPSENSOR_H | ||
#define HOCKEYPUCKTEMPSENSOR_H | ||
|
||
#include "gui/tooltemplate.h" | ||
|
||
#include "scopy-hockeypucktempsensorplugin_export.h" | ||
#include <QWidget> | ||
#include <QLabel> | ||
#include <QComboBox> | ||
#include <gui/lcdNumber.hpp> | ||
#include <gui/plotwidget.h> | ||
#include <gui/plotchannel.h> | ||
#include <gui/plotautoscaler.h> | ||
#include <deque> | ||
#include <iio.h> | ||
|
||
namespace scopy::HockeyPuckTempSensor { | ||
using namespace scopy::gui; | ||
#define HPTS_NR_SAMPLES 10 | ||
#define HPTS_COLOR StyleHelper::getColor("CH7") | ||
#define HPTS_HIST 20 | ||
|
||
// #define TESTING | ||
#ifdef TESTING | ||
#define COMPATIBLE_DESCRIPTION "PREEMPT" | ||
#define HPTS_DEV_NAME "xadc" | ||
#define HPTS_CH_NAME "temp0" | ||
#define HPTS_ATTR_NAME "raw" | ||
#define HPTS_UNIT_ATTR_NAME "" | ||
#else | ||
|
||
#define COMPATIBLE_DESCRIPTION "Hockey Puck IIO Server" | ||
#define HPTS_DEV_NAME "ad7124-4" | ||
#define HPTS_CH_NAME "voltage0-voltage0" | ||
#define HPTS_ATTR_NAME "temperature_output" | ||
#define HPTS_UNIT_ATTR_NAME "convert_output_unit" | ||
#endif | ||
|
||
class SCOPY_HOCKEYPUCKTEMPSENSORPLUGIN_EXPORT HockeyPuckTempSensor : public QWidget | ||
{ | ||
Q_OBJECT | ||
public: | ||
HockeyPuckTempSensor(iio_context *ctx, QWidget *parent = nullptr); | ||
~HockeyPuckTempSensor(); | ||
private Q_SLOTS: | ||
void refresh(); | ||
void setMin(double val); | ||
void setMax(double val); | ||
void updateUnit(QString txt); | ||
float readData(); | ||
void setCelsius(); | ||
private: | ||
void setupUiElements(); | ||
|
||
ToolTemplate *m_tool; | ||
QTimer *tim; | ||
QWidget *tempWidget; | ||
QLabel *name; | ||
PlotWidget *plot; | ||
QComboBox *unitOfMeasurement; | ||
LcdNumber *sevenseg; | ||
PlotAutoscaler *pa; | ||
PlotChannel *ch; | ||
|
||
std::deque<float> deque; | ||
std::vector<float> datax; | ||
std::vector<float> datay; | ||
bool changedUnit; | ||
QString unit; | ||
|
||
void applyStylesheet(QString lcdColor); | ||
void initData(); | ||
void setKelvin(); | ||
iio_context *m_ctx; | ||
iio_device *m_dev; | ||
iio_channel *m_ch; | ||
}; | ||
} // namespace scopy::HockeyPuckTempSensor | ||
#endif // HOCKEYPUCKTEMPSENSOR_H |
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 @@ | ||
{ | ||
"plugin": { | ||
"dir_name": "hpts", | ||
"plugin_name": "hockeypucktempsensorplugin", | ||
"class_name": "HockeyPuckTempSensorPlugin", | ||
"cmakelists": true, | ||
"namespace": "scopy::HockeyPuckTempSensor", | ||
"device_category": "iio", | ||
"tools": [ | ||
{ | ||
"id": "HPTS", | ||
"tool_name": "HockeyPuckTempSensor", | ||
"file_name": "hpts", | ||
"class_name": "HockeyPuckTempSensor", | ||
"namespace": "scopy::HockeyPuckTempSensor" | ||
} | ||
] | ||
}, | ||
"cmakelists": { | ||
"cmake_min_required": 3.9, | ||
"cxx_standard": 20, | ||
"enable_testing": "ON" | ||
}, | ||
"test": { | ||
"cmakelists": true, | ||
"cmake_min_required": 3.5, | ||
"tst_pluginloader": true | ||
}, | ||
"resources": { | ||
"resources_qrc": true | ||
}, | ||
"doc": true | ||
} |
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,2 @@ | ||
<!DOCTYPE RCC> | ||
<RCC version="1.0"/> |
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,140 @@ | ||
#include "hockeypucktempsensorplugin.h" | ||
#include <iioutil/connectionprovider.h> | ||
|
||
#include <QLoggingCategory> | ||
#include <QLabel> | ||
|
||
#include "hpts.h" | ||
|
||
Q_LOGGING_CATEGORY(CAT_HOCKEYPUCKTEMPSENSORPLUGIN, "HockeyPuckTempSensorPlugin") | ||
using namespace scopy::HockeyPuckTempSensor; | ||
|
||
bool HockeyPuckTempSensorPlugin::compatible(QString m_param, QString category) | ||
{ | ||
// This function defines the characteristics according to which the | ||
// plugin is compatible with a specific device | ||
bool ret = false; | ||
qDebug(CAT_HOCKEYPUCKTEMPSENSORPLUGIN) << "compatible"; | ||
|
||
Connection *conn = ConnectionProvider::GetInstance()->open(m_param); | ||
if(conn == nullptr) | ||
return ret; | ||
|
||
iio_context *ctx = conn->context(); | ||
QString description(iio_context_get_description(ctx)); | ||
if(description.contains(COMPATIBLE_DESCRIPTION)) { | ||
ret = true; | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
bool HockeyPuckTempSensorPlugin::loadPage() | ||
{ | ||
// Here you must write the code for the plugin info page | ||
// Below is an example for an iio device | ||
/*m_page = new QWidget(); | ||
m_page->setLayout(new QVBoxLayout(m_page)); | ||
m_page->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | ||
m_infoPage = new InfoPage(m_page); | ||
m_infoPage->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); | ||
m_page->layout()->addWidget(m_infoPage); | ||
m_page->layout()->addItem(new QSpacerItem(0, 0, QSizePolicy::Preferred, QSizePolicy::Expanding)); | ||
auto cp = ContextProvider::GetInstance(); | ||
struct iio_context *context = cp->open(m_param); | ||
ssize_t attributeCount = iio_context_get_attrs_count(context); | ||
for(int i = 0; i < attributeCount; ++i) { | ||
const char *name; | ||
const char *value; | ||
int ret = iio_context_get_attr(context, i, &name, &value); | ||
if(ret < 0) { | ||
qWarning(CAT_HOCKEYPUCKTEMPSENSORPLUGIN) << "Could not read attribute with index:" << i; | ||
continue; | ||
} | ||
m_infoPage->update(name, value); | ||
} | ||
cp->close(m_param); | ||
m_page->ensurePolished();*/ | ||
return true; | ||
} | ||
|
||
bool HockeyPuckTempSensorPlugin::loadIcon() | ||
{ | ||
// SCOPY_PLUGIN_ICON(":/gui/icons/scopy-default/icons/logo_analog.svg"); | ||
// m_icon->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); | ||
SCOPY_PLUGIN_ICON(":/gui/icons/scopy-default/icons/info.svg"); | ||
return true; | ||
} | ||
|
||
void HockeyPuckTempSensorPlugin::loadToolList() | ||
{ | ||
m_toolList.append( | ||
SCOPY_NEW_TOOLMENUENTRY("HPTS", "Temperature Sensor", ":/gui/icons/scopy-default/icons/tool_voltmeter.svg")); | ||
} | ||
|
||
void HockeyPuckTempSensorPlugin::unload() { /*delete m_infoPage;*/ } | ||
|
||
QString HockeyPuckTempSensorPlugin::description() { return "Hockey Puck temperature sensor"; } | ||
|
||
QString HockeyPuckTempSensorPlugin::displayName() | ||
{ | ||
return "Hockey Puck"; | ||
} | ||
|
||
bool HockeyPuckTempSensorPlugin::onConnect() | ||
{ | ||
// This method is called when you try to connect to a device and the plugin is | ||
// compatible to that device | ||
// In case of success the function must return true and false otherwise | ||
|
||
Connection *conn = ConnectionProvider::GetInstance()->open(m_param); | ||
if(conn == nullptr) | ||
return false; | ||
m_ctx = conn->context(); | ||
|
||
HockeyPuckTempSensor *hockeyPuckTempSensor = new HockeyPuckTempSensor(m_ctx); | ||
|
||
m_toolList[0]->setTool(hockeyPuckTempSensor); | ||
m_toolList[0]->setEnabled(true); | ||
m_toolList[0]->setRunBtnVisible(true); | ||
return true; | ||
|
||
|
||
} | ||
|
||
bool HockeyPuckTempSensorPlugin::onDisconnect() | ||
{ | ||
// This method is called when the disconnect button is pressed | ||
// It must remove all connections that were established on the connection | ||
qDebug(CAT_HOCKEYPUCKTEMPSENSORPLUGIN) << "disconnect"; | ||
if(m_ctx) | ||
ConnectionProvider::GetInstance()->close(m_param); | ||
|
||
for(auto &tool : m_toolList) { | ||
tool->setEnabled(false); | ||
tool->setRunning(false); | ||
tool->setRunBtnVisible(false); | ||
QWidget *w = tool->tool(); | ||
if(w) { | ||
tool->setTool(nullptr); | ||
delete(w); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
void HockeyPuckTempSensorPlugin::initMetadata() | ||
{ | ||
loadMetadata( | ||
R"plugin( | ||
{ | ||
"priority":110, | ||
"category":[ | ||
"iio" | ||
], | ||
"exclude":["*"] | ||
} | ||
)plugin"); | ||
} |
Oops, something went wrong.