runinig version

Dependencies:   C12832_lcd NetServices freezer_guard_running mbed

Fork of Freezer_Guard_prog by team moped

Committer:
fbitz
Date:
Thu Jun 11 08:54:46 2015 +0000
Revision:
0:fc20669f5ba8
Child:
2:896a33daab3d
running version;

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 0:fc20669f5ba8 5 * Emailfunktion anpassen (Text und Werte einsetzen)
fbitz 0:fc20669f5ba8 6 # 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 0:fc20669f5ba8 9 # 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 0:fc20669f5ba8 42 byte 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 0:fc20669f5ba8 50 int i8Value=0;
fbitz 0:fc20669f5ba8 51 bState=0; //statemachine: 0=no Alarm, 1=Alarm and no Mail sent, 2=Alarm and Mail sent
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 0:fc20669f5ba8 58 if(i8Value>LIMIT && bState==0) bState=1;
fbitz 0:fc20669f5ba8 59 if(i8Value<LIMIT) bState=0;
fbitz 0:fc20669f5ba8 60 switch(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 0:fc20669f5ba8 68 strcpy(cString,"Alarm!");
fbitz 0:fc20669f5ba8 69 vLcdStringPrint(cString);
fbitz 0:fc20669f5ba8 70 bError=SendMail(i8Value);
fbitz 0:fc20669f5ba8 71 vAudioAlarm();
fbitz 0:fc20669f5ba8 72 bState=2;
fbitz 0:fc20669f5ba8 73 break;
fbitz 0:fc20669f5ba8 74 }
fbitz 0:fc20669f5ba8 75 case 2:{
fbitz 0:fc20669f5ba8 76 vLcdIntPrint(i8Value);
fbitz 0:fc20669f5ba8 77 strcpy(cString,"Mail Sent!");
fbitz 0:fc20669f5ba8 78 vLcdStringPrint(cString);
fbitz 0:fc20669f5ba8 79 vAudioAlarm();
fbitz 0:fc20669f5ba8 80 break;
fbitz 0:fc20669f5ba8 81 }
fbitz 0:fc20669f5ba8 82 case 3:{ //bState=3 could only be set by ISR
fbitz 0:fc20669f5ba8 83 vLcdIntPrint(i8Value);
fbitz 0:fc20669f5ba8 84 strcpy(cString,"Alarm Confirmed");
fbitz 0:fc20669f5ba8 85 vLcdStringPrint(cString);
fbitz 0:fc20669f5ba8 86 break;
fbitz 0:fc20669f5ba8 87 }
fbitz 0:fc20669f5ba8 88 default:{
fbitz 0:fc20669f5ba8 89 strcpy(cString,"State Machine Error!");
fbitz 0:fc20669f5ba8 90 vLcdStringPrint(cString);
fbitz 0:fc20669f5ba8 91 break;
fbitz 0:fc20669f5ba8 92 }
fbitz 0:fc20669f5ba8 93 }//state machine
fbitz 0:fc20669f5ba8 94 }//while(1)
fbitz 0:fc20669f5ba8 95
fbitz 0:fc20669f5ba8 96 }//main