Select Git revision
string_format_modulo3.py.exp
-
Damien George authored
This patch fixes 2 things when printing a floating-point number that requires rounding up of the mantissa: - retain the correct precision; eg 0.99 becomes 1.0, not 1.00 - if the exponent goes from -1 to 0 then render it as +0, not -0
Damien George authoredThis patch fixes 2 things when printing a floating-point number that requires rounding up of the mantissa: - retain the correct precision; eg 0.99 becomes 1.0, not 1.00 - if the exponent goes from -1 to 0 then render it as +0, not -0
utime.c 4.65 KiB
#include "interrupt.h"
#include "epicardium.h"
#include "mxc_delay.h"
#include "py/mpconfig.h"
#include "py/obj.h"
#include "py/runtime.h"
#include "extmod/utime_mphal.h"
#include <stdint.h>
// Needs to be after the stdint include ...
#include "lib/timeutils/timeutils.h"
/* MicroPython has its epoch at 2000-01-01. Our RTC is in UTC */
#define EPOCH_OFFSET 946684800UL
#define TZONE_OFFSET 7200UL
static mp_obj_t time_set_time(mp_obj_t secs)
{
uint64_t timestamp = mp_obj_get_int(secs) * 1000ULL +
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_obj, time_set_time);
static mp_obj_t time_set_unix_time(mp_obj_t secs)
{
uint64_t timestamp = mp_obj_get_int(secs) * 1000ULL;
epic_rtc_set_milliseconds(timestamp);
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_1(time_set_unix_time_obj, time_set_unix_time);
static mp_obj_t time_time(void)
{
mp_int_t seconds;
seconds = epic_rtc_get_seconds() - EPOCH_OFFSET + TZONE_OFFSET;
return mp_obj_new_int(seconds);
}
MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time);
static mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args)
{
mp_int_t seconds;
if (n_args == 0 || args[0] == mp_const_none) {
seconds = epic_rtc_get_seconds() - EPOCH_OFFSET + TZONE_OFFSET;
} else {
seconds = mp_obj_get_int(args[0]);
}
timeutils_struct_time_t tm;
timeutils_seconds_since_2000_to_struct_time(seconds, &tm);
mp_obj_t tuple[8] = {
tuple[0] = mp_obj_new_int(tm.tm_year),
tuple[1] = mp_obj_new_int(tm.tm_mon),
tuple[2] = mp_obj_new_int(tm.tm_mday),
tuple[3] = mp_obj_new_int(tm.tm_hour),
tuple[4] = mp_obj_new_int(tm.tm_min),
tuple[5] = mp_obj_new_int(tm.tm_sec),
tuple[6] = mp_obj_new_int(tm.tm_wday),
tuple[7] = mp_obj_new_int(tm.tm_yday),
};
return mp_obj_new_tuple(8, tuple);
}
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
time_localtime_obj, 0, 1, time_localtime