27.02.2018

Dependencies:   Matrix

Fork of Alarmsystem_log_funksjon_funker_ikke by Programmeringsgruppe 1

Files at this revision

API Documentation at this revision

Comitter:
andreped
Date:
Tue Feb 27 11:19:05 2018 +0000
Parent:
16:3d2e29aa5df5
Commit message:
matrix;

Changed in this revision

Matrix.lib 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
diff -r 3d2e29aa5df5 -r f046c0ca9edd Matrix.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Matrix.lib	Tue Feb 27 11:19:05 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/Yo_Robot/code/Matrix/#a4014ab0a8cf
diff -r 3d2e29aa5df5 -r f046c0ca9edd main.cpp
--- a/main.cpp	Wed Feb 21 16:00:43 2018 +0000
+++ b/main.cpp	Tue Feb 27 11:19:05 2018 +0000
@@ -2,12 +2,14 @@
 #include "rtos.h"
 #include <string>
 #include <stdio.h>
+#include <vector>
+#include "Matrix.h"
 
 /////DEFINISJONER/////
 #define Inn 4
 Serial pc(USBTX, USBRX);
 LocalFileSystem local("local");
-FILE *fp = fopen("/local/log.txt", "w" ) ;
+FILE *fp = fopen("/local/log.txt", "w" );
 
 /////INNGANGER/////
 DigitalIn Servicebryter(p20);
@@ -26,12 +28,18 @@
 int tilstand = 0;
 volatile bool running = true;
 volatile bool admin = false;
+volatile int y1 = AlarmUtganger1;
+volatile int y2 = AlarmUtganger2;
 string password = ("admin");
 Timer t;
+Matrix tilstander(4, 4);
+Matrix buffer_tilstander(4, 4);
 
 /////FUNKSJON DEKLARASJONER/////
 void Alarmf();
+void log_to_file();
 Thread Alarm;
+Thread Log;
 int TilstandSjekk(int, int);
 void admin_access_granted();
 void sone_monitor();
@@ -40,7 +48,6 @@
 void request_status();
 void request_status_sone_dor(int sone, int dor);
 extern "C" void mbed_reset();
-int log_to_file(int, int);
 
 /////MAIN/////
 int main()
@@ -61,6 +68,7 @@
         }
         while((admin) && (Servicebryter == 0)) {
             Alarm.start(Alarmf);
+            Log.start(log_to_file);
             sone_monitor();
             read_keyinput();
         }
@@ -82,7 +90,7 @@
 
 int TilstandSjekk(int i, int tilstand)
 {
-    log_to_file(i, tilstand);
+    tilstander.add(i, tilstand, 1);
     if(tilstand == 0) {
         running = false;
         double n = 2;
@@ -118,29 +126,28 @@
     return 0;
 }
 
-int log_to_file(int i, int tilstand)
+void log_to_file(void)
 {
-    int p;
-    FILE *fp = fopen("/local/log.txt", "w" ) ;
-    if(fp != NULL) {
-        if ((tilstand == 1) && (p != 1)) {
-            fprintf(fp,"Sone %d, dor 1 er aapen \n",i);
-            fprintf(fp,"Tid:%f siden start \n",t.read());
-            p = 1;
-        }
+    while(tilstander != buffer_tilstander) {
+        for(int i = 0; i < 4; i++) {
+            if(fp != NULL) {
+                if(tilstander(i, 1) == 1) {
+                    fprintf(fp,"Sone %d, dor 1 er aapen \n", i);
+                    fprintf(fp,"Tid:%f siden start \n",t.read());
+                }
 
-        if ((tilstand == 2) && (p != 2)) {
-            fprintf(fp,"Sone %d, dor 2 er lukket \n",i);
-            fprintf(fp,"Tid:%f siden start \n",t.read());
-            p = 2;
-        }
-        if ((tilstand == 3) && (p != 3)) {
-            fprintf(fp,"Sone %d dor 1 og 2 er lukket \n",i);
-            fprintf(fp,"Tid:%f siden start \n",t.read());
-            p = 3;
+                if(tilstander(i, 2) == 1) {
+                    fprintf(fp,"Sone %d, dor 2 er lukket \n", i);
+                    fprintf(fp,"Tid:%f siden start \n",t.read());
+                }
+                if(tilstander(i, 3) == 1) {
+                    fprintf(fp,"Sone %d dor 1 og 2 er lukket \n",i);
+                    fprintf(fp,"Tid:%f siden start \n",t.read());
+                }
+            }
         }
     }
-    return 0;
+    buffer_tilstander = tilstander;
 }
 
 void sone_monitor()
@@ -215,7 +222,9 @@
             if( read == ("4, 1")) request_status_sone_dor(4, 1);
             if( read == ("4, 2")) request_status_sone_dor(4, 2);
             if( read == ("Status")) request_status();
-            if( read == ("Stop")) while(1){ fclose(fp); }
+            if( read == ("Stop")) while(1) {
+                    fclose(fp);
+                }
             if( read == ("Reset")) {
                 fclose(fp);
                 mbed_reset();