Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
François Revol
firmware
Commits
b4641dde
Commit
b4641dde
authored
Oct 04, 2019
by
dx
Browse files
Merge 'add set_time_ms and set_unix_time_ms'
See merge request
card10/firmware!289
parents
1631a288
76a079ba
Changes
2
Hide whitespace changes
Inline
Side-by-side
pycardium/modules/qstrdefs.h
View file @
b4641dde
...
...
@@ -55,7 +55,9 @@ Q(time_ms)
Q
(
unix_time
)
Q
(
unix_time_ms
)
Q
(
set_time
)
Q
(
set_time_ms
)
Q
(
set_unix_time
)
Q
(
set_unix_time_ms
)
/* vibra */
Q
(
vibra
)
...
...
pycardium/modules/utime.c
View file @
b4641dde
...
...
@@ -5,6 +5,7 @@
#include
"py/mpconfig.h"
#include
"py/obj.h"
#include
"py/objint.h"
#include
"py/runtime.h"
#include
"extmod/utime_mphal.h"
...
...
@@ -26,6 +27,17 @@ static mp_obj_t time_set_time(mp_obj_t secs)
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
time_set_time_obj
,
time_set_time
);
static
mp_obj_t
time_set_time_ms
(
mp_obj_t
msecs_obj
)
{
uint64_t
msecs
=
0
;
mp_obj_int_to_bytes_impl
(
msecs_obj
,
false
,
8
,
(
byte
*
)
&
msecs
);
uint64_t
timestamp
=
msecs
+
EPOCH_OFFSET
*
1000ULL
-
TZONE_OFFSET
*
1000ULL
;
epic_rtc_set_milliseconds
(
timestamp
);
return
mp_const_none
;
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
time_set_time_ms_obj
,
time_set_time_ms
);
static
mp_obj_t
time_set_unix_time
(
mp_obj_t
secs
)
{
uint64_t
timestamp
=
mp_obj_get_int
(
secs
)
*
1000ULL
;
...
...
@@ -34,6 +46,17 @@ static mp_obj_t time_set_unix_time(mp_obj_t secs)
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
time_set_unix_time_obj
,
time_set_unix_time
);
static
mp_obj_t
time_set_unix_time_ms
(
mp_obj_t
msecs_obj
)
{
uint64_t
timestamp
=
0
;
mp_obj_int_to_bytes_impl
(
msecs_obj
,
false
,
8
,
(
byte
*
)
&
timestamp
);
epic_rtc_set_milliseconds
(
timestamp
);
return
mp_const_none
;
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
time_set_unix_time_ms_obj
,
time_set_unix_time_ms
);
static
mp_obj_t
time_time
(
void
)
{
mp_int_t
seconds
;
...
...
@@ -167,8 +190,11 @@ static const mp_rom_map_elem_t time_module_globals_table[] = {
{
MP_ROM_QSTR
(
MP_QSTR_monotonic_ms
),
MP_ROM_PTR
(
&
time_monotonic_ms_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_set_time
),
MP_ROM_PTR
(
&
time_set_time_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_set_time_ms
),
MP_ROM_PTR
(
&
time_set_time_ms_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_set_unix_time
),
MP_ROM_PTR
(
&
time_set_unix_time_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_set_unix_time_ms
),
MP_ROM_PTR
(
&
time_set_unix_time_ms_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_localtime
),
MP_ROM_PTR
(
&
time_localtime_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_mktime
),
MP_ROM_PTR
(
&
time_mktime_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_sleep
),
MP_ROM_PTR
(
&
mp_utime_sleep_obj
)
},
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment