From 4aeb8751982d90ba65f04cdbc08eb0dc19be9357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20B=C3=BCrki?= Date: Tue, 7 Jul 2020 14:12:54 +0200 Subject: [PATCH] Create basic file watcher --- src/ofApp.cpp | 61 ++++++++++++++++++++++++++++++++++++--------------- src/ofApp.h | 12 ++++++++-- 2 files changed, 53 insertions(+), 20 deletions(-) diff --git a/src/ofApp.cpp b/src/ofApp.cpp index b37e69f..b5bf671 100644 --- a/src/ofApp.cpp +++ b/src/ofApp.cpp @@ -179,6 +179,8 @@ void ofApp::setup(){ capMesh.reSize(4); ofLog(OF_LOG_NOTICE) << "Setup over"; + + lastSettingsWriteTime = boost::filesystem::last_write_time(networkSettingsPath); } //-------------------------------------------------------------- @@ -247,6 +249,8 @@ void ofApp::update(){ ofBackground(100, 100, 100); + checkSettingsUpdate(); + #ifdef BLOB if(realSense->update(ofxRealSenseTwo::PointCloud::VIDEO)) { @@ -271,6 +275,43 @@ void ofApp::update(){ networkMng.update(tracker); } +void ofApp::saveSettings() +{ + tracker.panel->saveToFile("trackings.xml"); + networkMng.panel->saveToFile("broadcast.xml"); + guitransform->saveToFile("transformation.xml"); + +#ifdef BLOB + tracker.saveMask(); + post->saveToFile("postprocessing.xml"); + device->saveToFile(realSense->getSerialNumber(-1) + ".xml"); +#endif +} + +void ofApp::loadSettings() +{ + tracker.panel->loadFromFile("trackings.xml"); + networkMng.panel->loadFromFile("broadcast.xml"); + guitransform->loadFromFile("transformation.xml"); + reloadTransformMatrix(); +#ifdef BLOB + tracker.loadMask(); + post->loadFromFile("postprocessing.xml"); + // This seems to make the app crash on Linux + //device->loadFromFile(realSense->getSerialNumber(-1) + ".xml"); +#endif +} + +void ofApp::checkSettingsUpdate() { + std::time_t newLastWriteTime = boost::filesystem::last_write_time(networkSettingsPath); + + if (newLastWriteTime > lastSettingsWriteTime) { + lastSettingsWriteTime = newLastWriteTime; + + loadSettings(); + } +} + void ofApp::draw() { ofSetColor(255, 255, 255); @@ -444,27 +485,11 @@ void ofApp::keyPressed(int key){ break; case 's': - tracker.panel->saveToFile("trackings.xml"); - networkMng.panel->saveToFile("broadcast.xml"); - guitransform->saveToFile("transformation.xml"); -#ifdef BLOB - tracker.saveMask(); - post->saveToFile("postprocessing.xml"); - device->saveToFile(realSense->getSerialNumber(-1) + ".xml"); -#endif + saveSettings(); break; case 'l': - tracker.panel->loadFromFile("trackings.xml"); - networkMng.panel->loadFromFile("broadcast.xml"); - guitransform->loadFromFile("transformation.xml"); - reloadTransformMatrix(); -#ifdef BLOB - tracker.loadMask(); - post->loadFromFile("postprocessing.xml"); - // This seems to make the app crash on Linux - //device->loadFromFile(realSense->getSerialNumber(-1) + ".xml"); -#endif + loadSettings(); break; case 'h': diff --git a/src/ofApp.h b/src/ofApp.h index b269f56..11315b1 100644 --- a/src/ofApp.h +++ b/src/ofApp.h @@ -11,6 +11,7 @@ #include "Frustum.h" #include "CaptureMeshArray.h" #include "PointCloudManager.h" +#include #include "DetectionMethod.h" #ifdef BLOB @@ -23,7 +24,7 @@ #include "SkeletonFinder.h" #endif -#include +#include #define N_CAMERAS 3 @@ -165,7 +166,14 @@ public: ofParameter pixelSizeCorrector; ofParameter blobGrain; ofParameter captureVideo; - + + void saveSettings(); + void loadSettings(); + + void checkSettingsUpdate(); + const boost::filesystem::path networkSettingsPath = ofFilePath::getAbsolutePath("broadcast.xml"); + std::time_t lastSettingsWriteTime; + ////////// // HELP // ////////// -- GitLab