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:
parent
7764754686
commit
3e4229cd31
@ -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
|
||||
*
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user