diff --git a/StateHandler/inc/Counter.h b/StateHandler/inc/Counter.h index 8e38df4..f7ac193 100644 --- a/StateHandler/inc/Counter.h +++ b/StateHandler/inc/Counter.h @@ -12,15 +12,16 @@ class Counter { public: - Counter (int i, int up); + Counter (unsigned int i, unsigned int up); void inc (); void dec (); - int getCurrent (); - void setInit (int i); + unsigned int getCurrent (); + void setInit (unsigned int i); ~Counter () = default; private: - int init; - int up_lim; + unsigned int init; + unsigned int up_lim; + unsigned int down_lim; }; #endif /* COUNTER_H_ */ diff --git a/StateHandler/src/Counter.cpp b/StateHandler/src/Counter.cpp index ff60011..571e6c8 100644 --- a/StateHandler/src/Counter.cpp +++ b/StateHandler/src/Counter.cpp @@ -19,37 +19,38 @@ Counter::inc () void Counter::dec () { - if (init - 1 > 0) + if (init > down_lim) { --init; } } -int +unsigned int Counter::getCurrent () { return this->init; } -Counter::Counter (int i, int up) +Counter::Counter (unsigned int down, unsigned int up) { up_lim = up; - if (i > up) + down_lim = down; + if (down > up) { init = up; } - else if (i < 0) + else if (down < 0) { init = 0; } else { - init = i; + init = down; } } void -Counter::setInit (int i) +Counter::setInit (unsigned int i) { init = i; }