Skip to content

Commit 4b42e72

Browse files
committed
esp32/modutime: Add time.time() function.
1 parent 3da9d60 commit 4b42e72

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

esp32/modutime.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,21 @@
2828

2929
#include <stdio.h>
3030
#include <string.h>
31+
#include <sys/time.h>
3132

3233
#include "extmod/utime_mphal.h"
3334

35+
STATIC mp_obj_t time_time(void) {
36+
struct timeval tv;
37+
gettimeofday(&tv, NULL);
38+
return mp_obj_new_int(tv.tv_sec);
39+
}
40+
MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time);
41+
3442
STATIC const mp_rom_map_elem_t time_module_globals_table[] = {
3543
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime) },
3644

45+
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) },
3746
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj) },
3847
{ MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj) },
3948
{ MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj) },

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy