Skip to content

Update RTC sketch after enum changed #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/NonReg/RTC/RTC_Tests/RTC_Config.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

void rtc_config(STM32RTC::RTC_Source_Clock source, STM32RTC::RTC_Hour_Format format, const char* date, const char* time) {
void rtc_config(STM32RTC::Source_Clock source, STM32RTC::Hour_Format format, const char* date, const char* time) {
if (!IS_CLOCK_SOURCE(source)) {
Serial.println("Wrong clock source");
return;
Expand Down
44 changes: 22 additions & 22 deletions examples/NonReg/RTC/RTC_Tests/RTC_Tests.ino
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ static byte day = 0;
static byte month = 0;
static byte year = 0;

static STM32RTC::RTC_Hour_Format hourFormat = STM32RTC::RTC_HOUR_24;
static STM32RTC::RTC_AM_PM period = STM32RTC::RTC_AM;
static STM32RTC::Hour_Format hourFormat = STM32RTC::HOUR_24;
static STM32RTC::AM_PM period = STM32RTC::AM;

#ifndef STM32F1xx
static STM32RTC::Alarm_Match SS_MATCH = STM32RTC::MATCH_SS;
Expand All @@ -70,13 +70,13 @@ void setup()
void loop()
{
int c; // Serial input
STM32RTC::RTC_Source_Clock clkSource = rtc.RTC_LSI_CLOCK;
STM32RTC::Source_Clock clkSource = rtc.LSI_CLOCK;

// Select RTC clock source: RTC_LSI_CLOCK, RTC_LSE_CLOCK or RTC_HSE_CLOCK.
// Select RTC clock source: LSI_CLOCK, LSE_CLOCK or HSE_CLOCK.
Serial.println("Select clock Source:");
Serial.println("1- RTC_LSI_CLOCK");
Serial.println("2- RTC_LSE_CLOCK");
Serial.println("3- RTC_HSE_CLOCK");
Serial.println("1- LSI_CLOCK");
Serial.println("2- LSE_CLOCK");
Serial.println("3- HSE_CLOCK");
Serial.println();
// get input
while (1) {
Expand All @@ -91,16 +91,16 @@ void loop()
switch(c) {
case '1':
default:
Serial.println("Test will use RTC_LSI_CLOCK");
clkSource = rtc.RTC_LSI_CLOCK;
Serial.println("Test will use LSI_CLOCK");
clkSource = rtc.LSI_CLOCK;
break;
case '2':
Serial.println("Test will use RTC_LSE_CLOCK");
clkSource = rtc.RTC_LSE_CLOCK;
Serial.println("Test will use LSE_CLOCK");
clkSource = rtc.LSE_CLOCK;
break;
case '3':
Serial.println("Test will use RTC_HSE_CLOCK");
clkSource = rtc.RTC_HSE_CLOCK;
Serial.println("Test will use HSE_CLOCK");
clkSource = rtc.HSE_CLOCK;
break;
}
break;
Expand All @@ -112,46 +112,46 @@ void loop()
rtc.getPrediv(&a, &s);
Serial.print("Async/Sync for default LSI clock: ");
Serial.print(a); Serial.print('/'); Serial.println(s);
rtc_config(clkSource, rtc.RTC_HOUR_24, mydate, mytime);
rtc_config(clkSource, rtc.HOUR_24, mydate, mytime);
Serial.print("Async/Sync for selected clock: ");
rtc.getPrediv(&a, &s);
Serial.print(a); Serial.print('/'); Serial.println(s);
rtc.end();

if(clkSource == rtc.RTC_HSE_CLOCK) {
if(clkSource == rtc.HSE_CLOCK) {
Serial.print("User Async/Sync set to ");
Serial.print(userPredA);
Serial.print("/");
Serial.print(userPredS);
Serial.print(": ");
rtc.setPrediv(userPredA, userPredS);
rtc_config(clkSource, rtc.RTC_HOUR_24, mydate, mytime);
rtc_config(clkSource, rtc.HOUR_24, mydate, mytime);
rtc.getPrediv(&a, &s);
Serial.print(a); Serial.print('/'); Serial.println(s);
printDateTime(10, 1000, false);
}

Serial.print("User Async/Sync reset use the computed one: ");
rtc.setPrediv(-1, -1);
rtc_config(clkSource, rtc.RTC_HOUR_24, mydate, mytime);
rtc_config(clkSource, rtc.HOUR_24, mydate, mytime);
rtc.getPrediv(&a, &s);
Serial.print(a); Serial.print('/'); Serial.println(s);

// Check date change
Serial.println("Testing date and time");
Serial.println("24H format, new year");
rtc_config(clkSource, rtc.RTC_HOUR_24, "Dec 31 2017", "23:59:56");
rtc_config(clkSource, rtc.HOUR_24, "Dec 31 2017", "23:59:56");
printDateTime(8, 1000, false);
Serial.println();

#ifndef STM32F1xx
Serial.println("12H format, new year");
rtc_config(clkSource, rtc.RTC_HOUR_12, "Dec 31 2017", "23:59:56");
rtc_config(clkSource, rtc.HOUR_12, "Dec 31 2017", "23:59:56");
printDateTime(8, 1000, false);
Serial.println();

Serial.println("12H format, from AM to PM");
rtc_config(clkSource, rtc.RTC_HOUR_12, "Dec 31 2017", "11:59:56");
rtc_config(clkSource, rtc.HOUR_12, "Dec 31 2017", "11:59:56");
printDateTime(8, 1000, false);
Serial.println();
#endif //STM32F1xx
Expand All @@ -167,7 +167,7 @@ void loop()
}

Serial.println("\nTesting alarm");
rtc_config(clkSource, rtc.RTC_HOUR_24, mydate, mytime);
rtc_config(clkSource, rtc.HOUR_24, mydate, mytime);
byte alarmSeconds = ((seconds+5)<60) ? seconds+5 : 5;
byte alarmMinutes = ((seconds+5)<60) ? minutes : ((minutes+1)<60) ? minutes+1 : 0;
byte alarmHours = ((seconds+5)<60) ? hours : ((minutes+1)<60) ? hours : ((hours+1)<24) ? hours+1 : 0;
Expand Down Expand Up @@ -210,7 +210,7 @@ void loop()
rtc.disableAlarm();
rtc.detachInterrupt();

rtc_config(clkSource, rtc.RTC_HOUR_24, mydate, mytime);
rtc_config(clkSource, rtc.HOUR_24, mydate, mytime);
Serial.println("\nAlarm disabled. Printing each 10s.");
printDateTime(-1, 10000, false);
}
Expand Down
12 changes: 6 additions & 6 deletions examples/NonReg/RTC/RTC_Tests/RTC_utils.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ void initDateTime (const char* date, const char* time) {
}
day = conv2d(date + 4);
hours = conv2d(time);
if (hourFormat == rtc.RTC_HOUR_12) {
period = hours >= 12 ? rtc.RTC_PM : rtc.RTC_AM;
if (hourFormat == rtc.HOUR_12) {
period = hours >= 12 ? rtc.PM : rtc.AM;
hours = hours >= 13 ? hours - 12 : (hours < 1 ? hours + 12 : hours);
}
minutes = conv2d(time + 3);
Expand All @@ -56,8 +56,8 @@ void printDateTime(uint32_t t, uint32_t d, bool a) {
print2digits(rtc.getMinutes());
Serial.print(":");
print2digits(rtc.getSeconds());
if (hourFormat == rtc.RTC_HOUR_12) {
Serial.print(period == rtc.RTC_AM ? " AM":" PM");
if (hourFormat == rtc.HOUR_12) {
Serial.print(period == rtc.AM ? " AM":" PM");
}
if(a) {
// Print day...
Expand All @@ -71,8 +71,8 @@ void printDateTime(uint32_t t, uint32_t d, bool a) {
print2digits(rtc.getAlarmMinutes());
Serial.print(":");
print2digits(rtc.getAlarmSeconds());
if (hourFormat == rtc.RTC_HOUR_12) {
Serial.print(period == rtc.RTC_AM ? " AM":" PM");
if (hourFormat == rtc.HOUR_12) {
Serial.print(period == rtc.AM ? " AM":" PM");
}
}
Serial.println();
Expand Down