Skip to content
Snippets Groups Projects
Commit 56f44729 authored by Joakim Nohlgård's avatar Joakim Nohlgård
Browse files

sys/phydat: rename phydat_scale_to_str -> phydat_prefix_from_scale

Correct some outdated documentation and make the name represent what the
function does today.
parent bc9fb40c
No related branches found
No related tags found
No related merge requests found
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#define PHYDAT_H #define PHYDAT_H
#include <stdint.h> #include <stdint.h>
#include <errno.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -157,15 +156,17 @@ void phydat_dump(phydat_t *data, uint8_t dim); ...@@ -157,15 +156,17 @@ void phydat_dump(phydat_t *data, uint8_t dim);
const char *phydat_unit_to_str(uint8_t unit); const char *phydat_unit_to_str(uint8_t unit);
/** /**
* @brief Convert the given scale factor to a NULL terminated string * @brief Convert the given scale factor to an SI prefix
* *
* The given scaling factor will be given as SI unit (e.g. M for Mega, u for * The given scaling factor is returned as a SI unit prefix (e.g. M for Mega, u
* micro, etc) for obvious cases or in scientific notation (e.g. 2E11, 1E-22, * for micro, etc), or `\0` otherwise.
* etc) otherwise.
* *
* @param[in] scale scale factor to convert * @param[in] scale scale factor to convert
*
* @return SI prefix if applicable
* @return `\0` if no SI prefix was found
*/ */
char phydat_scale_to_str(int8_t scale); char phydat_prefix_from_scale(int8_t scale);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -32,7 +32,7 @@ void phydat_dump(phydat_t *data, uint8_t dim) ...@@ -32,7 +32,7 @@ void phydat_dump(phydat_t *data, uint8_t dim)
} }
printf("Data:"); printf("Data:");
for (uint8_t i = 0; i < dim; i++) { for (uint8_t i = 0; i < dim; i++) {
char scale_str; char scale_prefix;
switch (data->unit) { switch (data->unit) {
case UNIT_UNDEF: case UNIT_UNDEF:
...@@ -43,16 +43,16 @@ void phydat_dump(phydat_t *data, uint8_t dim) ...@@ -43,16 +43,16 @@ void phydat_dump(phydat_t *data, uint8_t dim)
case UNIT_TEMP_C: case UNIT_TEMP_C:
case UNIT_TEMP_F: case UNIT_TEMP_F:
/* no string conversion */ /* no string conversion */
scale_str = '\0'; scale_prefix = '\0';
break; break;
default: default:
scale_str = phydat_scale_to_str(data->scale); scale_prefix = phydat_prefix_from_scale(data->scale);
} }
printf("\t[%i] ", (int)i); printf("\t[%i] ", (int)i);
if (scale_str) { if (scale_prefix) {
printf("%i%c", (int)data->val[i], scale_str); printf("%i%c", (int)data->val[i], scale_prefix);
} }
else if (data->scale == 0) { else if (data->scale == 0) {
printf("%i", (int)data->val[i]); printf("%i", (int)data->val[i]);
...@@ -95,7 +95,7 @@ const char *phydat_unit_to_str(uint8_t unit) ...@@ -95,7 +95,7 @@ const char *phydat_unit_to_str(uint8_t unit)
} }
} }
char phydat_scale_to_str(int8_t scale) char phydat_prefix_from_scale(int8_t scale)
{ {
switch (scale) { switch (scale) {
case -3: return 'm'; case -3: return 'm';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment