Za liniju

Dependents:   Lilnija_29012017

Files at this revision

API Documentation at this revision

Comitter:
mario_meh
Date:
Wed Nov 22 08:51:20 2017 +0000
Parent:
0:bd9f3303564e
Commit message:
reserved

Changed in this revision

joystick.cpp Show annotated file Show diff for this revision Revisions of this file
joystick.h Show annotated file Show diff for this revision Revisions of this file
--- 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
--- a/joystick.h	Sun Jan 29 23:48:12 2017 +0000
+++ b/joystick.h	Wed Nov 22 08:51:20 2017 +0000
@@ -1,6 +1,6 @@
 #ifndef JOYSTICK_H
 #define JOYSTICK_H
-
+#endif
 #ifndef MBED_H
 #include "mbed.h"
 #endif 
@@ -12,23 +12,21 @@
     Gore=0,Dolje=1,Lijevo=2,Desno=3, Odabir=4, NijeOdabir = 5,
 } Kompas;
 
-struct JoysKompas {
-    double horizontala;
-    double vertikala;
-    int jTipkalo;
-};
+typedef struct {
+    Kompas horizontala;
+    Kompas vertikala;
+} JoysKompas;
 
 class Joystick {
     public:
-        Joystick();
-        // Podijelio joystick na dvije f-je os X i os Y
-        Kompas X();
-        Kompas Y();
-        Kompas tipka();
-        //
-        JoysKompas read();        
+        Joystick(JoysKompas *Data);
+        void YEnable();
+        void YDisable();
+        void YStatus();
+        void promjena();
     private:
-        int size;
         AnalogIn _x;
         AnalogIn _y;
+        Ticker y_ticker;
+        JoysKompas *y_enable;
 };
\ No newline at end of file