[riot-commits] [RIOT-OS/RIOT] fe46ca: sys/phydat: New phydat_fit API

Martine Lenders authmillenon at gmail.com
Thu Oct 25 19:16:55 CEST 2018


  Branch: refs/heads/master
  Home:   https://github.com/RIOT-OS/RIOT
  Commit: fe46cae00dc66cd599da8fe57d43478452987e48
      https://github.com/RIOT-OS/RIOT/commit/fe46cae00dc66cd599da8fe57d43478452987e48
  Author: Marian Buschsieweke <marian.buschsieweke at ovgu.de>
  Date:   2018-10-24 (Wed, 24 Oct 2018)

  Changed paths:
    M sys/include/phydat.h
    M sys/phydat/phydat.c
    M tests/unittests/tests-phydat/tests-phydat.c

  Log Message:
  -----------
  sys/phydat: New phydat_fit API

The current phydat_fit implementation the following limitations:
- The API is way more complicated to use than needed
- It doesn't perform any rounding
- It uses `long` in a place where actual width (or better range) of the type
  is pretty important.

This commit addresses these limitations and uses lookup-tables to reduce the
number of divisions required.

Before this commit code using it looked like this:
``` C
long values[] = { 100000, 2000000, 30000000 };
phydat_t dat = { .scale = 42, .unit = UNIT_V };
phydat_fit(&dat, values[0], 0, phydat_fit(&dat, values[1], 1, phydat_fit(&dat, values[2], 2, 0)));
```

Now it can be used like this:
``` C
int32_t values[] = { 100000, 2000000, 30000000 };
phydat_t dat = { .unit = UNIT_V, .scale = 42 };
phydat_fit(&dat, values, 3);
```


  Commit: 959e4491faaa6a0ef7f089507dd3b791a29715d3
      https://github.com/RIOT-OS/RIOT/commit/959e4491faaa6a0ef7f089507dd3b791a29715d3
  Author: Martine Lenders <authmillenon at gmail.com>
  Date:   2018-10-25 (Thu, 25 Oct 2018)

  Changed paths:
    M sys/include/phydat.h
    M sys/phydat/phydat.c
    M tests/unittests/tests-phydat/tests-phydat.c

  Log Message:
  -----------
  Merge pull request #9702 from maribu/phydat_fit

sys/phydat: New phydat_fit API


Compare: https://github.com/RIOT-OS/RIOT/compare/466bc341a6f5...959e4491faaa
      **NOTE:** This service has been marked for deprecation: https://developer.github.com/changes/2018-04-25-github-services-deprecation/

      Functionality will be removed from GitHub.com on January 31st, 2019.


More information about the commits mailing list