From e8f3593704f1979a66cef4c6cc5d5cf35a1003c0 Mon Sep 17 00:00:00 2001 From: Vasily Davydov Date: Wed, 21 Sep 2022 11:11:45 +0300 Subject: [PATCH] eventhandler: #6 add basic members --- EventHandler/inc/Counter.h | 26 +++++++++++++++++ EventHandler/inc/EventHandler.h | 10 +++++-- EventHandler/src/Counter.cpp | 47 +++++++++++++++++++++++++++++++ EventHandler/src/EventHandler.cpp | 9 ++++++ 4 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 EventHandler/inc/Counter.h create mode 100644 EventHandler/src/Counter.cpp diff --git a/EventHandler/inc/Counter.h b/EventHandler/inc/Counter.h new file mode 100644 index 0000000..1c6e89f --- /dev/null +++ b/EventHandler/inc/Counter.h @@ -0,0 +1,26 @@ +/* + * Counter.h + * + * Created on: Sep 1, 2022 + * Author: tylen + */ + +#ifndef COUNTER_H_ +#define COUNTER_H_ + +class Counter { + +public: + Counter(int i, int up); + void inc(); + void dec(); + int getInit(); + void setInit(int i); + ~Counter() = default; + +private: + int init; + int up_lim; + +}; +#endif /* COUNTER_H_ */ diff --git a/EventHandler/inc/EventHandler.h b/EventHandler/inc/EventHandler.h index 72d5ca9..10d9ce0 100644 --- a/EventHandler/inc/EventHandler.h +++ b/EventHandler/inc/EventHandler.h @@ -9,6 +9,7 @@ #define EVENTHANDLER_H_ #include "DigitalIoPin.h" +#include "Counter.h" typedef struct _EVENT_HANDL{ DigitalIoPin * _button_control_up; @@ -19,10 +20,15 @@ typedef struct _EVENT_HANDL{ class EventHandler { public: - EventHandler(EVENT_HANDL * btns); + EventHandler(EVENT_HANDL btns); virtual ~EventHandler(); + int getSetPresuure(); + int getSetSpeed(); private: - EVENT_HANDL = {0,0,0,0}; + EVENT_HANDL internal = {0,0,0,0}; + bool mode; + Counter * bar_pressure; + Counter * bar_speed; }; diff --git a/EventHandler/src/Counter.cpp b/EventHandler/src/Counter.cpp new file mode 100644 index 0000000..d3eadba --- /dev/null +++ b/EventHandler/src/Counter.cpp @@ -0,0 +1,47 @@ +/* + * Counter.cpp + * + * Created on: Sep 1, 2022 + * Author: tylen + */ + +#include "Counter.h" + +#include "Counter.h" + +void Counter::inc() { + if(init >= up_lim){ + init = 0; + } else{ + ++init; + } +} + +void Counter::dec() { + if(init <= 0){ + init = up_lim; + } else{ + --init; + } +} + + +int Counter::getInit(){ + return this->init; +} + +Counter::Counter(int i, int up) { + up_lim = up; + if(i > up){ + init = up; + }else if(i < 0){ + init = 0; + }else{ + init = i; + } + +} + +void Counter::setInit(int i){ + init = i; +} diff --git a/EventHandler/src/EventHandler.cpp b/EventHandler/src/EventHandler.cpp index 6eeb873..3afd39d 100644 --- a/EventHandler/src/EventHandler.cpp +++ b/EventHandler/src/EventHandler.cpp @@ -16,3 +16,12 @@ EventHandler::~EventHandler() { // TODO Auto-generated destructor stub } +int EventHandler::getSetPresuure(){ + //TODO + return 0; +} + +int EventHandler::getSetSpeed(){ + // TODO + return 0; +}