8000 rp2/machine_rtc: Check return value from rtc_set_alarm. · kadamski/micropython@aec645a · GitHub
[go: up one dir, main page]

Skip to content

Commit aec645a

Browse files
committed
rp2/machine_rtc: Check return value from rtc_set_alarm.
The rtc_set_datetime() from pico-sdk will validate the values in the datetime_t structure and refuse to set the time if they aren't valid. It makes sense to raise an exception if this happens instead of failing silently which might be confusing (as an example, see: micropython#6928 (comment) ).
1 parent 66115a3 commit aec645a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

ports/rp2/machine_rtc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ STATIC mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) {
8686

8787
return mp_obj_new_tuple(8, tuple);
8888
} else {
89+
bool ret;
8990
mp_obj_t *items;
9091

9192
mp_obj_get_array_fixed_n(args[1], 8, &items);
@@ -100,7 +101,10 @@ STATIC mp_obj_t machine_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) {
100101
.sec = mp_obj_get_int(items[6]),
101102
};
102103

103-
rtc_set_datetime(&t);
104+
ret = rtc_set_datetime(&t);
105+
if (!ret) {
106+
mp_raise_OSError(MP_EINVAL);
107+
}
104108

105109
}
106110
return mp_const_none;

0 commit comments

Comments
 (0)
0