Wecker-Library

Dependents:   Projekt_Wecker_LCD Projekt_Wecker_LCD Projekt_Wecker_LCD

Files at this revision

API Documentation at this revision

Comitter:
wolpra98
Date:
Fri May 29 11:58:57 2015 +0000
Parent:
0:6f0b18518e88
Commit message:
Completed the Alarm Clock

Changed in this revision

Wecker.cpp Show annotated file Show diff for this revision Revisions of this file
Wecker.h Show annotated file Show diff for this revision Revisions of this file
--- a/Wecker.cpp	Thu Apr 30 10:35:04 2015 +0000
+++ b/Wecker.cpp	Fri May 29 11:58:57 2015 +0000
@@ -4,30 +4,24 @@
 #include "RTC8563.h"
 #include "Wecker.h"
 
-char week;
+
+/*char week;
 int hour, minute, sec;
 int hrse, hrsz, mine, minz, sece, secz;
 int ahour, aminute, ahrse, ahrsz, amine, aminz;
 int nextStd, nextMin;
 typedef enum {Normal, setAlarm, AlarmOn, Alarm, Sleep} state;
-state Mode=Normal;
 Ticker tick1;
-Timer tim1,tim2;
+Timer tim1,tim2;*/
 
 RTC8563 rtc;
 Serial pc(USBTX, USBRX);
 I2C i2c(p28, p27);
 LCD lcd(p11, p6, p7, p8, p9, p10);
 
-InterruptIn swStd(P1_16);
-InterruptIn swMin(P0_23);
-InterruptIn swSlp(P0_10);
-
 Wecker::Wecker()
 {
-    swStd.rise(this, &Wecker::btn1);
-    swMin.rise(this, &Wecker::btn2);
-    swSlp.rise(this, &Wecker::btn3);
+
     //tick1.attach(this, &Wecker::tickHold,0.1);
 }
 
@@ -85,99 +79,8 @@
 
 }
 
-void Wecker::btn1()
+void Wecker::printState(char *Mode)
 {
-    switch (Mode) {
-        case Normal:
-            int nextStd = unbcd(rtc.rtc_read(HOURS));
-            if (nextStd>=23)
-                nextStd=0;
-            else
-                nextStd++;
-            rtc.rtc_write(HOURS, bcd(nextStd));
-            while(swStd==1);
-            break;
-        case setAlarm:
-            nextStd = unbcd(rtc.rtc_read(HOUR_ALARM));
-            if (nextStd>=23)
-                nextStd=0;
-            else
-                nextStd++;
-            rtc.rtc_write(HOUR_ALARM, bcd(nextStd));
-            while(swStd==1);
-            break;
-    }
-}
-
-void Wecker::btn2()
-{
-    switch (Mode) {
-        case Normal:
-            nextMin = unbcd(rtc.rtc_read(MINUTES));
-            if (nextMin>=59)
-                nextMin=0;
-            else
-                nextMin++;
-            rtc.rtc_write(MINUTES, bcd(nextMin));
-            while(swStd==1);
-            break;
-        case setAlarm:
-            nextMin = unbcd(rtc.rtc_read(MINUTE_ALARM));
-            if (nextMin>=59)
-                nextMin=0;
-            else
-                nextMin++;
-            rtc.rtc_write(MINUTE_ALARM, bcd(nextMin));
-            while(swStd==1);
-            break;
+    lcd.setcursor(14,1);
+    lcd.string(Mode);
     }
-}
-
-void Wecker::tickHold()
-{
-    switch (Mode) {
-        case Normal:
-            if (swSlp==1)
-                tim2.start();
-            if ((swStd==1&&tim2.read()<5.0)||(swMin==1&&tim2.read()<5.0)) {
-                Mode =setAlarm;
-                tim2.stop();
-                tim2.reset();
-            } else {
-                tim2.stop();
-                tim2.reset();
-            }
-            break;
-        case AlarmOn:
-            if (swSlp==1)
-                tim1.start();
-            while(swSlp==1);
-            tim1.stop();
-            if (tim1.read()>=3.0)
-                Mode = Normal;
-            tim1.reset();
-            break;
-        case Sleep:
-            if (swSlp==1)
-                tim1.start();
-            while(swSlp==1);
-            tim1.stop();
-            if (tim1.read()>=3.0)
-                Mode = Normal;
-            tim1.reset();
-            break;
-    }
-}
-
-void Wecker::btn3()
-{
-    switch (Mode) {
-        case Normal:
-            tim1.start();
-            while(swSlp==1);
-            tim1.stop();
-            if (tim1.read()>=3.0)
-                Mode = Alarm;
-            tim1.reset();
-    }
-}
\ No newline at end of file
--- a/Wecker.h	Thu Apr 30 10:35:04 2015 +0000
+++ b/Wecker.h	Fri May 29 11:58:57 2015 +0000
@@ -2,6 +2,7 @@
 #include "LCD.h"
 #include "const.h"
 #include "RTC8563.h"
+#include <string>
 
 #if !defined(_WECKER_H)
 #define _WECKER_H
@@ -11,11 +12,14 @@
     Wecker();
     void printTime();
     void printAlarmTime();
-    void btn1();
-    void btn2();
-    void btn3();
-    void tickHold();
+    void test();
     int bcd(int dec);
     int unbcd(int bcd);
+    void printState(char *Mode);
+    char week;
+    int hour, minute, sec;
+    int hrse, hrsz, mine, minz, sece, secz;
+    int ahour, aminute, ahrse, ahrsz, amine, aminz;
+    int nextStd, nextMin;
 };
 #endif
\ No newline at end of file