Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed
- Cmake when not using ESP-IDF ([#11](https://github.com/tuupola/bm8563/pull/11))
- BM8563_ALARM_SET confused mday and wday ([#14](https://github.com/tuupola/bm8563/issues/14), [#15](https://github.com/tuupola/bm8563/pull/15))

### Added
- Support for reading and writing timers ([#8](https://github.com/tuupola/bm8563/pull/8)).
Expand Down
2 changes: 1 addition & 1 deletion bm8563.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ bm8563_ioctl(const bm8563_t *bm, int16_t command, void *buffer)
}

/* 0..6 */
if (BM8563_ALARM_NONE == time->tm_mday) {
if (BM8563_ALARM_NONE == time->tm_wday) {
data[3] = BM8563_ALARM_DISABLE;
} else {
data[3] = decimal2bcd(time->tm_wday);
Expand Down
29 changes: 29 additions & 0 deletions tests/unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,34 @@ should_read_and_write_control_status2(void)
PASS();
}

TEST
bug_14_should_set_alarm_weekday(void)
{
struct tm datetime = {0};
struct tm datetime2 = {0};
bm8563_t bm;
bm.read = &mock_i2c_read;
bm.write = &mock_i2c_write;

/* Set weekday alarm enabled but mday alarm disabled. */
/* This tests that weekday uses tm_wday, not tm_mday. */
datetime.tm_min = BM8563_ALARM_NONE;
datetime.tm_hour = BM8563_ALARM_NONE;
datetime.tm_mday = BM8563_ALARM_NONE;
datetime.tm_wday = 3;

ASSERT(BM8563_OK == bm8563_init(&bm));
ASSERT(BM8563_OK == bm8563_ioctl(&bm, BM8563_ALARM_SET, &datetime));
ASSERT(BM8563_OK == bm8563_ioctl(&bm, BM8563_ALARM_READ, &datetime2));

/* Weekday should be 3, not disabled. */
ASSERT_EQ(datetime.tm_wday, datetime2.tm_wday);
/* mday should be disabled (ALARM_NONE). */
ASSERT_EQ(BM8563_ALARM_NONE, datetime2.tm_mday);

PASS();
}

GREATEST_MAIN_DEFS();

int
Expand Down Expand Up @@ -459,5 +487,6 @@ main(int argc, char **argv)
RUN_TEST(should_fail_write_time);
RUN_TEST(should_read_and_write_control_status1);
RUN_TEST(should_read_and_write_control_status2);
RUN_TEST(bug_14_should_set_alarm_weekday);
GREATEST_MAIN_END();
}