Tipkalo Linija
Revision 3:b9ab9a191011, committed 2017-11-22
- Comitter:
- mario_meh
- Date:
- Wed Nov 22 08:51:34 2017 +0000
- Parent:
- 1:fa666d2759a4
- Commit message:
- reserved
Changed in this revision
tipkalo.cpp | Show annotated file Show diff for this revision Revisions of this file |
tipkalo.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r fa666d2759a4 -r b9ab9a191011 tipkalo.cpp --- a/tipkalo.cpp Sun Jan 29 23:47:12 2017 +0000 +++ b/tipkalo.cpp Wed Nov 22 08:51:34 2017 +0000 @@ -1,33 +1,53 @@ -/** Klasa za dodavanje tipkala -* Status koliko puta je tipka pritisnuta +/** Projektiranje ugradbenih računalnih sustava +* Default metoda za dodavanje tipkala +* @author: mario_meh +* @code +* #include "mbed.h" +* #include "tipkalo.h" +* +* @endcode */ #include "mbed.h" #include "tipkalo.h" -Tipkalo::Tipkalo(PinName T) : _T(T), _countT(0) { - /** status je objekt koji bilježi ako je tipkalo u aktivnom stanju */ - t_status status = new t_status; - /** Na donji brid pozove funkciju tDolje(), koja vraća 1 - * i počne timer - */ - Tipkalo::status.pritisnut = TGORE; - _T.fall(this, &Tipkalo::tDolje); - /** Započni brojanje */ - Timer.debounce; - debounce.start(); +int timeAtPress; +bool pressed = false; + +Tipkalo::Tipkalo() : pbutton(PTA5), ledSec(PTE30) + +{ + t.start(); + pbutton.fall(this, &Tipkalo::blinkFall); + pbutton.rise(this, &Tipkalo::blinkRise); +} + +void Tipkalo::blinkFall() { + if(t.read_ms() > t_milisec_pritisnut) { + pressed = false; + ledSec = 0; + //ledSec != ledSec; + } t.reset(); + toggler.attach(this, &Tipkalo::togglerOff, 0.3); } -t_status Tipkalo::tDolje() { - - status.radim = TDOLJE; - _countT++; - status.pritisnut = _countT; - return TDOLJE; - +void Tipkalo::togglerOff() { + if(pressed == false) { + ledSec = 0; + //fallL = 0; + pressed = true; + t.reset(); + } } - - +void Tipkalo::blinkRise() { + if(t.read_ms() > t_milisec_pritisnut) { + pressed = true; + ledSec = 1; + //ledSec != ledSec; + } t.reset(); +} - - \ No newline at end of file +void Tipkalo::bStop() { + toggler.detach(); +} + \ No newline at end of file
diff -r fa666d2759a4 -r b9ab9a191011 tipkalo.h --- a/tipkalo.h Sun Jan 29 23:47:12 2017 +0000 +++ b/tipkalo.h Wed Nov 22 08:51:34 2017 +0000 @@ -1,29 +1,38 @@ #ifndef TIPKALO_H #define TIPKALO_H +#ifndef MBED_H +#include "mbed.h" +#endif +#ifndef GLOBAL_NAZIVI_H +#include "global_nazivi.h" +#endif -#define t_milisec_pritisnut = 200; +#define t_milisec_pritisnut 50 typedef enum { TDOLJE = 1, TGORE = 0, TNEZNAM = -1 -}; +} TTipkalo; typedef struct t_status { - int radim; // tukljucen ili tiskljucen - int pritisnut; -} t_status; + TTipkalo pritisnut; // debounce +} TStatus; //---------------TIPKALO------------------// class Tipkalo { public: - Tipkalo(PinName T); - t_status tDolje(); + Tipkalo(); + void bStart(); + void blinkFall(); + void togglerOff(); + void blinkRise(); + void bStop(); private: - InterruptIn _T; - int _countT; + DigitalOut ledSec; + InterruptIn pbutton; + Ticker toggler; + Timeout detachToggler; + Timer t; }; -//-----------TIPKALO JOYSTICK-------------// -// To je zapravo TIPKALO - #endif /* TIPKALO_H */ \ No newline at end of file