Clock with Real-Time Clock (RTC-8564) and I2C LCD module(SB1062B).

Dependencies:   DebouncedEdgeIn I2cLCD_cursor Rtc8564 mbed beep

/media/uploads/togayan/imgp0004s.jpg /media/uploads/togayan/lcdclock_circuit_rev4.png

Files at this revision

API Documentation at this revision

Comitter:
togayan
Date:
Fri Feb 28 14:04:16 2014 +0000
Parent:
4:75ed86b78045
Child:
6:e7073adacdc8
Commit message:
Change pin assign. Add BEEP sound.

Changed in this revision

ViewModel/ClockViewModel.cpp Show annotated file Show diff for this revision Revisions of this file
ViewModel/ClockViewModel.h Show annotated file Show diff for this revision Revisions of this file
beep.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
--- a/ViewModel/ClockViewModel.cpp	Sun Feb 23 00:16:54 2014 +0000
+++ b/ViewModel/ClockViewModel.cpp	Fri Feb 28 14:04:16 2014 +0000
@@ -20,11 +20,13 @@
 
 const char* ClockViewModel::WEEKDAYS[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT", "ERR"};
 
-ClockViewModel::ClockViewModel(I2cLCD& i2clcd, PinName set, PinName increment, PinName decrement)
+ClockViewModel::ClockViewModel(I2cLCD& i2clcd, PinName set, PinName increment, PinName decrement, PinName beep1, PinName beep2)
     :m_i2clcd(i2clcd),
      m_set(set),
      m_increment(increment),
      m_decrement(decrement),
+     m_beep(beep1),
+     m_beepGnd(beep2),
      m_clock(0),
      m_dateTime(0),
      m_mode(Model::CLOCK)
@@ -32,7 +34,7 @@
     m_set.mode(PullUp);
     m_increment.mode(PullUp);
     m_decrement.mode(PullUp);
-    m_set.fall(this, &ClockViewModel::setButtonOn);
+    m_set.fall(this, &ClockViewModel::modeButtonOn);
     m_increment.fall(this, &ClockViewModel::incrementButtonOn);
     m_decrement.fall(this, &ClockViewModel::decrementButtonOn);
 }
@@ -100,47 +102,55 @@
     setCurSor();
 }
 
-void ClockViewModel::setButtonOn()
+void ClockViewModel::modeButtonOn()
 {
+    m_beep.beep(400, 0.05);
     m_clock->requestModeChange();
 }
 
 void ClockViewModel::incrementButtonOn()
 {
+    if(m_mode == Model::CLOCK) {
+        return;
+    }
+    m_beep.beep(400, 0.05);
     m_clock->requestIncrementValue();
 }
 
 void ClockViewModel::decrementButtonOn()
 {
+    if(m_mode == Model::CLOCK) {
+        return;
+    }
+    m_beep.beep(400, 0.05);
     m_clock->requestDecrementValue();
 }
 
 void ClockViewModel::setCurSor()
 {
-    switch(m_mode)
-    {
-    case Model::CLOCK:
-        m_i2clcd.cursor(false, 0, 0);
-        break;
-    case Model::SET_YEAR:
-        m_i2clcd.cursor(true, 4, 0);
-        break;
-    case Model::SET_MONTH:
-        m_i2clcd.cursor(true, 7, 0);
-        break;
-    case Model::SET_DAY:
-        m_i2clcd.cursor(true, 10, 0);
-        break;
-    case Model::SET_HOUR:
-        m_i2clcd.cursor(true, 3, 1);
-        break;
-    case Model::SET_MINUTE:
-        m_i2clcd.cursor(true, 8, 1);
-        break;
-    case Model::SET_SECOND:
-        m_i2clcd.cursor(true, 13, 1);
-        break;
-    default:
-        break;
+    switch(m_mode) {
+        case Model::CLOCK:
+            m_i2clcd.cursor(false, 0, 0);
+            break;
+        case Model::SET_YEAR:
+            m_i2clcd.cursor(true, 4, 0);
+            break;
+        case Model::SET_MONTH:
+            m_i2clcd.cursor(true, 7, 0);
+            break;
+        case Model::SET_DAY:
+            m_i2clcd.cursor(true, 10, 0);
+            break;
+        case Model::SET_HOUR:
+            m_i2clcd.cursor(true, 3, 1);
+            break;
+        case Model::SET_MINUTE:
+            m_i2clcd.cursor(true, 8, 1);
+            break;
+        case Model::SET_SECOND:
+            m_i2clcd.cursor(true, 13, 1);
+            break;
+        default:
+            break;
     }
 }
--- a/ViewModel/ClockViewModel.h	Sun Feb 23 00:16:54 2014 +0000
+++ b/ViewModel/ClockViewModel.h	Fri Feb 28 14:04:16 2014 +0000
@@ -6,13 +6,14 @@
 #include "I2cLCD/I2cLCD.h"
 #include "Model/I_NotifyUpdate.h"
 #include "DebouncedEdgeIn/DebouncedEdgeIn.h"
+#include "beep.h"
 
 namespace ViewModel
 {
 class ClockViewModel : public Model::I_NotifyUpdate, public Model::I_SetMode
 {
 public:
-    ClockViewModel(I2cLCD& i2clcd, PinName set, PinName increment, PinName decrement);
+    ClockViewModel(I2cLCD& i2clcd, PinName set, PinName increment, PinName decrement, PinName sound1, PinName Sound2);
     void setClock(Model::Clock* clock);
     void initialize();
 
@@ -24,12 +25,14 @@
     DebouncedEdgeIn m_set;
     DebouncedEdgeIn m_increment;
     DebouncedEdgeIn m_decrement;
+    Beep m_beep;
+    DigitalOut m_beepGnd;
     Model::Clock* m_clock;
     struct tm* m_dateTime;
     Model::OperationMode m_mode;
     static const char* WEEKDAYS[];
-    
-    void setButtonOn();
+        
+    void modeButtonOn();
     void incrementButtonOn();
     void decrementButtonOn();
     void setCurSor();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/beep.lib	Fri Feb 28 14:04:16 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/dreschpe/code/beep/#d8e14429a95f
--- a/main.cpp	Sun Feb 23 00:16:54 2014 +0000
+++ b/main.cpp	Fri Feb 28 14:04:16 2014 +0000
@@ -5,12 +5,26 @@
 #include "Mechanism/RtcMechanism.h"
 #include "Model/Clock.h"
 
+extern "C" void HardFault_Handler()
+{
+    puts("Hard Fault!");
+    while(1);
+}
+
+void no_memory ()
+{
+    puts("panic: can't allocate to memory!");
+    exit(-1);
+}
+
 int main()
 {
+    set_new_handler(no_memory);
+
     I2C i2c(dp5, dp27); //sda scl
     I2cLCD lcd(i2c, dp26); //i2c reset
-    Rtc8564 rtc(i2c, dp25, PullUp); 
-    ViewModel::ClockViewModel clockVm(lcd, dp1, dp2, dp4); // set increment decrement
+    Rtc8564 rtc(i2c, dp25, PullUp);
+    ViewModel::ClockViewModel clockVm(lcd, dp28, dp24, dp17, dp1, dp2); // set increment decrement sound1 sound2
     RtcMechanism rtcMechanism;
     Model::Clock clock(&clockVm, &rtcMechanism);
     clock.addSetMode(&rtcMechanism);