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

Committer:
togayan
Date:
Fri Feb 14 09:24:03 2014 +0000
Revision:
1:f8713c387a68
Parent:
0:86ab67787717
Child:
2:6f0158399eff
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
togayan 0:86ab67787717 1 #include "ClockViewModel.h"
togayan 1:f8713c387a68 2 #include "EventMechanism/EventParam0.h"
togayan 0:86ab67787717 3
togayan 0:86ab67787717 4 using ViewModel::ClockViewModel;
togayan 0:86ab67787717 5
togayan 0:86ab67787717 6 // Icon Name ----
togayan 0:86ab67787717 7 // Mark
togayan 0:86ab67787717 8 // Battery_1
togayan 0:86ab67787717 9 // Battery_2
togayan 0:86ab67787717 10 // Battery_3
togayan 0:86ab67787717 11 // Battery_4
togayan 0:86ab67787717 12 // NoSound
togayan 0:86ab67787717 13 // Lock
togayan 0:86ab67787717 14 // ArrowDown
togayan 0:86ab67787717 15 // ArrowUp
togayan 0:86ab67787717 16 // Input
togayan 0:86ab67787717 17 // Alarm
togayan 0:86ab67787717 18 // Tell
togayan 0:86ab67787717 19 // Antenna
togayan 0:86ab67787717 20 // --------------
togayan 0:86ab67787717 21
togayan 1:f8713c387a68 22 ClockViewModel::ClockViewModel(I2cLCD& i2clcd, PinName set, PinName select, EventMechanism::I_EventHandler* evHandler, DigitalOut& led)
togayan 0:86ab67787717 23 :m_i2clcd(i2clcd),
togayan 1:f8713c387a68 24 m_set(set),
togayan 1:f8713c387a68 25 m_select(select),
togayan 1:f8713c387a68 26 m_evHandler(evHandler),
togayan 1:f8713c387a68 27 m_clock(0),
togayan 1:f8713c387a68 28 m_dateTime(0),
togayan 1:f8713c387a68 29 m_led(led)
togayan 0:86ab67787717 30 {
togayan 1:f8713c387a68 31 m_set.mode(PullUp);
togayan 1:f8713c387a68 32 m_set.fall(this, &ClockViewModel::setButtonPressed);
togayan 1:f8713c387a68 33 }
togayan 1:f8713c387a68 34
togayan 1:f8713c387a68 35 void ClockViewModel::setClock(Model::Clock* clock)
togayan 1:f8713c387a68 36 {
togayan 1:f8713c387a68 37 m_clock = clock;
togayan 1:f8713c387a68 38 m_dateTime = m_clock->getDateTime();
togayan 0:86ab67787717 39 }
togayan 0:86ab67787717 40
togayan 0:86ab67787717 41 void ClockViewModel::initialize()
togayan 0:86ab67787717 42 {
togayan 1:f8713c387a68 43 //m_set.rise(this, &ClockViewModel::setButtonPressed);
togayan 1:f8713c387a68 44 m_select.fall(this, &ClockViewModel::selectButtonPressed);
togayan 1:f8713c387a68 45
togayan 0:86ab67787717 46 // print ICON
togayan 0:86ab67787717 47 m_i2clcd.seticon( I2cLCD::Mark );
togayan 0:86ab67787717 48 m_i2clcd.seticon( I2cLCD::Battery_1 );
togayan 0:86ab67787717 49 m_i2clcd.seticon( I2cLCD::Battery_2 );
togayan 0:86ab67787717 50 m_i2clcd.seticon( I2cLCD::Battery_3 );
togayan 0:86ab67787717 51 m_i2clcd.seticon( I2cLCD::Battery_4 );
togayan 0:86ab67787717 52 m_i2clcd.seticon( I2cLCD::NoSound );
togayan 0:86ab67787717 53 m_i2clcd.seticon( I2cLCD::Lock );
togayan 0:86ab67787717 54 m_i2clcd.seticon( I2cLCD::ArrowDown );
togayan 0:86ab67787717 55 m_i2clcd.seticon( I2cLCD::ArrowUp );
togayan 0:86ab67787717 56 m_i2clcd.seticon( I2cLCD::Input );
togayan 0:86ab67787717 57 m_i2clcd.seticon( I2cLCD::Alarm );
togayan 0:86ab67787717 58 m_i2clcd.seticon( I2cLCD::Tell );
togayan 0:86ab67787717 59 m_i2clcd.seticon( I2cLCD::Antenna );
togayan 0:86ab67787717 60 }
togayan 0:86ab67787717 61
togayan 1:f8713c387a68 62 void ClockViewModel::dateTimeUpdated()
togayan 0:86ab67787717 63 {
togayan 1:f8713c387a68 64 static char dat[31] = " 20-- / -- / --\n -- : -- : --";
togayan 1:f8713c387a68 65 uint8_t val = 0;
togayan 1:f8713c387a68 66
togayan 1:f8713c387a68 67 val = m_dateTime->year % 100;
togayan 1:f8713c387a68 68 dat[3] = '0' + val / 10;
togayan 1:f8713c387a68 69 dat[4] = '0' + val % 10;
togayan 1:f8713c387a68 70 val = m_dateTime->month;
togayan 1:f8713c387a68 71 dat[8] = '0' + val / 10;
togayan 1:f8713c387a68 72 dat[9] = '0' + val % 10;
togayan 1:f8713c387a68 73 val = m_dateTime->day;
togayan 1:f8713c387a68 74 dat[13] = '0' + val / 10;
togayan 1:f8713c387a68 75 dat[14] = '0' + val % 10;
togayan 1:f8713c387a68 76 val = m_dateTime->hour;
togayan 1:f8713c387a68 77 dat[18] = '0' + val / 10;
togayan 1:f8713c387a68 78 dat[19] = '0' + val % 10;
togayan 1:f8713c387a68 79 val = m_dateTime->minute;
togayan 1:f8713c387a68 80 dat[23] = '0' + val / 10;
togayan 1:f8713c387a68 81 dat[24] = '0' + val % 10;
togayan 1:f8713c387a68 82 val = m_dateTime->second;
togayan 1:f8713c387a68 83 dat[28] = '0' + val / 10;
togayan 1:f8713c387a68 84 dat[29] = '0' + val % 10;
togayan 1:f8713c387a68 85
togayan 0:86ab67787717 86 m_i2clcd.locate(0, 0);
togayan 1:f8713c387a68 87 m_i2clcd.puts(dat);
togayan 0:86ab67787717 88 }
togayan 0:86ab67787717 89
togayan 1:f8713c387a68 90 void ClockViewModel::setButtonPressed()
togayan 0:86ab67787717 91 {
togayan 1:f8713c387a68 92 m_evHandler->postEvent(new EventMechanism::EventParam0<ClockViewModel>(this, &ClockViewModel::setButtonPressedAsync));
togayan 1:f8713c387a68 93 }
togayan 1:f8713c387a68 94
togayan 1:f8713c387a68 95 void ClockViewModel::setButtonPressedAsync()
togayan 1:f8713c387a68 96 {
togayan 1:f8713c387a68 97 puts("setButtonPressedAsync\n");
togayan 1:f8713c387a68 98 m_led = (m_led == 1)? 0 : 1;
togayan 1:f8713c387a68 99 m_clock->initialize();
togayan 0:86ab67787717 100 }
togayan 0:86ab67787717 101
togayan 1:f8713c387a68 102 void ClockViewModel::selectButtonPressed()
togayan 1:f8713c387a68 103 {
togayan 1:f8713c387a68 104 m_evHandler->postEvent(new EventMechanism::EventParam0<ClockViewModel>(this, &ClockViewModel::selectButtonPressedAsync));
togayan 1:f8713c387a68 105 }
togayan 1:f8713c387a68 106
togayan 1:f8713c387a68 107 void ClockViewModel::selectButtonPressedAsync()
togayan 1:f8713c387a68 108 {
togayan 1:f8713c387a68 109 puts("selectButtonPressedAsync\n");
togayan 1:f8713c387a68 110 m_led = (m_led == 1)? 0 : 1;
togayan 1:f8713c387a68 111 m_clock->initialize();
togayan 1:f8713c387a68 112 }