Commit e1ea4b5d authored by Geithner, Thomas's avatar Geithner, Thomas Committed by Mall, Anon
Browse files

integrated config file into desk-controller

parent 85b923e9
/*
* callback-test.cpp
*
* Created on: 21.09.2017
* Author: geith
*/
#include <iostream>
#include <functional>
using namespace std;
typedef int (callback_t) (int, int);
void
test_function(callback_t cb, int arg1, int arg2){
cout << "calling callback function with arguments "
<< arg1 << " and " << arg2 << endl;
auto rv = cb(arg1, arg2);
cout << "got result " << rv << endl;
}
class Test{
public:
int test_cb(int arg1, int arg2){
return arg1 + arg2;
}
void doCallbackTest(){
int a1 = 5;
int a2 = 7;
#if 0
std::function<int(int, int)> func([this](int arg1, int arg2) -> int{
return this->test_cb(arg1, arg1);
});
test_function(func, a1, a2);
#else
/*
test_function([this](int arg1, int arg2) -> int{
return this->test_cb(arg1, arg1);
}, a1, a2);
*/
#endif
}
protected:
};
int main(int argc, char** argv){
cout << "starting callback test" << endl;
Test t;
t.doCallbackTest();
cout << "finished callback test" << endl;
return 0;
}
File added
...@@ -36,6 +36,9 @@ public: ...@@ -36,6 +36,9 @@ public:
std::string get(const std::string& key, const std::string& default_value); std::string get(const std::string& key, const std::string& default_value);
void set(const std::string& key, const std::string& value); void set(const std::string& key, const std::string& value);
void set(const std::string& key, const int& value){
set(key, std::to_string(value));
}
protected: protected:
void readFile(); void readFile();
......
...@@ -20,8 +20,8 @@ using namespace usb2lin06; ...@@ -20,8 +20,8 @@ using namespace usb2lin06;
#define STOP_DELAY 2 #define STOP_DELAY 2
#define SMALL_STEP_TIME 220 #define SMALL_STEP_TIME 220
Controller::Controller(std::string offset_file): Controller::Controller(Config& conf):
m_offsetFile(offset_file), m_config(conf),
m_offset(0), m_offset(0),
m_targetHeight(0), m_targetHeight(0),
m_currentHeight(0), m_currentHeight(0),
...@@ -31,14 +31,10 @@ Controller::Controller(std::string offset_file): ...@@ -31,14 +31,10 @@ Controller::Controller(std::string offset_file):
return &a.get() < &b.get(); return &a.get() < &b.get();
}) })
{ {
ifstream f_in(m_offsetFile);
if(f_in.is_open()){ m_offset = stoi(m_config.get("offset", "0"));
f_in >> m_offset; m_minHeight = stoi(m_config.get("min_height", std::to_string(MIN_HEIGHT)));
f_in.close(); m_maxHeight = stoi(m_config.get("max_height", std::to_string(MAX_HEIGHT)));
}
m_minHeight = MIN_HEIGHT+m_offset;
m_maxHeight = MAX_HEIGHT+m_offset;
} }
void void
...@@ -56,13 +52,8 @@ Controller::removeFrontend(Frontend& frontend) ...@@ -56,13 +52,8 @@ Controller::removeFrontend(Frontend& frontend)
void void
Controller::setOffset(int offset) Controller::setOffset(int offset)
{ {
m_offset = offset; m_config.set("offset", offset);
ofstream f_out(m_offsetFile);
if(f_out.is_open()){
f_out << m_offset;
f_out.close();
}
m_maxHeight = m_offset + MAX_HEIGHT; m_maxHeight = m_offset + MAX_HEIGHT;
m_minHeight = m_offset + MIN_HEIGHT; m_minHeight = m_offset + MIN_HEIGHT;
} }
...@@ -134,10 +125,10 @@ DummyDesk::doDeskControl() ...@@ -134,10 +125,10 @@ DummyDesk::doDeskControl()
} }
} }
LinakDesk::LinakDesk(std::string offset_file): LinakDesk::LinakDesk(Config& conf):
m_stopDelay(STOP_DELAY), m_stopDelay(STOP_DELAY),
m_smallStepTime(SMALL_STEP_TIME), m_smallStepTime(SMALL_STEP_TIME),
Controller(offset_file), Controller(conf),
m_smallStep(false), m_smallStep(false),
m_finished(true) m_finished(true)
{ {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "desk-frontend.h" #include "desk-frontend.h"
#include "message-queue.h" #include "message-queue.h"
#include "config.h"
#include <memory> #include <memory>
#include <iostream> #include <iostream>
...@@ -26,7 +27,8 @@ namespace desk ...@@ -26,7 +27,8 @@ namespace desk
class Controller class Controller
{ {
public: public:
Controller(std::string offset_file = "desk_offset.conf"); Controller(Config& conf);
virtual ~Controller() {}
void addFrontend(Frontend &f); void addFrontend(Frontend &f);
void removeFrontend(Frontend &f); void removeFrontend(Frontend &f);
...@@ -42,7 +44,7 @@ class Controller ...@@ -42,7 +44,7 @@ class Controller
virtual int getMinHeight(void){return m_minHeight;}; virtual int getMinHeight(void){return m_minHeight;};
protected: protected:
std::string m_offsetFile; Config& m_config;
int m_offset; int m_offset;
int m_targetHeight; int m_targetHeight;
int m_currentHeight; int m_currentHeight;
...@@ -95,7 +97,7 @@ class LinakDesk : public Controller ...@@ -95,7 +97,7 @@ class LinakDesk : public Controller
Operation operationState; Operation operationState;
}; };
LinakDesk(std::string offset_file = "desk_offset.conf"); LinakDesk(Config& conf);
void notifyFrontends(int height); void notifyFrontends(int height);
virtual void doDeskControl(void); virtual void doDeskControl(void);
virtual void setHeight(int height); virtual void setHeight(int height);
......
...@@ -8,20 +8,21 @@ ...@@ -8,20 +8,21 @@
#include "desk-controller.h" #include "desk-controller.h"
#include "cmd-frontend.h" #include "cmd-frontend.h"
#include "coap-frontend.h" #include "coap-frontend.h"
#include "config.h"
#include <iostream> #include <iostream>
using namespace std; using namespace std;
using namespace desk; using namespace desk;
int main(int rgc, char** argv){ int main(int argc, char** argv){
//Controller c; Config conf("/etc/desk.conf");
//DummyDesk c;
LinakDesk c;
CmdFrontend cf(c);
CoapFrontend cof(c, 5678);
c.doDeskControl(); LinakDesk desk(conf);
CmdFrontend cf(desk);
CoapFrontend cof(desk, 5678);
desk.doDeskControl();
return 0; return 0;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment