Za liniju
joystick.cpp@1:95b8a1055816, 2017-02-08 (annotated)
- Committer:
- mario_meh
- Date:
- Wed Feb 08 08:29:27 2017 +0000
- Revision:
- 1:95b8a1055816
- Parent:
- 0:bd9f3303564e
Stavljen Joystick destruktor na y_enable pointer tipa Joystick. Biblioteka ima nedostatak ?to nema na?in da upravlja Linijom dok radi neki drugi prekid, npr od tipkala ili nekog od motora
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mario_meh | 1:95b8a1055816 | 1 | /** Projektiranje ugradbenih računalnih sustava |
mario_meh | 1:95b8a1055816 | 2 | * Default metoda za joystick X i Y os |
mario_meh | 1:95b8a1055816 | 3 | * @author: mario_meh |
mario_meh | 1:95b8a1055816 | 4 | * @code |
mario_meh | 1:95b8a1055816 | 5 | * #include "mbed.h" |
mario_meh | 1:95b8a1055816 | 6 | * #include "joystick.h" |
mario_meh | 1:95b8a1055816 | 7 | * |
mario_meh | 1:95b8a1055816 | 8 | * JoysKompas *data = new JoysKompas; |
mario_meh | 1:95b8a1055816 | 9 | * Joystick *joys = new Joystick(data); |
mario_meh | 1:95b8a1055816 | 10 | * joys->YEnable(); |
mario_meh | 1:95b8a1055816 | 11 | * |
mario_meh | 1:95b8a1055816 | 12 | * while(1) { |
mario_meh | 1:95b8a1055816 | 13 | * switch(data->vertikala) { |
mario_meh | 1:95b8a1055816 | 14 | * case 0: |
mario_meh | 1:95b8a1055816 | 15 | * serial.printf("Gore: %i\r\n", data->vertikala); |
mario_meh | 1:95b8a1055816 | 16 | * t_y0 = 0; |
mario_meh | 1:95b8a1055816 | 17 | * break; |
mario_meh | 1:95b8a1055816 | 18 | * case 1: |
mario_meh | 1:95b8a1055816 | 19 | * serial.printf("Dolje: %i\r\n", data->vertikala); |
mario_meh | 1:95b8a1055816 | 20 | * t_y1 = 0; |
mario_meh | 1:95b8a1055816 | 21 | * break; |
mario_meh | 1:95b8a1055816 | 22 | * } |
mario_meh | 1:95b8a1055816 | 23 | * |
mario_meh | 1:95b8a1055816 | 24 | *} |
mario_meh | 1:95b8a1055816 | 25 | * |
mario_meh | 1:95b8a1055816 | 26 | * @endcode |
mario_meh | 1:95b8a1055816 | 27 | */ |
mario_meh | 0:bd9f3303564e | 28 | #include "mbed.h" |
mario_meh | 1:95b8a1055816 | 29 | #include "joystick.h" |
mario_meh | 0:bd9f3303564e | 30 | |
mario_meh | 1:95b8a1055816 | 31 | bool yRadi = false; |
mario_meh | 1:95b8a1055816 | 32 | volatile int y_i = 0; |
mario_meh | 0:bd9f3303564e | 33 | |
mario_meh | 1:95b8a1055816 | 34 | int y_flag = false; |
mario_meh | 1:95b8a1055816 | 35 | int x_flag = false; |
mario_meh | 1:95b8a1055816 | 36 | |
mario_meh | 1:95b8a1055816 | 37 | Joystick::Joystick(JoysKompas *Data) : _x(PTB0), _y(PTB1), y_enable(Data) |
mario_meh | 1:95b8a1055816 | 38 | // PTB0 | PTB1 |
mario_meh | 1:95b8a1055816 | 39 | { |
mario_meh | 0:bd9f3303564e | 40 | } |
mario_meh | 0:bd9f3303564e | 41 | |
mario_meh | 1:95b8a1055816 | 42 | void Joystick::YEnable() { |
mario_meh | 1:95b8a1055816 | 43 | y_ticker.attach(this, &Joystick::YStatus, 1); |
mario_meh | 1:95b8a1055816 | 44 | } |
mario_meh | 1:95b8a1055816 | 45 | |
mario_meh | 1:95b8a1055816 | 46 | void Joystick::YDisable() { |
mario_meh | 1:95b8a1055816 | 47 | y_ticker.detach(); |
mario_meh | 0:bd9f3303564e | 48 | } |
mario_meh | 0:bd9f3303564e | 49 | |
mario_meh | 1:95b8a1055816 | 50 | void Joystick::YStatus() { |
mario_meh | 1:95b8a1055816 | 51 | if(_x.read() < 0.022222222) { |
mario_meh | 1:95b8a1055816 | 52 | y_enable->horizontala = Lijevo; |
mario_meh | 1:95b8a1055816 | 53 | } else if(_x.read() > 0.9888888) { |
mario_meh | 1:95b8a1055816 | 54 | y_enable->horizontala = Desno; |
mario_meh | 1:95b8a1055816 | 55 | } else if(_y.read() < 0.022222222) { |
mario_meh | 1:95b8a1055816 | 56 | y_enable->vertikala = Dolje; |
mario_meh | 0:bd9f3303564e | 57 | } else if(_y.read() > 0.9888888) { |
mario_meh | 1:95b8a1055816 | 58 | y_enable->vertikala = Gore; |
mario_meh | 0:bd9f3303564e | 59 | } |
mario_meh | 0:bd9f3303564e | 60 | } |
mario_meh | 0:bd9f3303564e | 61 | |
mario_meh | 1:95b8a1055816 | 62 | Joystick::~Joystick() { |
mario_meh | 1:95b8a1055816 | 63 | delete y_enable; |
mario_meh | 0:bd9f3303564e | 64 | } |