runinig version

Dependencies:   C12832_lcd NetServices freezer_guard_running mbed

Fork of Freezer_Guard_prog by team moped

Committer:
fbitz
Date:
Tue Jun 16 11:16:33 2015 +0000
Revision:
2:896a33daab3d
Parent:
0:fc20669f5ba8
Child:
3:94c8a14df287
coding std applied

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fbitz 0:fc20669f5ba8 1 /*
fbitz 0:fc20669f5ba8 2 TODO:
fbitz 0:fc20669f5ba8 3 * Display entmüllen
fbitz 0:fc20669f5ba8 4 * Displayausgabefunktion anpassen (übergabe von koordinaten)
fbitz 2:896a33daab3d 5 OK Emailfunktion anpassen (Text und Werte einsetzen)
fbitz 2:896a33daab3d 6 OK wait anweisungen überprüfen und wenn möglich eliminieren
fbitz 0:fc20669f5ba8 7 # Datentypen reduzieren
fbitz 0:fc20669f5ba8 8 # Ungarische Notation einführen (-> Coding Richtline)
fbitz 2:896a33daab3d 9 OK bei printfunktionen string direkt übergeben
fbitz 0:fc20669f5ba8 10 #Doku
fbitz 0:fc20669f5ba8 11 #Demo VErsion mit Alarm bei >temp erstellen
fbitz 0:fc20669f5ba8 12 # DEBUG ausgaben entfernen
fbitz 0:fc20669f5ba8 13 */
fbitz 0:fc20669f5ba8 14
fbitz 0:fc20669f5ba8 15
fbitz 0:fc20669f5ba8 16 /******************************************************
fbitz 0:fc20669f5ba8 17 *File Name: Freezer_Guard main.cpp
fbitz 0:fc20669f5ba8 18 *Purpose: Freezer Guard System protects your freezer from unintentionaly defrost
fbitz 0:fc20669f5ba8 19 *
fbitz 0:fc20669f5ba8 20 *Author: denis schnier and fabian bitz @ University of applied sciences bingen
fbitz 0:fc20669f5ba8 21 *Changes:
fbitz 0:fc20669f5ba8 22 *
fbitz 0:fc20669f5ba8 23 * 18.05.2015 initial version
fbitz 0:fc20669f5ba8 24 * ...
fbitz 0:fc20669f5ba8 25 *******************************************************/
fbitz 0:fc20669f5ba8 26
fbitz 0:fc20669f5ba8 27 /******************************************************
fbitz 0:fc20669f5ba8 28 *1 Initialisierungsfunktion aufrufen
fbitz 0:fc20669f5ba8 29 *2
fbitz 0:fc20669f5ba8 30 *3 readValue() aufrufen
fbitz 0:fc20669f5ba8 31 *3 Rueckgabewert pruefen
fbitz 0:fc20669f5ba8 32 *3a Zustandsautomat auf Alarm oder zurück setzen
fbitz 0:fc20669f5ba8 33 *4 ggf. sendMail() aufrufen
fbitz 0:fc20669f5ba8 34 *4a sendMail initialisiert Ethertnet IF
fbitz 0:fc20669f5ba8 35 *4b sendMail versendet email (alle ausgabe über serielle Konsole)
fbitz 0:fc20669f5ba8 36 *5 audioAlarm() aufrufen und Alarmsound ausgeben
fbitz 0:fc20669f5ba8 37 *6 springe zu *3
fbitz 0:fc20669f5ba8 38 *******************************************************/
fbitz 0:fc20669f5ba8 39 #include "guard.h"
fbitz 0:fc20669f5ba8 40 #include "string.h"
fbitz 0:fc20669f5ba8 41 #define LIMIT -10 // Temperature Alarm Threshold
fbitz 2:896a33daab3d 42 byte MAIN_bState;
fbitz 0:fc20669f5ba8 43 byte bError;
fbitz 0:fc20669f5ba8 44 char cString[25];
fbitz 0:fc20669f5ba8 45 char data_array[2];
fbitz 0:fc20669f5ba8 46
fbitz 0:fc20669f5ba8 47
fbitz 0:fc20669f5ba8 48 int main()
fbitz 0:fc20669f5ba8 49 {
fbitz 2:896a33daab3d 50 int8 i8Value=0; //value has 8 bit + sign
fbitz 2:896a33daab3d 51 MAIN_bState=0; //statemachine: 0=no Alarm, 1=Alarm and no Mail sent, 2=Alarm and Mail sent, 3= Pending Alarm Confirmed
fbitz 0:fc20669f5ba8 52 bError=0;
fbitz 0:fc20669f5ba8 53 vGuardInit();
fbitz 0:fc20669f5ba8 54
fbitz 0:fc20669f5ba8 55 while(1){
fbitz 0:fc20669f5ba8 56 i8Value=readValue(MCP9808_ADDR);
fbitz 0:fc20669f5ba8 57 wait(1);
fbitz 2:896a33daab3d 58 if(i8Value>LIMIT && MAIN_bState==0) MAIN_bState=1;
fbitz 2:896a33daab3d 59 if(i8Value<LIMIT) MAIN_bState=0;
fbitz 2:896a33daab3d 60 switch(MAIN_bState) {
fbitz 0:fc20669f5ba8 61 case 0: { //normal case
fbitz 0:fc20669f5ba8 62 vLcdIntPrint(i8Value);
fbitz 0:fc20669f5ba8 63 break;
fbitz 0:fc20669f5ba8 64 }
fbitz 0:fc20669f5ba8 65
fbitz 0:fc20669f5ba8 66 case 1:{
fbitz 0:fc20669f5ba8 67 vLcdIntPrint(i8Value);
fbitz 2:896a33daab3d 68 vLcdStringPrint("Alarm!");
fbitz 0:fc20669f5ba8 69 bError=SendMail(i8Value);
fbitz 0:fc20669f5ba8 70 vAudioAlarm();
fbitz 2:896a33daab3d 71 MAIN_bState=2;
fbitz 0:fc20669f5ba8 72 break;
fbitz 0:fc20669f5ba8 73 }
fbitz 0:fc20669f5ba8 74 case 2:{
fbitz 0:fc20669f5ba8 75 vLcdIntPrint(i8Value);
fbitz 2:896a33daab3d 76 vLcdStringPrint("Mail Sent!");
fbitz 0:fc20669f5ba8 77 vAudioAlarm();
fbitz 0:fc20669f5ba8 78 break;
fbitz 0:fc20669f5ba8 79 }
fbitz 2:896a33daab3d 80 case 3:{ //MAIN_bState=3 could only be set by ISR
fbitz 0:fc20669f5ba8 81 vLcdIntPrint(i8Value);
fbitz 2:896a33daab3d 82 vLcdStringPrint("Alarm Confirmed");
fbitz 0:fc20669f5ba8 83 break;
fbitz 0:fc20669f5ba8 84 }
fbitz 0:fc20669f5ba8 85 default:{
fbitz 2:896a33daab3d 86 // strcpy(cString,"State Machine Error!");
fbitz 2:896a33daab3d 87 vLcdStringPrint("State Machine Error!");
fbitz 0:fc20669f5ba8 88 break;
fbitz 0:fc20669f5ba8 89 }
fbitz 0:fc20669f5ba8 90 }//state machine
fbitz 0:fc20669f5ba8 91 }//while(1)
fbitz 0:fc20669f5ba8 92
fbitz 0:fc20669f5ba8 93 }//main