PRO2_Team 1_collected code with ticker_not working yet

Dependencies:   SHTx mbed

Fork of PRO2_samlet_kode by Software hold - Team 1 - PRO2 2017

Files at this revision

API Documentation at this revision

Comitter:
OlgaHoeyer
Date:
Thu May 18 22:34:57 2017 +0000
Parent:
0:21e9cc38dd31
Child:
2:0864be57f81e
Commit message:
half finished modular design

Changed in this revision

compare.cpp Show annotated file Show diff for this revision Revisions of this file
compare.h Show annotated file Show diff for this revision Revisions of this file
data_out.cpp Show annotated file Show diff for this revision Revisions of this file
data_out.h Show annotated file Show diff for this revision Revisions of this file
get_humid.cpp Show annotated file Show diff for this revision Revisions of this file
get_humid.h Show annotated file Show diff for this revision Revisions of this file
get_temp.cpp Show annotated file Show diff for this revision Revisions of this file
get_temp.h Show annotated file Show diff for this revision Revisions of this file
logging.cpp Show annotated file Show diff for this revision Revisions of this file
logging.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compare.cpp	Thu May 18 22:34:57 2017 +0000
@@ -0,0 +1,82 @@
+//Author : Olga Hoeyer
+//Date : 18 May 2017
+//Version : 2.0
+//Changes: Structure changed to modular, to ease future use of the funktion.
+//Copyright : Open for everyone
+//
+// Description : Analysis part for EDE PRO2 Team 1 project. 
+//Program takes temperature and humidity as arguments (read from sensors), 
+//together with lower and higher limit on temperature and evaluate air quality. 
+//Output is status (int, from 1 to 5).
+
+#include "mbed.h"
+
+int Compare_values(float hum, float temp, 
+                    int temperature_low, int temperature_high)
+{
+//local variables
+int status, humidity, temperature;
+
+//__________________________________
+// Definition of limits
+//__________________________________
+
+//Humidity limits.
+    const int HUMIDITY_LOW = 20;
+    const int HUMIDITY_HIGH= 60;
+
+//Extra limits where LED will start blinking in red:
+//13 < Temp < 30; 10%< hum < 80%
+    const int HUMIDITY_EXTRA_LOW = 10;
+    const int HUMIDITY_EXTRA_HIGH= 80;
+    const int TEMPERATURE_EXTRA_LOW = 13;
+    const int TEMPERATURE_EXTRA_HIGH= 30;
+
+//Definition of output values
+    const int GOOD_LEVEL = 1;               //green
+    const int ACCEPT_LEVEL = 2;             //orange
+    const int CRITICAL_LEVEL = 3;           //red
+    const int EXTRA_CRITICAL_LEVEL = 4;     //red strobe
+    const int USER_NEEDED = 5;              //blue strobe
+
+
+//__________________________________
+// main body: comparison
+//__________________________________
+
+    humidity=(int)hum;                          //convertation of float to int.
+    temperature=(int)temp;
+
+// check if there is a connection to the sensor
+// (if null=no data=there is no connection
+
+    if ((temperature == 0)  || (humidity == 0))
+        status= USER_NEEDED;
+
+    //comparing in nested loop.
+    else if ((temperature < TEMPERATURE_EXTRA_LOW)  ||
+             (temperature > TEMPERATURE_EXTRA_HIGH))
+
+        status= EXTRA_CRITICAL_LEVEL;
+
+    else if ((humidity < HUMIDITY_EXTRA_LOW)  ||
+             (humidity > HUMIDITY_EXTRA_HIGH))
+
+        status= EXTRA_CRITICAL_LEVEL;
+
+    else if ((temperature < temperature_low) ||
+             (temperature > temperature_high))
+
+        status= CRITICAL_LEVEL;
+
+    else if ((temperature < temperature_high) &&
+             (temperature > temperature_low) &&
+             (humidity < HUMIDITY_HIGH) &&
+             (humidity > HUMIDITY_LOW))
+
+        status= GOOD_LEVEL;
+
+    else status= ACCEPT_LEVEL;
+
+    return(status);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compare.h	Thu May 18 22:34:57 2017 +0000
@@ -0,0 +1,16 @@
+//Author : Olga Hoeyer
+//Date : 18 May 2017
+//Version : 2.0
+//Changes: Structure changed to modular, to ease future use of the funktion.
+//Copyright : Open for everyone
+//
+// Description : Analysis part for EDE PRO2 Team 1 project. 
+//Program takes temperature and humidity as arguments (read from sensors), 
+//together with lower and higher limit on temperature and evaluate air quality. 
+//Output is status (int, from 1 to 5).
+//
+// Usage: Compare_values(float hum, float temp, 
+//                       int temperature_low, int temperature_high)
+
+int Compare_values(float hum, float temp, 
+                    int temperature_low, int temperature_high);
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data_out.cpp	Thu May 18 22:34:57 2017 +0000
@@ -0,0 +1,72 @@
+/*
+================================================================================
+==              ==                                                            ==
+== Source File: ==  main.cpp                                                  ==
+== Author:      ==  Poul Erik Tjørnfelt                                       ==
+== Date:        ==  07/05-2017                                                ==
+== Copyright:   ==  Open to all                                               ==
+== Version:     ==  0.6 - Creation of file.                                   ==
+==              ==  0.7 - Added a 5th choice for colour. Red_Blink.           ==
+==              ==                                                            ==
+== Description: ==  A program (for a school project) that needs to collect    ==
+==              ==  data from sensors, and show an output to 3 seven-segmented==
+==              ==  displays and to a RGB-LED.                                ==
+==              ==                                                            ==
+================================================================================
+*/
+
+#include "mbed.h"
+#include "rgb_led.h"
+#include "7_segment_control.h"
+#include "data_out.h"
+
+void rgb_outp(int status)
+{
+     RGB_LED lamp(PC_8,PC_6,PB_9);   // Creates an object out of the class RGB_LED.
+    // Connect pins on the Nucleo, to the pins the
+    // class.
+// Following is a object of the class segment_7. It is the actual analogy
+// to our 7 segmented displays. There needs to go 11 pins into the parenteses.
+//segment_7 seg_num(11 pins);
+
+     enum colour {   // Enumeration is used only for making the program more
+        // easily readable.
+        green,      // Is alike an int, starts at green = 1,
+        orange,     // orange = 2 etc.
+        red,
+        red_blink,
+        blue
+    };
+
+    colour RGB_out = static_cast<colour>(status);
+    // Taking the value from the sensors and change them the enum type.
+    // Enum is somewhat akin to an int already, but RGB_out != status..
+
+    switch(RGB_out) {
+        case green:
+            lamp.set(0.0f, 1.0f, 0.0f);
+            lamp.flash(1.0f, 1.0f);         // On constantly.
+            break;
+        case orange:
+            lamp.set(1.0f, 0.6f, 0.0f);
+            lamp.flash(1.0f, 1.0f);         // On constantly.
+            break;
+        case red:
+            lamp.set(1.0f, 0.0f, 0.0f);
+            lamp.flash(1.0f, 1.0f);         // On constantly.
+            break;
+        case red_blink:
+            lamp.set(1.0f, 0.0f, 0.0f);
+            lamp.flash(2.0f, 0.5f);         // On for 50% of every 2 seconds.
+            break;
+        case blue:
+            lamp.set(0.0f, 0.0f, 1.0f);
+            lamp.flash(2.0f, 0.5f);         // On for 50% of every 2 seconds.
+            break;
+        default:   // Error has occured, blue. Could just have defaulted instead
+            lamp.set(0.0f, 0.0f, 1.0f);     // of case blue, however I think
+            lamp.flash(2.0f, 0.5f);         // this is more understandable.
+    }
+
+    return;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/data_out.h	Thu May 18 22:34:57 2017 +0000
@@ -0,0 +1,2 @@
+
+void rgb_outp(int status);
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/get_humid.cpp	Thu May 18 22:34:57 2017 +0000
@@ -0,0 +1,38 @@
+//Author : Olga Hoeyer
+//Date : 18 May 2017
+//Version : 2.0
+//Changes: Structure changed to modular, to ease future use of the funktion.
+//Copyright : Open for everyone
+//
+// Description : Function will get a humidity value from the SHF-15 sensor
+// Output is relative humidity (float).
+
+
+#include "mbed.h"
+#include "SHTx/sht15.hpp"
+
+DigitalOut busy(LED1);
+//ports on the Nucleo: PB_8, PB_9
+SHTx::SHT15 sensor(PB_8, PB_9);
+
+float GetHumid()
+{
+//VARIABLES:
+    float humidity;          //this will be data read from sensor
+
+// Speed things up a bit.
+    sensor.setOTPReload(false);
+    sensor.setResolution(true);
+
+    busy = true;
+    sensor.update();
+    busy = false;
+
+    // Temperature in celcius
+    sensor.setScale(false);
+    humidity=sensor.getHumidity();        //don't know if it works
+
+    wait(5);
+    return (humidity);
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/get_humid.h	Thu May 18 22:34:57 2017 +0000
@@ -0,0 +1,12 @@
+//Author : Olga Hoeyer
+//Date : 18 May 2017
+//Version : 2.0
+//Changes: Structure changed to modular, to ease future use of the funktion.
+//Copyright : Open for everyone
+//
+// Description : Function will get a humidity value from the SHF-15 sensor
+// Output is relative humidity (float). 
+//
+// Usage: GetHumid()
+
+float GetHumid();
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/get_temp.cpp	Thu May 18 22:34:57 2017 +0000
@@ -0,0 +1,38 @@
+//Author : Olga Hoeyer
+//Date : 18 May 2017
+//Version : 2.0
+//Changes: Structure changed to modular, to ease future use of the funktion.
+//Copyright : Open for everyone
+//
+//Description : Function will get a temperature value from the SHF-15 sensor
+//Output is value in Celsius (float).
+
+
+#include "mbed.h"
+#include "SHTx/sht15.hpp"
+
+DigitalOut busy(LED1);
+//ports on the Nucleo: PB_8, PB_9
+SHTx::SHT15 sensor(PB_8, PB_9);
+
+float GetTemperature()
+{
+//VARIABLES:
+    float temperature;          //this will be data read from sensor
+    
+    // Speed things up a bit.
+        sensor.setOTPReload(false);
+        sensor.setResolution(true);
+
+        busy = true;
+        sensor.update();
+        busy = false;
+
+    // Temperature in celcius
+    sensor.setScale(false);
+    temperature=sensor.getTemperature();       
+
+    wait(5);
+    return (temperature);
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/get_temp.h	Thu May 18 22:34:57 2017 +0000
@@ -0,0 +1,12 @@
+//Author : Olga Hoeyer
+//Date : 18 May 2017
+//Version : 2.0
+//Changes: Structure changed to modular, to ease future use of the funktion.
+//Copyright : Open for everyone
+//
+// Description : Function will get a temperature value from the SHF-15 sensor
+// Output is value in Celsius (float). 
+//
+// Usage: GetTemperature()
+
+float GetTemperature();
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/logging.cpp	Thu May 18 22:34:57 2017 +0000
@@ -0,0 +1,29 @@
+#include "mbed.h"
+
+void logging ()
+{
+    int i,t;
+    FILE *fp;
+
+
+    if ((fp = fopen("Logger_data", "a+")) == NULL) { //filnavn logger_data
+        fprintf (stdout, "Can't open \"Logger_data\" file.\n");
+        exit(EXIT_FAILURE);//sikre at filen kan åbnes
+    }
+
+    fprintf(fp,"\n\nlogger_data kl.00.00 D.dd-mm-yyyy\n"); //skriver i fil
+    fprintf(fp,"Temperatur:x\n");//variable fra temp indsættes
+    fprintf(fp,"Co2:x\n");//variable fra Co2 indsættes
+    fprintf(fp,"H2o:x"); //variable fra H2o indsættes
+
+
+    fprintf(fp,"Logger_data update complete!"); // 
+    if (fclose(fp) != 0)
+        fprintf(stderr, "Error closing file\n"); //lukker fil
+    
+    //sætter i og t = 0
+    i=0;
+    t=0;
+ 
+    return; //går over i hibernation
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/logging.h	Thu May 18 22:34:57 2017 +0000
@@ -0,0 +1,3 @@
+
+
+void logging ();
\ No newline at end of file
--- a/main.cpp	Thu May 11 11:40:27 2017 +0000
+++ b/main.cpp	Thu May 18 22:34:57 2017 +0000
@@ -1,289 +1,54 @@
 //Defining and Including stuff up here
 #include <mbed.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include "SHTx/sht15.hpp"               //"CMSIS Target not recognised"
-#define temperature_low = 18; //For use in the Data Analysis
-#define temperature_high = 25;  //For use in the Data Analysis
+#include "SHTx/sht15.hpp"
+#define temperature_low         //For use in the Data Analysis
+#define temperature_high        //For use in the Data Analysis
 #include "rgb_led.h"            //For use in the RGB_LED_output part
 #include "7_segment_control.h"  //For use in the RGB_LED_output part
 
+// MAIN er ikke færdig rettet!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+
+//Prototype definitions
+void Logging(); //Prototype for Logging
+void Hibernation();
+void Settings();
+void Comparevalues();
+void rgb_outp();
+
 
 //The correct order of files:
 
 //Declaration of GLOBAL VARIABLES:
 float temperature, humidity;            //this will be data read from sensor
 void GetTemperatureAndHumidity();
- 
-    Serial pc(USBTX, USBRX);
-    DigitalOut busy(LED1);                  //Don't think we need it.
-    InterruptIn event(USER_BUTTON);
-    DigitalOut myled(LED1);
-    DigitalIn up(p5);
-    DigitalIn down(p6);
-    
-    int status, humidity, temperature;
-    int Compare_values();
- 
+int i,t,set_temp,timespan,status;
+
+Serial pc(USBTX, USBRX);
+//DigitalOut busy(LED1);                 
+InterruptIn event(USER_BUTTON);
+DigitalOut myled(LED1);
+DigitalIn up(PA_5);
+DigitalIn down(PA_6);
+
+
 //ports on the Nucleo: PB_8, PB_9
 SHTx::SHT15 sensor(PB_8, PB_9);
 
 
-//At the very top, we're going to have main()
 
-int main() {
-    
+int main()
+{
+
     Logging();
-    
-    Hiberation();
-    
+
     Settings();
     
-    //Data Collection
-    GetTemperatureAndHumidity();
-
-    Comparevalues(); //Data Analysis
-    
-    void rgb_outp(int status)(); //RGB_LED_output
-    
-    return 0;
-    }
-
-    
-//1) Logging
-    void Logging() { //This needs to be updated before we have
-    //the final program done. 
-        FILE *fp;
- 
- 
-    if ((fp = fopen("Logger_data", "a+")) == NULL) { //filename logging_data
-        fprintf (stdout, "Can't open \"Logger_data\" file.\n");
-        exit(EXIT_FAILURE);//making sure that we can open the file
-    }
- 
-    fprintf(fp,"\n\nlogger_data kl.00.00 D.dd-mm-yyyy\n");//writing in the file
-    fprintf(fp,"Temperatur:x\n");//variable from temp will be put here
-    fprintf(fp,"Co2:x\n");//variable from Co2
-    fprintf(fp,"H2o:x"); //variable from H2o
- 
- 
-    fprintf(fp,"Logger_data update complete!"); 
-    if (fclose(fp) != 0)
-        fprintf(stderr, "Error closing file\n"); //Closing file
-    
-    //i and t are assigned to 0 here
-    i=0
-    t=0
- 
-    return 0; //goes into Hibernation
-}
-
-    
-
-//2) Hibernation
-
+    GetTemperatureAndHumidity();        //Data Collection
 
-void Hibernation() {
-    int t;
-    int i;
-    //Or whatever that brings it into Hibernation at once
-    
-    while(1)
-    {
-        if (i>0)
-        {
-            Settings();
-            }
-            else if (t=600) {
-                GetTemperatureAndHumidity(); //Data Collection
-                Comparevalues(); //Data Analysis
-                rgb.output(Olga_variable);
-                }
-                else
-                {
-                    t++;
-                    wait 1000 ms;
-                }
-            
-          
-          return 0;
-          
-            
-
-//3) Settings
-
-    void Settings(int t,i,set_temp,extern int timespan) {
-        while(i<1){ //Opening set_temp for input
-    
-    
-        if (up==1) {//Recieving input from the user
-           set_temp = (set_temp +1); } //if up, temp rises by 1
-        if (down==1) { //Recieving input from the user
-            set_temp = (set_temp -1);} //If down, temp drops by 1
-        else if (timespan == 500);{ 
-            break;}
-        }
-        
-        //If the system is passive for 5 seconds, i will be assigned to 2
-        //and t will get the value 700
-        //This forces it to go past hibernation
-        
-        i=2
-        t=700
-        return 0;
-    }
-
-
-//4) Data Collection
-
-void GetTemperatureAndHumidity()
-{
-    // Speed things up a bit.
-sensor.setOTPReload(false);
-sensor.setResolution(true);
- 
-while(1)
-{
-    busy = true;
-    sensor.update();
-    busy = false;
- 
-    // Temperature in celcius
-    sensor.setScale(false);
-    temperature=sensor.getTemperature();        //don't know if it works
- 
-    // Relative Humidity
-    humidity=sensor.getHumidity();               //don't know if it works
- 
-    wait(5);
-    return;
-}
-}
-
-//5) Data Analysis
+    Comparevalues( );                    //Data Analysis
 
-    void Comparevalues() {
-        
-        //__________________________________
-// Definition of limits
-//__________________________________
- 
-//Humidity limits.
-    const int HUMIDITY_LOW = 20;
-    const int HUMIDITY_HIGH= 60;
- 
-//Extra limits where LED will start blinking in red:
-//13 < Temp < 30; 10%< hum < 80%
-    const int HUMIDITY_EXTRA_LOW = 10;
-    const int HUMIDITY_EXTRA_HIGH= 80;
-    const int TEMPERATURE_EXTRA_LOW = 13;
-    const int TEMPERATURE_EXTRA_HIGH= 30;
- 
-//Definition of output values
-    const int GOOD_LEVEL = 1;               //green
-    const int ACCEPT_LEVEL = 2;             //orange
-    const int CRITICAL_LEVEL = 3;           //red
-    const int EXTRA_CRITICAL_LEVEL = 4;     //red strobe
-    const int USER_NEEDED = 5;              //blue strobe
- 
- 
-//__________________________________
-// main body: comparison
-//__________________________________
- 
-    humidity=(int)hum;                          //convertation of float to int.
-    temperature=(int)temp;
- 
-// check if there is a connection to the sensor
-// (if null=no data=there is no connection
- 
-    if ((temperature == 0)  || (humidity == 0))
-        status= USER_NEEDED;
- 
-    //comparing in nested loop.
-    else if ((temperature < TEMPERATURE_EXTRA_LOW)  ||
-             (temperature > TEMPERATURE_EXTRA_HIGH))
- 
-        status= EXTRA_CRITICAL_LEVEL;
- 
-    else if ((humidity < HUMIDITY_EXTRA_LOW)  ||
-             (humidity > HUMIDITY_EXTRA_HIGH))
- 
-        status= EXTRA_CRITICAL_LEVEL;
- 
-    else if ((temperature < temperature_low) ||
-             (temperature > temperature_high))
- 
-        status= CRITICAL_LEVEL;
- 
-    else if ((temperature < temperature_high) &&
-             (temperature > temperature_low) &&
-             (humidity < HUMIDITY_HIGH) &&
-             (humidity > HUMIDITY_LOW))
- 
-        status= GOOD_LEVEL;
- 
-    else status= ACCEPT_LEVEL;
- 
-    return(status);
+    rgb_outp(status);                         //RGB_LED_output
+
+    return 0;
 }
-
-
-//6) RGB_LED_output
-  void rgb_outp(int status)   {
-        
-    int status;                  // Status carries data from data analysis().
-    RGB_LED lamp(PC_8,PC_6,PB_9);// Creates an object out of the class RGB_LED.
-                                // Connect pins on the Nucleo, to the pins the
-                                // class.
-    // Following is a object of the class segment_7. It is the actual analogy
- // to our 7 segmented displays. There needs to go 11 pins into the parenteses.
-    //segment_7 seg_num(11 pins);              
-        
-        enum colour     // Enumeration is used only for making the program more 
-    {               // easily readable.
-        green,      // Is alike an int, starts at green = 1,
-        orange,     // orange = 2 etc.
-        red,
-        red_blink,
-        blue
-    }; 
- 
-    colour RGB_out = static_cast<colour>(status);
-    // Taking the value from the sensors and change them the enum type.
-    // Enum is somewhat akin to an int already, but RGB_out != status..
-    
-    switch(RGB_out)
-    {
-        case green:
-            lamp.set(0.0f, 1.0f, 0.0f);
-            lamp.flash(1.0f, 1.0f);         // On constantly.
-            break;
-        case orange:
-            lamp.set(1.0f, 0.6f, 0.0f);
-            lamp.flash(1.0f, 1.0f);         // On constantly.
-            break;
-        case red:
-            lamp.set(1.0f, 0.0f, 0.0f);
-            lamp.flash(1.0f, 1.0f);         // On constantly.
-            break;
-        case red_blink:
-            lamp.set(1.0f, 0.0f, 0.0f);
-            lamp.flash(2.0f, 0.5f);         // On for 50% of every 2 seconds.
-            break;
-        case blue:
-            lamp.set(0.0f, 0.0f, 1.0f);
-            lamp.flash(2.0f, 0.5f);         // On for 50% of every 2 seconds.
-            break;
-        default:   // Error has occured, blue. Could just have defaulted instead
-            lamp.set(0.0f, 0.0f, 1.0f);     // of case blue, however I think
-            lamp.flash(2.0f, 0.5f);         // this is more understandable.
-    }
-    
-    return;
-}
-
-        
-       
-