1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 04:52:59 +01:00

phydat: add verbose unit_to_str function

This commit is contained in:
Hauke Petersen 2017-06-26 14:44:38 +02:00
parent 7764754686
commit 3e4229cd31
2 changed files with 31 additions and 0 deletions

View File

@ -35,6 +35,7 @@
#ifndef PHYDAT_H
#define PHYDAT_H
#include <stddef.h>
#include <stdint.h>
#include "kernel_defines.h"
@ -179,6 +180,23 @@ void phydat_dump(phydat_t *data, uint8_t dim);
*/
const char *phydat_unit_to_str(uint8_t unit);
/**
* @brief Return a string representation for every unit, including
* non-physical units like 'none' or 'time'
*
* This function is useful when converting phydat_t structures to non-binary
* representations like JSON or XML.
*
* In practice, this function extends phydat_unit_to_str() with additional
* identifiers for non physical units.
*
* @param[in] unit unit to convert
*
* @return string representation of given unit
* @return empty string ("") if unit was not recognized
*/
const char *phydat_unit_to_str_verbose(uint8_t unit);
/**
* @brief Convert the given scale factor to an SI prefix
*

View File

@ -133,6 +133,19 @@ const char *phydat_unit_to_str(uint8_t unit)
}
}
const char *phydat_unit_to_str_verbose(uint8_t unit)
{
switch (unit) {
case UNIT_UNDEF: return "undefined";
case UNIT_NONE: /* fall through */
case UNIT_BOOL:
return "none";
case UNIT_TIME: return "time";
case UNIT_DATE: return "date";
default: return phydat_unit_to_str(unit);
}
}
char phydat_prefix_from_scale(int8_t scale)
{
switch (scale) {