Compare commits
5 Commits
f8ee536829
...
example
| Author | SHA1 | Date | |
|---|---|---|---|
| 2147637385 | |||
| 966af1d5cf | |||
| a83671bda5 | |||
| 7e8a6b0dad | |||
| a897b7d9be |
Submodule ds3231/ds3231 updated: 1388412d70...8a6170cb10
@@ -218,6 +218,9 @@
|
|||||||
<Compile Include="clock.hpp">
|
<Compile Include="clock.hpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="ds3231\alarms.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
<Compile Include="ds3231\ds3231.hpp">
|
<Compile Include="ds3231\ds3231.hpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
@@ -64,28 +64,6 @@ static inline void printLocalTime(const rtc::DateTime &dateTime)
|
|||||||
serial << dateTime << (dst ? F(" +2") : F(" +1")) << F("\r\n");
|
serial << dateTime << (dst ? F(" +2") : F(" +1")) << F("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool operator==(const rtc::DateTime &lhs, const rtc::DateTime &rhs)
|
|
||||||
{
|
|
||||||
if (lhs.second != rhs.second)
|
|
||||||
return false;
|
|
||||||
if (lhs.minute != rhs.minute)
|
|
||||||
return false;
|
|
||||||
if (lhs.hour != rhs.hour)
|
|
||||||
return false;
|
|
||||||
if (lhs.day != rhs.day)
|
|
||||||
return false;
|
|
||||||
if (lhs.month != rhs.month)
|
|
||||||
return false;
|
|
||||||
if (lhs.year != rhs.year)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool operator!=(const rtc::DateTime &lhs, const rtc::DateTime &rhs)
|
|
||||||
{
|
|
||||||
return !(lhs == rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline size_t receiveLine(char *buffer, const size_t maxLength)
|
static inline size_t receiveLine(char *buffer, const size_t maxLength)
|
||||||
{
|
{
|
||||||
uart_t serial;
|
uart_t serial;
|
||||||
@@ -148,10 +126,27 @@ int main()
|
|||||||
{
|
{
|
||||||
uart_t serial;
|
uart_t serial;
|
||||||
rtc::DS3231<i2c::Hardware<100'000>, false> ds3231;
|
rtc::DS3231<i2c::Hardware<100'000>, false> ds3231;
|
||||||
|
io::Pin<io::P::C3> rtcPwr;
|
||||||
|
|
||||||
|
rtcPwr = false;
|
||||||
|
rtcPwr.dir(io::Dir::OUT);
|
||||||
|
|
||||||
|
rtcPwr = true;
|
||||||
|
_delay_ms(1000);
|
||||||
|
|
||||||
ds3231.init();
|
ds3231.init();
|
||||||
serial.init();
|
serial.init();
|
||||||
|
|
||||||
|
ds3231.clearAlarm1();
|
||||||
|
ds3231.clearAlarm2();
|
||||||
|
|
||||||
|
rtc::DateTime alarmTime;
|
||||||
|
alarmTime.second = 17;
|
||||||
|
alarmTime.minute = 54;
|
||||||
|
|
||||||
|
ds3231.setAlarm1(alarmTime, rtc::Alarm1Rate::WHEN_S_MATCH);
|
||||||
|
ds3231.setAlarm2(alarmTime, rtc::Alarm2Rate::WHEN_M_MATCH);
|
||||||
|
|
||||||
auto oldDate = ds3231.getDateTime();
|
auto oldDate = ds3231.getDateTime();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -162,12 +157,28 @@ int main()
|
|||||||
printLocalTime(date);
|
printLocalTime(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ds3231.checkAlarm1()) {
|
||||||
|
serial << F("Alarm1!\r\n");
|
||||||
|
ds3231.clearAlarm1();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ds3231.checkAlarm2()) {
|
||||||
|
serial << F("Alarm2!\r\n");
|
||||||
|
ds3231.clearAlarm2();
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t receivedByte;
|
uint8_t receivedByte;
|
||||||
|
|
||||||
if (serial.rxByte(receivedByte)) {
|
if (serial.rxByte(receivedByte)) {
|
||||||
if (receivedByte == 's') {
|
if (receivedByte == 's') {
|
||||||
const auto newDate = receiveTime();
|
const auto newDate = receiveTime();
|
||||||
ds3231.setDateTime(newDate);
|
ds3231.setDateTime(newDate);
|
||||||
|
} else if (receivedByte == '1') {
|
||||||
|
const auto alarm = ds3231.getAlarm1();
|
||||||
|
serial << F("Alarm1: ") << alarm << F("\r\n");
|
||||||
|
} else if (receivedByte == '2') {
|
||||||
|
const auto alarm = ds3231.getAlarm2();
|
||||||
|
serial << F("Alarm2: ") << alarm << F("\r\n");
|
||||||
} else
|
} else
|
||||||
serial << F("Invalid input: ") << static_cast<char>(receivedByte) << F("\r\n");
|
serial << F("Invalid input: ") << static_cast<char>(receivedByte) << F("\r\n");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user