Za liniju
Diff: joystick.cpp
- Revision:
- 2:bdd4ee83ec25
- Parent:
- 0:bd9f3303564e
--- a/joystick.cpp Sun Jan 29 23:48:12 2017 +0000 +++ b/joystick.cpp Wed Nov 22 08:51:20 2017 +0000 @@ -1,49 +1,60 @@ +/** Projektiranje ugradbenih računalnih sustava +* Default metoda za joystick X i Y os +* @author: mario_meh +* @code +* #include "mbed.h" +* #include "joystick.h" +* +* JoysKompas *data = new JoysKompas; +* Joystick *joys = new Joystick(data); +* joys->YEnable(); +* +* while(1) { +* switch(data->vertikala) { +* case 0: +* serial.printf("Gore: %i\r\n", data->vertikala); +* t_y0 = 0; +* break; +* case 1: +* serial.printf("Dolje: %i\r\n", data->vertikala); +* t_y1 = 0; +* break; +* } +* +*} +* +* @endcode +*/ #include "mbed.h" -#include "tipkalo.h" - -Joystick::Joystick() : _x(PTB0), _y(PTB1) - - // PTB0 | PTB1 -{ - - Tipkalo tjoys = new Tipkalo(PT); +#include "joystick.h" -} +bool yRadi = false; +volatile int y_i = 0; -JoysKompas Joystick::read() { - - JoysKompas data; - - data.horizontala = X(); - data.vertikala = Y(); - data.jTipkalo = t_status.radim; - return data; - +int y_flag = false; +int x_flag = false; + +Joystick::Joystick(JoysKompas *Data) : _x(PTB0), _y(PTB1), y_enable(Data) + // PTB0 | PTB1 +{ } -//------------- KOMPAS NAV Y --- -----------/ -Kompas Joystick::Y() { - if(_y.read() < 0.022222222) { - return Dolje; - } else if(_y.read() > 0.9888888) { - return Gore; - } +void Joystick::YEnable() { + y_ticker.attach(this, &Joystick::YStatus, 1); +} + +void Joystick::YDisable() { + y_ticker.detach(); } -//------------- KOMPAS NAV X ---------------/ -Kompas Joystick::X() { +void Joystick::YStatus() { if(_x.read() < 0.022222222) { - return Lijevo; + y_enable->horizontala = Lijevo; } else if(_x.read() > 0.9888888) { - return Desno; + y_enable->horizontala = Desno; + } else if(_y.read() < 0.022222222) { + y_enable->vertikala = Dolje; + } else if(_y.read() > 0.9888888) { + y_enable->vertikala = Gore; } } - -//------------- KOMPAS TIPKA ---------------/ -Kompas tipka() { - if(tjoys->tDolje()) { - return NijeOdabir; - } else { - return Odabir; - } -} \ No newline at end of file