From 5f3ea80088e380bb209d1b27e126ee1067b9a8c9 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sun, 29 Jan 2017 20:27:17 +0100 Subject: [PATCH] Add reboot() for Raspberry Pi on press --- src/Application/Application.cpp | 12 ++++++++++++ src/Application/Application.h | 3 +++ src/ofxPiMapper.cpp | 4 ++++ src/ofxPiMapper.h | 3 +++ 4 files changed, 22 insertions(+) diff --git a/src/Application/Application.cpp b/src/Application/Application.cpp index cb7c995..ebbcd93 100644 --- a/src/Application/Application.cpp +++ b/src/Application/Application.cpp @@ -153,6 +153,10 @@ void Application::onKeyPressed(ofKeyEventArgs & args){ case 'n': setNextPreset(); break; + + case 'x': + reboot(); + break; default: // All the other keypresses are handled by the application state onKeyPressed @@ -296,6 +300,14 @@ void Application::setNextPreset(){ setPreset(activePreset); } +void Application::reboot(){ + #ifdef TARGET_RASPBERRY_PI + system("sudo shutdown -r now"); + #else + ofLogNotice("Application::reboot()", "Supported only on Raspberry Pi"); + #endif +} + bool Application::loadXmlSettings(string fileName){ if(!ofFile::doesFileExist(fileName)){ ofLogError("Application::loadXmlSettings()") << fileName << " does not exist"; diff --git a/src/Application/Application.h b/src/Application/Application.h index 28e2652..a18d04a 100644 --- a/src/Application/Application.h +++ b/src/Application/Application.h @@ -124,6 +124,9 @@ class Application : public KeyListener { void setPreset(unsigned int i); void setNextPreset(); + // System commands + void reboot(); + protected: void setState(ApplicationBaseMode * st); diff --git a/src/ofxPiMapper.cpp b/src/ofxPiMapper.cpp index 873da5c..d847952 100644 --- a/src/ofxPiMapper.cpp +++ b/src/ofxPiMapper.cpp @@ -150,6 +150,10 @@ void ofxPiMapper::setNextSource(){ _application.setNextSource(); } +void ofxPiMapper::reboot(){ + _application.reboot(); +} + void ofxPiMapper::saveProject(){ _application.saveProject(); } diff --git a/src/ofxPiMapper.h b/src/ofxPiMapper.h index 728e444..9be9859 100644 --- a/src/ofxPiMapper.h +++ b/src/ofxPiMapper.h @@ -65,6 +65,9 @@ class ofxPiMapper { // Sources, selected surface void setNextSource(); + + // System commands + void reboot(); private: ofx::piMapper::Application _application;