Skip to content

Commit

Permalink
sys: add pseudomodule scanf_float
Browse files Browse the repository at this point in the history
To read float number from stdin, add "-u scanf_float"
option to the linker.
This option is setup using a pseudomodule as it is already done for
printf_float.
Just add to your Makefile:
USEMODULE += scanf_float

Signed-off-by: Gilles DOFFE <g.doffe@gmail.com>
  • Loading branch information
gdoffe committed May 28, 2019
1 parent 1dc479d commit 7fc3207
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions makefiles/pseudomodules.inc.mk
Expand Up @@ -65,6 +65,7 @@ PSEUDOMODULES += saul_adc
PSEUDOMODULES += saul_default
PSEUDOMODULES += saul_gpio
PSEUDOMODULES += saul_nrf_temperature
PSEUDOMODULES += scanf_float
PSEUDOMODULES += schedstatistics
PSEUDOMODULES += sock
PSEUDOMODULES += sock_ip
Expand Down
6 changes: 6 additions & 0 deletions sys/Makefile.include
Expand Up @@ -77,6 +77,12 @@ ifneq (,$(filter printf_float,$(USEMODULE)))
endif
endif

ifneq (,$(filter scanf_float,$(USEMODULE)))
ifeq (1,$(USE_NANO_SPECS))
export LINKFLAGS += -u _scanf_float
endif
endif

ifneq (,$(filter riotboot,$(FEATURES_USED)))
include $(RIOTBASE)/sys/riotboot/Makefile.include
endif
Expand Down

6 comments on commit 7fc3207

@zpw199062
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,gdoffe

Thank you first for the efforts solving this problem . And I tried to use the Riot-master version that you merged this "float problem" into, and i use it now. I do find that you changed the Make.include part and the pseudomodules.inc.mk which is added the float part. And i then tried the suggestion that adding USEMODULE += scanf_float in Makefile. It is built and flashed successfully, but when i run it. I still cannot see any float number. You can see the picture below.
image

And i want to show you my code for this part.
image
image

you can see that i defined the variable speed float type and try to print it ,but it still cannot work. Could you pls help me find the reason why?

Thanks so much!
Best regard!
By Peiwen

@aabadie
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to use float values with printf, you also need to add the printf_float module to your application.

@zpw199062
Copy link

@zpw199062 zpw199062 commented on 7fc3207 Jun 19, 2019 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aabadie
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean we should use printf_float instead of print if we want to print float?

No, I said add USEMODULE += printf_float to your application the same you did with scanf_float module. There are already plenty applications doing this in RIOT codebase (try git grep printf_float). But in a word, use USEMODULE += scanf_float printf_floatand you'll be able to useprintfandscanf` with floating point values.

One last thing: as already pointed out by @kaspar030, don't comment in closed PRs for a usage question but rather send an email to devel@riot-os.org or users@riot-os.org mailnig lists.

@zpw199062
Copy link

@zpw199062 zpw199062 commented on 7fc3207 Jun 19, 2019 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zpw199062
Copy link

@zpw199062 zpw199062 commented on 7fc3207 Jun 19, 2019 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.