Skip to content

Fix random number generation on ESP8266 #2157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2018
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 targets/esp8266/js/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function sysloop(ticknow) {
blink();
};
print("Random generated number: ", Math.random());
print("main js OK");
2 changes: 1 addition & 1 deletion targets/esp8266/ld/eagle.app.v6.ld
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ MEMORY
dport0_0_seg : org = 0x3FF00000, len = 0x10
dram0_0_seg : org = 0x3FFE8000, len = 0x18000
iram1_0_seg : org = 0x40100000, len = 0x8000
irom0_0_seg : org = 0x40220000, len = 0x6C000
irom0_0_seg : org = 0x40220000, len = 0x7C000
}

INCLUDE ../ld/eagle.app.v6.common.ld
15 changes: 13 additions & 2 deletions targets/esp8266/user/jerry_extapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,20 @@ DELCARE_HANDLER(print) {
printf("%s ", buffer);
free (buffer);
}
else
else if (jerry_value_is_number (args_p[cc]))
{
printf ("(%d) ", args_p[cc]);
double number = jerry_get_number_value (args_p[cc]);
if ((int) number == number)
{
printf ("%d", (int) number);
}
else
{
char buff[50];
sprintf(buff, "%.10f", number);
printf("%s", buff);
}

}
}
printf ("\r\n");
Expand Down
10 changes: 2 additions & 8 deletions targets/esp8266/user/jerry_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,8 @@ jerry_port_fatal (jerry_fatal_code_t code)
double
jerry_port_get_current_time (void)
{
struct timeval tv;

if (gettimeofday (&tv, NULL) != 0)
{
return 0;
}

return ((double) tv.tv_sec) * 1000.0 + ((double) tv.tv_usec) / 1000.0;
uint32_t rtc_time = system_rtc_clock_cali_proc();
return (double) rtc_time;
} /* jerry_port_get_current_time */

/**
Expand Down