Testing Linija

Dependencies:   JoystickLinija IRremote mbed Tipkalo UniServ_linijapogona umotor_linijapogona

Files at this revision

API Documentation at this revision

Comitter:
mario_meh
Date:
Sun Jan 29 23:23:10 2017 +0000
Child:
1:055ae04a8003
Child:
2:9d19b20a60a9
Commit message:
Rok za predaju s. zadatka

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
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/joystick.cpp	Sun Jan 29 23:23:10 2017 +0000
@@ -0,0 +1,49 @@
+#include "mbed.h"
+#include "tipkalo.h"
+
+Joystick::Joystick() : _x(PTB0), _y(PTB1)
+        
+                     //  PTB0  |   PTB1  
+{
+    
+    Tipkalo tjoys = new Tipkalo(PT); 
+
+}
+
+JoysKompas Joystick::read() {
+    
+    JoysKompas data;
+    
+    data.horizontala   = X();
+    data.vertikala     = Y();
+    data.jTipkalo      = t_status.radim;
+    return data;
+    
+}
+
+//------------- KOMPAS NAV Y --- -----------/
+Kompas Joystick::Y() {
+    if(_y.read() < 0.022222222) {
+        return Dolje; 
+    } else if(_y.read() > 0.9888888) {
+        return 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;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/joystick.h	Sun Jan 29 23:23:10 2017 +0000
@@ -0,0 +1,34 @@
+#ifndef JOYSTICK_H
+#define JOYSTICK_H
+
+#ifndef MBED_H
+#include "mbed.h"
+#endif 
+#ifndef GLOBAL_NAZIVI_H
+#include "global_nazivi.h"
+#endif
+
+typedef enum {
+    Gore=0,Dolje=1,Lijevo=2,Desno=3, Odabir=4, NijeOdabir = 5,
+} Kompas;
+
+struct JoysKompas {
+    double horizontala;
+    double vertikala;
+    int jTipkalo;
+};
+
+class Joystick {
+    public:
+        Joystick();
+        // Podijelio joystick na dvije f-je os X i os Y
+        Kompas X();
+        Kompas Y();
+        Kompas tipka();
+        //
+        JoysKompas read();        
+    private:
+        int size;
+        AnalogIn _x;
+        AnalogIn _y;
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Jan 29 23:23:10 2017 +0000
@@ -0,0 +1,65 @@
+#include "mbed.h"
+#include "IRremote.h"
+
+Serial serial(USBTX, USBRX); // PC
+IRrecv pinIn(PTA5);          // IR
+I2C i2c(PTC9, PTC8);         // SDA, SCL
+//Tipkalo led(PT);             // LED svjetlo
+
+const int addr = 0x0A;
+uint8_t result[4];
+
+int main() {
+    
+    //--------------------------------------------------tipke pogona
+    //Tipkalo start = new Tipkalo(PT);
+    //Tipkalo stop  = new Tipkalo(PT);
+    //Tipkalo lcd   = new Tipkalo(PT);
+    
+    //--------------------------------------------------IR argumenti
+    pinIn.enableIRIn(); // Start the receiver
+    decode_results results;
+    
+    int IR_REMOTE = 1;
+    
+    while(IR_REMOTE == 1) {
+        if (pinIn.decode(&results)) {
+            uint32_t value = results.value;
+            remote[0] = (value); 
+            remote[1] = (value) >> 8; 
+            remote[2] = (value) >> 16; 
+            remote[3] = (value) >> 24;
+            
+            i2c.write(addr,remote, 4);
+            pinIn.resume(); // Receive the next value
+        }
+        wait(0.1);
+    }
+    //-----------------------------------------------------gotov iR
+      
+    //------------------------------------------isprobavam joystick
+    // Pozovi Joystick
+    Joystick *joys = new Joystick;
+    // Aktivan ručni mod
+    int LCD_SELECTED = 1;
+    //int BUTTON        = 1;
+    
+    while(LCD_SELECTED == 1) {
+        switch(joys->Y()) {
+            case 0:
+                serial.printf("Gore: %i\r\n", joys->Y());
+                break;
+            case 1:
+                serial.printf("Dolje: %i\r\n", joys->Y());
+                break;
+            case 4:
+                serial.printf("Odabir: %i\r\n", joys->tipka());
+        }      
+    }
+    //----------------------------------------------gotov joystick
+    
+    //-----------------------------------------------------svjetlo
+    //led = 1;
+    //-------------------------------------------------end svjetlo
+    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Jan 29 23:23:10 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/ad3be0349dc5
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tipkalo.cpp	Sun Jan 29 23:23:10 2017 +0000
@@ -0,0 +1,28 @@
+#include "mbed.h"
+#include "tipkalo.h"
+
+Tipkalo::Tipkalo(PinName T) : _T(T), _countT(0) {
+    
+    t_status status = new t_status;
+    
+    Tipkalo::t_status.tiskljucen = TDOLJE;
+    _T.fall(this, &Tipkalo::tDolje);
+    
+    Timer.debounce;
+    debounce.start();
+}
+
+t_status Tipkalo::tDolje() {
+    
+    status.radim = TDOLJE;
+    _countT++;
+    status.pritisnut = _countT;
+    return TGORE;
+    
+}
+
+
+
+
+    
+    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tipkalo.h	Sun Jan 29 23:23:10 2017 +0000
@@ -0,0 +1,29 @@
+#ifndef TIPKALO_H
+#define TIPKALO_H
+
+#define t_milisec_pritisnut = 200;
+
+typedef enum {
+    TDOLJE = 1, TGORE = 0, TNEZNAM = -1
+};
+
+typedef struct t_status {
+    int radim;                // tukljucen ili tiskljucen
+    int pritisnut;
+} t_status;
+
+
+//---------------TIPKALO------------------//
+class Tipkalo {
+    public:
+        Tipkalo(PinName T);
+        t_status tDolje();
+    private:
+        InterruptIn _T;
+        int _countT;
+};
+
+//-----------TIPKALO JOYSTICK-------------//
+// To je zapravo TIPKALO
+
+#endif /* TIPKALO_H */
\ No newline at end of file