From 1ab3c4995e44f44a845dce7b241554c0621527b9 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 3 May 2022 21:25:44 -0700 Subject: web: use generic JS function for updating opt elems --- web/web_opts.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'web/web_opts.c') diff --git a/web/web_opts.c b/web/web_opts.c index 0f37bba..945909f 100644 --- a/web/web_opts.c +++ b/web/web_opts.c @@ -3,6 +3,8 @@ #include "comp.h" #include +#include +#include #include @@ -11,8 +13,21 @@ int delay_ms = 1000; void opts_init() { EM_ASM(readOpts()); - EM_ASM({updateDelay($0)}, delay_ms); - EM_ASM({updateStdev($0)}, horizontal_stdev); + + char buf[64]; + sprintf(buf, "%d", delay_ms); + EM_ASM({elemSetValue($0, $1)}, "#delay", buf); + + int len = sprintf(buf, "%4.2f", horizontal_stdev); + char *dot = strchr(buf, '.'); + if (dot) { + for (char *ptr = buf + len - 1; ptr >= dot; --ptr) { + if (*ptr != '0' && *ptr != '.') + break; + *ptr = 0; + } + } + EM_ASM({elemSetValue($0, $1)}, "#stdev", buf); } EMSCRIPTEN_KEEPALIVE -- cgit v1.2.3-70-g09d2