Commit 0089f54a authored by Leander Schulten's avatar Leander Schulten
Browse files

First attempt

parent 4cff1f49
......@@ -14,33 +14,41 @@ QML_IMPORT_PATH =
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
SOURCES += main.cpp \
deviceprototype.cpp \
channel.cpp \
id.cpp \
device.cpp \
programmprototype.cpp \
programm.cpp \
SOURCES += \
applicationdata.cpp \
namedobject.cpp \
dmxchannelfilter.cpp \
syncservice.cpp \
usermanagment.cpp \
channel.cpp \
channelprogrammeditor.cpp \
modelmanager.cpp \
mapview.cpp \
polygon.cpp \
mapeditor.cpp \
gridbackground.cpp \
modelvector.cpp \
controlpanel.cpp \
colorplot.cpp \
controlitem.cpp \
controlitemdata.cpp \
controlpanel.cpp \
device.cpp \
deviceprototype.cpp \
dmxchannelfilter.cpp \
dmxinterface.cpp \
driver.cpp \
errornotifier.cpp \
graph.cpp \
gridbackground.cpp \
id.cpp \
main.cpp \
mapeditor.cpp \
mapview.cpp \
modelmanager.cpp \
modelvector.cpp \
namedobject.cpp \
oscillogram.cpp \
polygon.cpp \
programm.cpp \
programmprototype.cpp \
programms/dmxconsumer.cpp \
programms/loopprogramm.cpp \
programms/property.cpp \
test/testloopprogramm.cpp \
settings.cpp \
driver.cpp \
test/DriverDummy.cpp
syncservice.cpp \
test/DriverDummy.cpp \
usermanagment.cpp
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
......@@ -81,7 +89,18 @@ HEADERS += \
errornotifier.h \
settings.h \
driver.h \
test/DriverDummy.h
test/DriverDummy.h \
colorplot.h \
graph.h \
oscillogram.h \
programms/programm.h \
programms/filter.h \
programms/types.h \
programms/property.h \
programms/loopprogramm.h \
programms/dmxconsumer.h \
programms/consumer.h \
test/testloopprogramm.h
# Default rules for deployment.
......
......@@ -31,6 +31,7 @@
#include "settings.h"
#include <QDir>
#include "driver.h"
#include "test/testloopprogramm.h"
int main(int argc, char *argv[])
{
......@@ -91,6 +92,8 @@ int main(int argc, char *argv[])
//#warning Dont use IDBase<xxxxx>::getAllIDBases() in this file. It will crash the aplication when its closing
test();
auto after = ApplicationData::loadData(file);
......@@ -135,7 +138,7 @@ int main(int argc, char *argv[])
// Treiber laden
//#define USE_DUMMY_DRIVER
#define USE_DUMMY_DRIVER
#ifndef USE_DUMMY_DRIVER
if(!Driver::loadAndStartDriver(settings.getDriverFilePath())){
ErrorNotifier::showError("Cant start driver.");
......@@ -144,7 +147,7 @@ int main(int argc, char *argv[])
#else
#include "test/DriverDummy.h"
DriverDummy driver;
/*DriverDummy driver;
driver.setSetValuesCallback([](unsigned char* values, int size, double time){
DMXChannelFilter::initValues(values,size);
Programm::fill(values,size,time);
......@@ -152,7 +155,7 @@ int main(int argc, char *argv[])
});
driver.setWaitTime(std::chrono::seconds(5));
driver.init();
driver.start();
driver.start();*/
#endif
......
......@@ -131,7 +131,7 @@ QSGNode* Polygon::updatePaintNode(QSGNode *oldNode , UpdatePaintNodeData *){
QSGGeometry *geometry = nullptr;
const auto fiveDegrees = 10/180.*M_PI;
static const auto fiveDegrees = 10/180.*M_PI;
int extraVertexCountForArcs = 0;
for(const auto a : arcs){
......
#ifndef COMSUMER_H
#define COMSUMER_H
#include "types.h"
class Consumer{
public:
virtual ValueType getInputValueType()=0;
virtual void setInputSize(unsigned int)=0;
virtual void start()=0;
virtual void show(void * data) = 0;
virtual ~Consumer() = default;
};
#endif // COMSUMER_H
#include "dmxconsumer.h"
DMXConsumer::DMXConsumer()
{
}
void DMXConsumer::setInputSize(unsigned int size){
channel.resize(size,-1);
}
void DMXConsumer::start(){}
void DMXConsumer::show(void * data){
brightness_t * b = static_cast<brightness_t*>(data);
for(auto i = channel.cbegin();i!=channel.cend();++i,++b){
if(*i>0){
//dmxData[*i] = *b;
//TODO;
}
}
}
#ifndef DMXCONSUMER_H
#define DMXCONSUMER_H
#include "consumer.h"
#include <vector>
class DMXConsumer : public Consumer
{
std::vector<short> channel;
public:
DMXConsumer();
virtual ValueType getInputValueType()override{return Brightness;}
virtual void setInputSize(unsigned int) override;
virtual void start()override;
virtual void show(void * data) override;
const std::vector<short> & getChannelAssoziation()const{return channel;}
};
#endif // DMXCONSUMER_H
#ifndef FILTER_H
#define FILTER_H
#include "types.h"
class Filter : public PropertyBase{
public:
void setInputLength(int length);
int getOutputLength();
ValueType getInputType();
ValueType getOutputType();
void filter(void * inputData, void * outputData);
};
#endif // FILTER_H
#include "loopprogramm.h"
#ifndef LOOPPROGRAMM_H
#define LOOPPROGRAMM_H
#include "programm.h"
#include <csetjmp>
#include "types.h"
namespace Modules {
template<typename BaseClass>
class LoopProgramm : public BaseClass
{
/**
* Address : 0 ... 100 101 102 103 ... 1000
* eg: ^ ^
* | + Stackbuttom
* + Stacktop
* Stacktop have smaller address then stackbuttom.
*/
unsigned char * stack = nullptr;
int stackSize = 0;
int maxStackSize = 0;
void * stackButtom;
void * stackTop;
bool first = true;
bool finished = false;
jmp_buf waitPos;
jmp_buf doStepPos;
time_diff_t currentWaitTime = 0;
time_diff_t timeToWait = 0;
static_assert (std::is_base_of<Programm,BaseClass>::value,"BaseClass must be an Subclass of Programm or the clas Programm.");
protected:
void wait(time_diff_t time){
currentWaitTime = 0;
timeToWait = time;
if(!setjmp(waitPos)){
volatile int currentStackSize;
stackTop = reinterpret_cast<void*>(reinterpret_cast<size_t>(&currentStackSize));
currentStackSize = size_t(stackButtom)-size_t(stackTop);
if(currentStackSize>maxStackSize){
delete [] stack;
stack = new unsigned char[maxStackSize];
maxStackSize = currentStackSize;
}
stackSize = currentStackSize;
std::memcpy(stack,stackTop,stackSize);
longjmp(doStepPos,1);
}else{
// restore stack
std::memcpy(reinterpret_cast<void*>((size_t(stackButtom)-stackSize)),stack,stackSize);
}
}
virtual void loopProgramm() = 0;
public:
LoopProgramm() = default;
virtual bool doStep(time_diff_t t)override{
if(finished)
return true;
currentWaitTime+=t;
if(currentWaitTime>=timeToWait){
currentWaitTime = 0;
volatile char stack_bottom;
if(!setjmp(doStepPos)){
// button for savong stack
stackButtom = (void*)(size_t)&stack_bottom;
if(first){
first = false;
loopProgramm();
finished = true;
}else{
// jump into the wait function
longjmp(waitPos,1);
}
}
}
return false;
}
};
}
#endif // LOOPPROGRAMM_H
#ifndef MODULES_PROGRAMM_H
#define MODULES_PROGRAMM_H
#include "types.h"
#include "property.h"
#include <vector>
#include <functional>
namespace Modules {
class Programm : public PropertyBase{
protected:
void show(void *values){
if(callback)
callback(values);
}
public:
Programm(const ValueType valueType):valueType(valueType){}
const ValueType valueType;
std::function<void(void*)> callback;
virtual int getProgrammLengthInMS() = 0;
virtual void setOutputLength(int length)=0;
virtual void start() = 0;
virtual bool doStep(time_diff_t) = 0;
virtual ~Programm(){}
};
template<typename value_type_t>
class ProgrammTemplate : public Programm{
protected:
value_type_t *values = nullptr;
int size;
void show(){
Programm::show(values);
}
public:
ProgrammTemplate(const ValueType valueType):Programm(valueType){}
virtual void setOutputLength(int length){
size = length;
if(values)
delete [] values;
values = new value_type_t[size];
}
virtual ~ProgrammTemplate(){delete values;}
};
class RGBProgramm:public ProgrammTemplate<rgb_t>{
public:
RGBProgramm():ProgrammTemplate(RGB){}
};
class BrightnessProgramm: public ProgrammTemplate<brightness_t>{
public:
BrightnessProgramm():ProgrammTemplate(Brightness){}
};
}
#endif // MODULES_PROGRAMM_H
#include "property.h"
#ifndef VARIABLE_H
#define VARIABLE_H
#include <string>
union ValueUnion{
float floatValue;
int intValue;
ValueUnion(float f):floatValue(f){}
ValueUnion(int i):intValue(i){}
};
template<typename ValueType>
class TypedProperty;
class Property
{
protected:
ValueUnion min;
ValueUnion max;
ValueUnion value;
private:
std::string name;
std::string description;
public:
const enum {Int, Float} Type;
Property(int min, int max, int value):min(min),max(max),value(value),Type(Int){}
Property(float min, float max, float value):min(min),max(max),value(value),Type(Float){}
void setName( const std::string _name){
name = _name;
}
std::string getName() const {
return name;
}
void setDescription( const std::string _description){
description = _description;
}
std::string getDescription() const {
return description;
}
template<typename asType>
TypedProperty<asType> * as(){
if(std::is_same<asType,int>::value){
if(Type == Int){
return static_cast<TypedProperty<asType>*>(this);
}
}else if(std::is_same<asType,float>::value){
if(Type==Float){
return static_cast<TypedProperty<asType>*>(this);
}
}
throw std::runtime_error("Bad Type.");
}
};
template<typename ValueType>
class TypedProperty : public Property{
static_assert (std::is_same<ValueType,float>::value||std::is_same<ValueType,int>::value,"Wrong Type. Con be only int or float");
public:
void setValue( const ValueType _value){
value = std::min(getMax(),std::max(_value,getMin()));
}
ValueType getValue() const {
return value;
}
void setMin( const ValueType _min){
min = _min;
}
ValueType getMin() const {
return min;
}
void setMax( const ValueType _max){
max = _max;
}
ValueType getMax() const {
return max;
}
};
#endif // VARIABLE_H
#ifndef TYPES_H
#define TYPES_H
#include "property.h"
#include <vector>
enum ValueType{Brightness, RGB};
typedef int time_diff_t;
typedef unsigned char brightness_t;
static_assert (sizeof (brightness_t)==1, "size of unsigned char is not 1");
struct rgb_t{
union{
brightness_t r;
brightness_t red;
};
union{
brightness_t g;
brightness_t green;
};
union{
brightness_t b;
brightness_t blue;
};
};
class PropertyBase{
protected:
std::vector<Property> properties;
public:
const std::vector<Property>& getProperties()const{return properties;}
};
#endif // TYPES_H
#include "testloopprogramm.h"
void test(){
TestLoopProgramm p;
p.setOutputLength(10);
p.start();
while (!p.doStep(10)) {
}
std::cout<<"finished5\n";
}
#ifndef TESTLOOPPROGRAMM_H
#define TESTLOOPPROGRAMM_H
#include "programms/loopprogramm.h"
#include "programms/programm.h"
#include <iostream>
void test();
class TestLoopProgramm : public Modules::LoopProgramm<Modules::BrightnessProgramm>
{
protected:
virtual void loopProgramm()override{
for(int i = 0; i< size;++i){
values[i] = 255;
show();
std::cout << i<<std::endl;
wait(50);
}
std::cout<<"finished\n";
}
public:
TestLoopProgramm() = default;
virtual int getProgrammLengthInMS() override{return size*50;}
virtual void start() override{}
virtual ~TestLoopProgramm()override = default ;
};
#endif // TESTLOOPPROGRAMM_H
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