Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of prosjektoppgave_alarm by
Diff: main.cpp
- Revision:
- 14:4020d8bdb6a6
- Parent:
- 13:892212c61603
- Child:
- 15:549d573fcad7
--- a/main.cpp Wed Jan 25 11:59:08 2017 +0000
+++ b/main.cpp Wed Jan 25 12:17:20 2017 +0000
@@ -18,6 +18,7 @@
struct alarmKretser brytere[4];
int status = 0; //1 = alarm
+int alarmStatus = 0;
@@ -39,20 +40,18 @@
void blink()
{
- if (status==0) {
- led.period(0.1f);
- led.write(1.0f);
- } else {
led.period(0.1f);
led.write(0.5f);
}
-void log(int status = 0, int tall = 0, char bokstav = '0') {
+
+void log(int status = 0, int tall = 0, char bokstav = '0')
+{
FILE *fp = fopen("/local/log.txt", "a");
fprintf(fp, "\r\n TIME: %f |", systemTid.read());
- switch(status){
+ switch(status) {
case 1:
- fprintf(fp,"ALARM, bryter: %d", tall);
+ fprintf(fp,"ALARM! krest %d, bryter %c", tall,bokstav);
break;
case 2:
fprintf(fp,"ALARM, nullstillt ved servisbryter");
@@ -72,9 +71,6 @@
int alarmSjekk(AnalogIn& krets, int kretsn)
{
-
-
-int alarmSjekk(AnalogIn& krets, int kretsn){
//TODO: oppdater tabell med hvilken alarm som har gått
/* Sjekker kretsen etter spenningsendring og returnerer hvilke bryter som er åpen
@@ -91,38 +87,35 @@
pc.printf("volt %f", volt);
if(volt <= bryter0) {
- pc.printf("volt: %f",volt);
- if(volt <= bryter0){
-
status = 1;
if(volt < bryterAhigh) {
if(volt < bryterBhigh) {
if(volt < bryterABhigh) {
bryter = 3;
- if (brytere[kretsn-1].A != 1 || brytere[kretsn-1].B != 1){
+ if (brytere[kretsn].A != 1 || brytere[kretsn].B != 1) {
log(1,kretsn,'A');
log(1,kretsn,'B');
}
- brytere[kretsn-1].A = brytere[kretsn-1].B = 1;
-
+ brytere[kretsn].A = brytere[kretsn].B = 1;
+
} else {
bryter = 2;
- if ( brytere[kretsn-1].B != 1){
+ if ( brytere[kretsn].B != 1) {
log(1,kretsn,'B');
}
- brytere[kretsn-1].B = 1;
+ brytere[kretsn].B = 1;
}
} else {
bryter = 1;
- if ( brytere[kretsn-1].B != 1){
- log(1,kretsn,'B');
- }
- brytere[kretsn-1].A = 1;
+ if ( brytere[kretsn].B != 1) {
+ log(1,kretsn,'B');
+ }
+ brytere[kretsn].A = 1;
}
} else {
bryter = -2;
}
- } else(bryter = 0);
+ } else(bryter = 0;)
return bryter;
}
@@ -137,10 +130,16 @@
void statusLED()
{
- //oppdatere statusLED til aktiverte alarmer
- for(int i=0; brytere[i]!=NULL; i++) {
- if(brytere[i] == 1) {
- ledStatus = ledStatus+i;
+ if(status == 0){
+ if(alarmStatus != 1){
+ led.period(1.0f);
+ led.write(1.0f);
+ alarmStatus = 1;
+ }
+ } else {
+ if(alarmStatus != 2){
+ blink();
+ alarmStatus = 2;
}
}
}
@@ -149,11 +148,6 @@
void resetSystem()
{
- //reseter alarmsystemet
- for(int i=0; brytere[i]!=NULL; i++) {
- brytere[i] = 0;
- }
- status = 0;
}
@@ -169,10 +163,9 @@
int main()
{
systemTid.start();
- while(1){
+ while(1) {
pc.printf("\r ");
- sjekkAlleKretser();
+ chron();
pc.printf(" | Alarm Status: %d\r\n",status);
- wait(0.5);
}
}
