Za liniju

Dependents:   Lilnija_29012017

Revision:
1:95b8a1055816
Parent:
0:bd9f3303564e
--- a/joystick.cpp	Sun Jan 29 23:48:12 2017 +0000
+++ b/joystick.cpp	Wed Feb 08 08:29:27 2017 +0000
@@ -1,49 +1,64 @@
+/** 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"
+#include "joystick.h"
 
-Joystick::Joystick() : _x(PTB0), _y(PTB1)
-        
-                     //  PTB0  |   PTB1  
-{
-    
-    Tipkalo tjoys = new Tipkalo(PT); 
+bool yRadi = false;
+volatile int y_i = 0;
 
+int y_flag = false;
+int x_flag = false;
+
+Joystick::Joystick(JoysKompas *Data) : _x(PTB0), _y(PTB1), y_enable(Data)
+                                     //  PTB0  |   PTB1  
+{      
 }
 
-JoysKompas Joystick::read() {
-    
-    JoysKompas data;
-    
-    data.horizontala   = X();
-    data.vertikala     = Y();
-    data.jTipkalo      = t_status.radim;
-    return data;
-    
+void Joystick::YEnable() {
+    y_ticker.attach(this, &Joystick::YStatus, 1);
+}
+
+void Joystick::YDisable() {
+    y_ticker.detach();
 }
 
-//------------- KOMPAS NAV Y --- -----------/
-Kompas Joystick::Y() {
-    if(_y.read() < 0.022222222) {
-        return Dolje; 
+void Joystick::YStatus() {
+    if(_x.read() < 0.022222222) {
+        y_enable->horizontala = Lijevo; 
+    } else if(_x.read() > 0.9888888) {
+        y_enable->horizontala = Desno;
+    } else if(_y.read() < 0.022222222) {
+        y_enable->vertikala = Dolje;
     } else if(_y.read() > 0.9888888) {
-        return Gore;
+        y_enable->vertikala = Gore;
     }
 }
 
-//------------- KOMPAS NAV X ---------------/
-Kompas Joystick::X() {
-    if(_x.read() < 0.022222222) {
-        return Lijevo; 
-    } else if(_x.read() > 0.9888888) {
-        return Desno;
-    }
-}
-
-//------------- KOMPAS TIPKA ---------------/
-Kompas tipka() {
-    if(tjoys->tDolje()) {
-        return NijeOdabir;
-    } else {
-        return Odabir;
-    }
+Joystick::~Joystick() {
+    delete y_enable;    
 }
\ No newline at end of file