bunch of tesitng for F746NG

Dependencies:   BSP_DISCO_F746NG F746_GUI F7_Ethernet LCD_DISCO_F746NG SimpleSocket TMP36 GZ TS_DISCO_F746NG TextLCD WebSocketClient mbed-rtos mbed sMotor

Revision:
1:1f4543ea364d
Parent:
0:45610c4af223
--- a/main.cpp	Mon Dec 11 09:46:58 2017 +0000
+++ b/main.cpp	Mon Jun 18 13:16:23 2018 +0000
@@ -12,7 +12,6 @@
 #include "lwip/dhcp.h"
 #include "eth_arch.h"
 #include "lwip/tcpip.h"
-
 #include "NTPClient.h"
 #include <stdio.h>
 
@@ -20,26 +19,60 @@
 //Initialization of varius connections and interfaces
 
 
-DigitalOut myled2(D4);
+
 
 
-int number_clicks;
 LCD_DISCO_F746NG lcd;
 EthernetInterface eth;
-Thread t1, t2;
-
+Thread t1, t2, t3, t4, t5, t6;
+NTPClient ntp;
+TCPSocketConnection *sock;
 //declare external funktions and pointers
 extern void heartrate();
 extern double *h_p;
+extern double *hum;
+extern double *t_p;
+extern int *beats_per_min;
+extern void smotor();
+extern void temp();
+extern void humidity();
+//extern void sending();
 //extern void proximity();
-NTPClient ntp;
+
+char ip_add[30];
+
+
+
+/*void sending(message)
+{
+
+    sock = new TCPSocketConnection();
+    sock->connect("192.168.8.115", 12345);
+    sock->set_blocking(false, (int) (60 * 1000));
+    //std::string s = std::to_string(message);
+    //char s = '0'+message;
+    //const char *cstr = s.c_str();
+    sock->send(message, 127);
+
+}*/
 
 
 int main()
 {
-   
+    /*double humid;
+    while(1){
+        t5.start(humidity);
+        char humidity_levels[31];
+         humid = *hum;
+        sprintf(humidity_levels, "%.40f", humid);
 
-    
+        lcd.DisplayStringAt(-10, LINE(8), (uint8_t *)humidity_levels, CENTER_MODE);
+
+        wait(0.5);
+        }*/
+    //t3.start(smotor);
+
+
     //First we check if the ethernet interface was able to initialize
     if(eth.init()!=0) {
 
@@ -47,7 +80,7 @@
         sprintf(eth_init, "EthernetInterface Initialize Error");
         lcd.DisplayStringAt(0, LINE(10), (uint8_t *)eth_init, CENTER_MODE);
         while (1) {
-            wait(10);
+            wait(5);
         }
     }
     //check if the ethernet intercace is connected to a network.
@@ -60,19 +93,23 @@
         sprintf(mac_add, "Mac: %s", eth.getMACAddress());
         lcd.DisplayStringAt(0, LINE(10), (uint8_t *)mac_add, CENTER_MODE);
         while (1) {
-            wait(10);
+            wait(5);
         }
     }
-    char ip_add[30];
+    /*
+
     char net_mask[30];
     char gate_Way[30];
     char dhcp_status[30];
-
+    */
 
     /*Display the varius information achived from the dhcp server,
     It is also possible to set all these values manually,
     if no dhcp server is available
     */
+
+    //used for troupleshooting with the network configuration
+    /*
     sprintf(ip_add, "IP Address is %s", eth.getIPAddress());
     sprintf(net_mask, "NetMask is %s", eth.getNetworkMask());
     sprintf(gate_Way, "Gateway Address is %s", eth.getGateway());
@@ -81,90 +118,122 @@
     lcd.DisplayStringAt(0, LINE(4), (uint8_t *)net_mask, CENTER_MODE);
     lcd.DisplayStringAt(0, LINE(6), (uint8_t *)gate_Way, CENTER_MODE);
     lcd.DisplayStringAt(0, LINE(8), (uint8_t *)dhcp_status, CENTER_MODE);
-    wait(5);
-    lcd.Clear(LCD_COLOR_GREEN);
-    if (ntp.setTime("1.dk.pool.ntp.org") == 0)
-            {
-            char ntp_message [50];
-            time_t ctTime;
-            ctTime = time(NULL);
-            sprintf(ntp_message, "%s \r\n", ctime(&ctTime));
-            //sprintf(ntp_message, "Time is set to : %s \r\n", ctime(&ctTime));
-            lcd.DisplayStringAt(-10, LINE(8), (uint8_t *)ntp_message, CENTER_MODE);
-            
-            }
-        else
-        {
-        
-            lcd.DisplayStringAt(0, LINE(8), (uint8_t *)"Error getting time", CENTER_MODE);
-        }
-    wait(2);
+    lcd.Clear(LCD_COLOR_GREEN); */
+    
+    
+    //Connects to a danish NTP server to syncronise time and date. 
+    if (ntp.setTime("1.dk.pool.ntp.org") == 0) {
+        char ntp_message [50];
+        time_t ctTime;
+        ctTime = time(NULL);
+        sprintf(ntp_message, "%s \r\n", ctime(&ctTime));
+        //sprintf(ntp_message, "Time is set to : %s \r\n", ctime(&ctTime));
+        lcd.DisplayStringAt(-10, LINE(8), (uint8_t *)ntp_message, CENTER_MODE);
+
+    } else {
+
+        lcd.DisplayStringAt(0, LINE(8), (uint8_t *)"Error getting time", CENTER_MODE);
+    }
+    wait(1);
     lcd.Clear(LCD_COLOR_GREEN);
 
 
 
     //This is the main tasks included in the programm
