Maček Dorijan Miljković Dominik Napon i temperatura sa istog slave-a

Dependencies:   Display1602 mbed-rtos mbed nRF24L01P

Files at this revision

API Documentation at this revision

Comitter:
DorijanMacek
Date:
Wed Jan 27 18:18:00 2016 +0000
Parent:
0:d74d1d840f60
Child:
2:d0f85a573b89
Commit message:
radi ali ne znam zakaj

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Jan 25 16:06:10 2016 +0000
+++ b/main.cpp	Wed Jan 27 18:18:00 2016 +0000
@@ -1,7 +1,10 @@
 #include "mbed.h"
+#include "rtos.h"
 #include "nRF24L01P.h"
 #include "Display1602.h"
 
+Mutex stdio_mutex;
+
 
 I2C MSP430G(p9, p10); //sda, sc1
 nRF24L01P odasiljac(p11,p12,p13,p14,p28,p27);  //// mosi, miso, sck, csn, ce, irq
@@ -17,38 +20,72 @@
 
 void startLCD(void);
 void startNRF(int);
-void readJoystick(float &up, float &lr);
-void readTempFromMSP430G(int , int &temp);
-void readVoltFromMSP430G(int , int &volt);
+
+void printTempAndVoltOnLCD(void const *args);
+void printJoystickOnLCD(void const *args);
+
+void readJoystick(void const *args);
+void readTempFromMSP430G(void const *args);
+void readVoltFromMSP430G(void const *args);
+
+//nrf
+const int transfer_size = 4;
+char txData[transfer_size],rxData[transfer_size];
+int txDataCnt = 0;
+int rxDataCnt = 0;
+    
+//joystick
+float velocity=upDown;
+float direction =leftRight;
+    
+//MSP430g
+const int addr= 0x94;
+float temp=0.0;
+float volt=0.0;
+
+int testT=0;
+int testY=0;
+
+Semaphore semMSP430G(1);
+Semaphore semLCD(1);
+Semaphore semJoystick(1);
 
 int main() 
 {
-    //nrf
-    const int transfer_size = 4;
-    char txData[transfer_size],rxData[transfer_size];
-    int txDataCnt = 0;
-    int rxDataCnt = 0;
-    
-    //joystick
-    float velocity=upDown;
-    float direction =leftRight;
-    
-    //MSP430g
-    const int addr= 94;
-    float temp=0.0;
-    float voltage=0.0;
+
 
     
     
     startLCD();
     startNRF(transfer_size);
-    readJoystick(velocity,direction);
+    wait(1);
+    
+    //Thread t0(readJoystick, (void *)"readJoystick");
+    //Thread t1(readTempFromMSP430G, (void *)"readTemp");
+    ////Thread t2(readVoltFromMSP430G, (void *)"readVoltage");
+    //Thread t3(printTempAndVoltOnLCD, (void *)"printTemp");
+    //Thread t4(printJoystickOnLCD, (void *)"printJoytick");
+    
+   
+    
+    while(1){
+    //Thread t0(readJoystick, (void *)"readJoystick");
+    //Thread t1(readTempFromMSP430G, (void *)"readTemp");
+    //Thread t2(readVoltFromMSP430G, (void *)"readVoltage");
+    //Thread t3(printTempAndVoltOnLCD, (void *)"printTemp");
+    //Thread t4(printJoystickOnLCD, (void *)"printJoytick");
+    
+    printTempAndVoltOnLCD((void *)"printemAndVolt");    
+    printJoystickOnLCD((void *)"printjoystick");
+    readJoystick((void *)"readJoystick");
+    readTempFromMSP430G((void *)"readTemp");
     
     
-    while(1)
-    {
-        
+    //readVoltFromMSP430G((void *)"readVoltage");
+    //Thread printOnLCD(temp,volt,1);
+    //Thread t2(test_thread, (void *)"Th 2");
     }
+    
 }
 
 void startLCD()
@@ -116,43 +153,110 @@
     
     wait(0.5);
     
-} 
+}
+
+void printTempAndVoltOnLCD(void const *args)
+{
+    //while(true)
+    //{
+        semLCD.wait(1);
+        
+        int znakgore=30;
+        int znakdolje=31;
+        int znaklijevo=174;
+        int znakdesno=175;
+    
+        display.SetXY(8,0);
+        display.printf("T = %.2f ",temp);  
+        display.SetXY(8,1);
+        display.printf("V = %.2f ",volt);
+        pc.printf("printTempAndVoltOnLCD \n\r");
+        
+            
+        Thread::wait(1000);
+        semLCD.release();
+    //}  
+}
 
