runinig version

Dependencies:   C12832_lcd NetServices freezer_guard_running mbed

Fork of Freezer_Guard_prog by team moped

Committer:
fbitz
Date:
Sat Jun 27 09:36:05 2015 +0000
Revision:
5:51602f038021
Parent:
4:cc87d93fd170
running version;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fbitz 0:fc20669f5ba8 1 /******************************************************
fbitz 0:fc20669f5ba8 2 *File Name: Freezer_Guard main.cpp
fbitz 0:fc20669f5ba8 3 *Purpose: Freezer Guard System protects your freezer from unintentionaly defrost
fbitz 0:fc20669f5ba8 4 *
fbitz 0:fc20669f5ba8 5 *Author: denis schnier and fabian bitz @ University of applied sciences bingen
fbitz 0:fc20669f5ba8 6 *Changes:
fbitz 0:fc20669f5ba8 7 *
fbitz 0:fc20669f5ba8 8 * 18.05.2015 initial version
fbitz 0:fc20669f5ba8 9 * ...
fbitz 0:fc20669f5ba8 10 *******************************************************/
fbitz 0:fc20669f5ba8 11
fbitz 0:fc20669f5ba8 12 #include "guard.h"
fbitz 0:fc20669f5ba8 13 #include "string.h"
fbitz 4:cc87d93fd170 14 #define LIMIT 25 // Temperature Alarm Threshold
fbitz 2:896a33daab3d 15 byte MAIN_bState;
fbitz 0:fc20669f5ba8 16 byte bError;
fbitz 0:fc20669f5ba8 17 char cString[25];
fbitz 0:fc20669f5ba8 18 char data_array[2];
fbitz 4:cc87d93fd170 19 DigitalOut led4(LED4); //DEBUG
fbitz 0:fc20669f5ba8 20
fbitz 0:fc20669f5ba8 21 int main()
fbitz 0:fc20669f5ba8 22 {
fbitz 2:896a33daab3d 23 int8 i8Value=0; //value has 8 bit + sign
fbitz 2:896a33daab3d 24 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 25 bError=0;
fbitz 0:fc20669f5ba8 26 vGuardInit();
fbitz 4:cc87d93fd170 27 led4=0; //DEBUG
fbitz 0:fc20669f5ba8 28 while(1){
fbitz 0:fc20669f5ba8 29 i8Value=readValue(MCP9808_ADDR);
fbitz 0:fc20669f5ba8 30 wait(1);
fbitz 2:896a33daab3d 31 if(i8Value>LIMIT && MAIN_bState==0) MAIN_bState=1;
fbitz 2:896a33daab3d 32 if(i8Value<LIMIT) MAIN_bState=0;
fbitz 2:896a33daab3d 33 switch(MAIN_bState) {
fbitz 0:fc20669f5ba8 34 case 0: { //normal case
fbitz 0:fc20669f5ba8 35 vLcdIntPrint(i8Value);
fbitz 4:cc87d93fd170 36 vLcdAlarmPrint("System Running");
fbitz 4:cc87d93fd170 37 vLcdStringPrint("Temperature Ok \n ");
fbitz 0:fc20669f5ba8 38 break;
fbitz 0:fc20669f5ba8 39 }
fbitz 0:fc20669f5ba8 40
fbitz 0:fc20669f5ba8 41 case 1:{
fbitz 0:fc20669f5ba8 42 vLcdIntPrint(i8Value);
fbitz 4:cc87d93fd170 43 vLcdAlarmPrint("Alarm! ");
fbitz 4:cc87d93fd170 44 vAudioAlarm();
fbitz 4:cc87d93fd170 45 // bError=SendMail(i8Value);
fbitz 4:cc87d93fd170 46 if(SendMail(i8Value))vLcdStringPrint("Mail Sent! \n ");
fbitz 4:cc87d93fd170 47 else{
fbitz 4:cc87d93fd170 48 vLcdStringPrint("Mail Not Sent! \n ");
fbitz 4:cc87d93fd170 49 }
fbitz 4:cc87d93fd170 50 led4=1; //DEBUG
fbitz 4:cc87d93fd170 51
fbitz 4:cc87d93fd170 52 MAIN_bState=2;
fbitz 0:fc20669f5ba8 53 break;
fbitz 0:fc20669f5ba8 54 }
fbitz 4:cc87d93fd170 55 case 2:{ // case: mail sent, alarm pending
fbitz 0:fc20669f5ba8 56 vLcdIntPrint(i8Value);
fbitz 0:fc20669f5ba8 57 vAudioAlarm();
fbitz 0:fc20669f5ba8 58 break;
fbitz 0:fc20669f5ba8 59 }
fbitz 2:896a33daab3d 60 case 3:{ //MAIN_bState=3 could only be set by ISR
fbitz 0:fc20669f5ba8 61 vLcdIntPrint(i8Value);
fbitz 0:fc20669f5ba8 62 break;
fbitz 0:fc20669f5ba8 63 }
fbitz 0:fc20669f5ba8 64 default:{
fbitz 2:896a33daab3d 65 vLcdStringPrint("State Machine Error!");
fbitz 0:fc20669f5ba8 66 break;
fbitz 0:fc20669f5ba8 67 }
fbitz 0:fc20669f5ba8 68 }//state machine
fbitz 0:fc20669f5ba8 69 }//while(1)
fbitz 0:fc20669f5ba8 70
fbitz 0:fc20669f5ba8 71 }//main