-    Button b1(300, 3, 70, 40, "Hjerterytme", Font16);
-    Button b2(200, 3, 70, 40, "Lyd og temp", Font16);
-    lcd.DisplayStringAt(0, LINE(10), (uint8_t *)ip_add, CENTER_MODE);
+    sprintf(ip_add, "IP Address is %s", eth.getIPAddress());
+    //Creates a endless loop that works as the "main menu"
     while(1) {
-       
-        
-       
-        
-       
-       
-        
+        Button b1(300, 3, 70, 40, "Hjerterytme", Font16);
+        Button b2(50, 3, 70, 40, "Lyd og temp", Font16);
+        Button b3(150, 3, 70, 40, "Send", Font16);
+        lcd.DisplayStringAt(0, LINE(10), (uint8_t *)ip_add, CENTER_MODE);
 
         lcd.SetTextColor(LCD_COLOR_BLACK);
-        lcd.SetBackColor(LCD_COLOR_WHITE);
-        //print raw text to the LCD display
         lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"Commence Initial Testing...", CENTER_MODE);
-        //shows the number of times the button was clicked
-       
-        lcd.DisplayStringAt(0, LINE(6), (uint8_t *) "Christoffer Bisander", CENTER_MODE);
-       
-       
-//t1.start(testing);
-//t1.detach();
-//input_functions fact;
-        //t1.start(proximity);
-        //t1.join();
-
-
-        
 
 
-
+        lcd.DisplayStringAt(0, LINE(6), (uint8_t *) "Christoffer Bisander", CENTER_MODE);
 
-        //Check if the button was clicked and then increments the number_clicks with one
-        if (b1.Touched()) { // if user touched "MODE" panel then return
+        if (b1.Touched()) { // switch to the heart rate monitor when b1 is clicked
             lcd.SetTextColor(LCD_COLOR_RED);
-            
+            //Spawn a thread that start monitoring the heartrate
             t2.start(heartrate);
-        lcd.Clear(LCD_COLOR_GREEN);
-        char heart_rate_current[50];
-        double hr;
-        while(1) {
-            hr = *h_p;
+            lcd.Clear(LCD_COLOR_GREEN);
+            char heart_rate_current[50];
+            char beats_per_min_final[10];
+            double hr;
+            int bpm;
+            Button stop_hr(400, 3, 70, 40, "Exit", Font16);
+            //from the pointer assigned in the hearrate function we constantly read the new vallues from the heartrate monitor. 
+            while(1) {
+                hr = *h_p;
+                bpm = *beats_per_min;
+                sprintf(heart_rate_current, "hjerterytme: %.8f", hr);
+                sprintf(beats_per_min_final, "Din puls er: %i", bpm);
+                //sending(bpm);
+                lcd.DisplayStringAt(0, LINE(10), (uint8_t *)beats_per_min_final, CENTER_MODE);
+                lcd.DisplayStringAt(0, LINE(14), (uint8_t *)heart_rate_current, CENTER_MODE);
+                //if the exit button is pressed the thread is terminated and we return to the main menu.
+                if (stop_hr.Touched()) {
+                    t2.terminate();
+                    break;
+                } else {
 
-//t2.start(input_functions::heartrate, fact);
-            sprintf(heart_rate_current, "hjerterytme: %f", hr);
-            lcd.DisplayStringAt(0, LINE(14), (uint8_t *)heart_rate_current, CENTER_MODE);
-            wait(0.1);
-        }
-        t2.join();
+                }
+                wait(0.1);
+            }
 
-            
-            wait(0.5);
+            t2.join();
             lcd.Clear(LCD_COLOR_BLACK);
         }
+        //Switch to the temperature monitoring mode 
+        if(b2.Touched()) {
+            lcd.SetTextColor(LCD_COLOR_RED);
+            //Spawn a thread that constantly monitor the temperature, and calculates the avarage temperature over a 5 sec period. 
+            t2.start(temp);
+            lcd.Clear(LCD_COLOR_GREEN);
+            char current_temp[20];
+            double tp;
+            Button stop_hr(400, 3, 70, 40, "Exit", Font16);
+            while(1) {
+                tp = *t_p;
+                //If the temperatur reached a certain limit, the motor start the idea here would be that it could be used as a climate system etc. 
+                if(tp>22.0) {
+                    t4.start(smotor);
+                } else {
+                }
+
+                sprintf(current_temp, "temp: %.8f", tp);
+                lcd.DisplayStringAt(0, LINE(14), (uint8_t *)current_temp, CENTER_MODE);
+                if (stop_hr.Touched()) {
+                    t2.terminate();
+                    break;
+                } else {
+
+                }
+                wait(0.5);
+            }
+
+            t2.join();
+            lcd.Clear(LCD_COLOR_BLACK);
+        }
+        //This is primarly a proof of concept it sends af message to a TCP socket running on a different machine. 
+        if(b3.Touched()) {
+            lcd.SetTextColor(LCD_COLOR_RED);
+            sock = new TCPSocketConnection();
+            sock->connect("10.130.17.131", 12345);
+            sock->set_blocking(false, (int) (60 * 1000));
+            //std::string utf8 = u8"This is just a test";
+
+            //message = "this is a test";
+
+            sock->send("This is a test", 30);
+            delete sock;
+            //TCPSocketConnection().connect("192.168.8.115", 12345);
+            //sending();
+            //Send some data
         
-        //----------------------------------------------------------------------------//
-        //analog sound sensor.
-        //read the voltage from the sound sensor
-        
-
+        }
     }
 
 }