-void readJoystick(float &x, float &y)
+void printJoystickOnLCD(void const *args)
 {
-    x=upDown;
-    y=leftRight;
+    //while(true)
+    //{
+        semLCD.wait(1);
+        
+        display.SetXY(0,0);
+        display.printf("Up %.2f ",velocity);
+        display.SetXY(0,1);
+        display.printf("LR %.2f ",direction);
+        pc.printf("printJoystickOnLCD \n\r ");
+        
+                
+        Thread::wait(1000);
+        semLCD.release();
+    //}
+}
+        
+
+
+void readJoystick(void const *args)
+{
+    //while(true)
+    //{
+        semJoystick.wait(1);
+        
+        velocity=upDown;
+        direction =leftRight;
+        pc.printf("readJoystick \n\r ");
+        
+        Thread::wait(50);
+        semJoystick.release();
+    //}
+        
 } 
 
-void readTempFromMSP430G(int ad, float &temperature)
+void readTempFromMSP430G(void const *args)
 {
-    
-    char config_t[2]; // transmitt buffer
-    char value_read[2]; // read buffer     
-    MSP430G.write(ad, config_t, 2);
-    
-    float temp;
-    config_t[0] = 0xC0; //config slave to int temp
-    config_t[1] = 0x55; // config data byte1, BOut  
-            
-    MSP430G.read(ad, value_read, 2); //read the two-byte temp data 
-    temp = value_read[0]+value_read[1]*256;
-    temperature=temp/10.;
-        
+    //while(true)
+    //{
+        semMSP430G.wait(1);
+        char config_t[2]; // transmitt buffer
+        char value_read[2]; // read buffer
+        config_t[0] = 0xC0; //config slave to int temp
+        wait(0.1);
+        config_t[1] = 0x55; // config data byte1, BOut
+        wait(0.1);      
+        MSP430G.write(addr, config_t, 2);
+        wait(0.1);
+                               
+        MSP430G.read(addr, value_read, 2); //read the two-byte temp data 
+        temp = (value_read[0]+value_read[1]*256)/10.0;
+        pc.printf("readTempFromMSP430G \n\r ");
+                
+        Thread::wait(500);
+        semMSP430G.release();    
+    //}    
 }    
 
 
-void readVoltFromMSP430G(int ad, float voltage)
+void readVoltFromMSP430G(void const *args)
 {
-    char config_t[2]; // transmitt buffer
-    char value_read[2]; // read buffer     
-    MSP430G.write(ad, config_t, 2);
-    
-    float volt;
-    config_t[0] = 0xC1; //config slave to int temp
-    config_t[1] = 0xff; // config data byte1, BOut  
-            
-    MSP430G.read(ad, value_read, 2); //read the two-byte temp data 
-    volt = value_read[0]+value_read[1]*256;
-    voltage = 1.5 * (volt / 1023);
+    //while(true)
+    //{
+        semMSP430G.wait(1); 
+        
+        char config_t[2]; // transmitt buffer
+        char value_read[2]; // read buffer
+        config_t[0] = 0xC1; //config slave to int temp
+        wait(0.1);
+        config_t[1] = 0xff; // config data byte1, BOut  
+        wait(0.1);
+        MSP430G.write(addr, config_t, 2);
+        wait(0.2);
+                       
+        MSP430G.read(addr, value_read, 2); //read the two-byte temp data 
+        volt = (value_read[0]+value_read[1]*256)*(1.5/1024);        
+        pc.printf("readVoltFromMSP430G \n\r ");
+        Thread::wait(500);
+        semMSP430G.release(); 
+    //}
 }  
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Wed Jan 27 18:18:00 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mbed_official/code/mbed-rtos/#3d9d2b8b8f17