Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
2a4b7cbc
Commit
2a4b7cbc
authored
9 years ago
by
Hauke Petersen
Browse files
Options
Downloads
Patches
Plain Diff
sys/phydat: dump function can handle fixed floats
parent
95d26d3b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sys/include/phydat.h
+1
-3
1 addition, 3 deletions
sys/include/phydat.h
sys/phydat/phydat_str.c
+34
-20
34 additions, 20 deletions
sys/phydat/phydat_str.c
with
35 additions
and
23 deletions
sys/include/phydat.h
+
1
−
3
View file @
2a4b7cbc
...
@@ -162,10 +162,8 @@ const char *phydat_unit_to_str(uint8_t unit);
...
@@ -162,10 +162,8 @@ const char *phydat_unit_to_str(uint8_t unit);
* etc) otherwise.
* etc) otherwise.
*
*
* @param[in] scale scale factor to convert
* @param[in] scale scale factor to convert
* @param[in] str buffer to write the result into, MUST be at least of
* length @p PHYDAT_SCALE_STR_MAXLEN
*/
*/
void
phydat_scale_to_str
(
int8_t
scale
,
char
*
str
);
char
phydat_scale_to_str
(
int8_t
scale
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
This diff is collapsed.
Click to expand it.
sys/phydat/phydat_str.c
+
34
−
20
View file @
2a4b7cbc
...
@@ -32,10 +32,27 @@ void phydat_dump(phydat_t *data, uint8_t dim)
...
@@ -32,10 +32,27 @@ 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
tmp
[
PHYDAT_SCALE_STR_MAXLEN
];
char
scale_str
=
phydat_scale_to_str
(
data
->
scale
);
phydat_scale_to_str
(
data
->
scale
,
tmp
);
printf
(
"
\t
[%i] %i%s%s
\n
"
,
(
int
)
i
,
(
int
)
data
->
val
[
i
],
tmp
,
printf
(
"
\t
[%i] "
,
(
int
)
i
);
phydat_unit_to_str
(
data
->
unit
));
if
(
scale_str
)
{
printf
(
"%i%c"
,
(
int
)
data
->
val
[
i
],
scale_str
);
}
else
if
(
data
->
scale
==
0
)
{
printf
(
"%i"
,
(
int
)
data
->
val
[
i
]);
}
else
if
((
data
->
scale
>
-
5
)
&&
(
data
->
scale
<
0
))
{
char
num
[
8
];
size_t
len
=
fmt_s16_dfp
(
num
,
data
->
val
[
i
],
data
->
scale
*
-
1
);
num
[
len
]
=
'\0'
;
printf
(
"%s"
,
num
);
}
else
{
printf
(
"%iE%i"
,
(
int
)
data
->
val
[
i
],
(
int
)
data
->
scale
);
}
printf
(
"%s
\n
"
,
phydat_unit_to_str
(
data
->
unit
));
}
}
}
}
...
@@ -55,27 +72,24 @@ const char *phydat_unit_to_str(uint8_t unit)
...
@@ -55,27 +72,24 @@ const char *phydat_unit_to_str(uint8_t unit)
case
UNIT_BAR
:
return
"Bar"
;
case
UNIT_BAR
:
return
"Bar"
;
case
UNIT_PA
:
return
"Pa"
;
case
UNIT_PA
:
return
"Pa"
;
case
UNIT_CD
:
return
"cd"
;
case
UNIT_CD
:
return
"cd"
;
case
UNIT_PERCENT
:
return
"%"
;
default:
return
""
;
default:
return
""
;
}
}
}
}
void
phydat_scale_to_str
(
int8_t
scale
,
char
*
str
)
char
phydat_scale_to_str
(
int8_t
scale
)
{
{
switch
(
scale
)
{
switch
(
scale
)
{
case
0
:
*
str
=
'\0'
;
return
;
case
-
3
:
return
'm'
;
case
-
3
:
*
str
=
'm'
;
break
;
case
-
6
:
return
'u'
;
case
-
6
:
*
str
=
'u'
;
break
;
case
-
9
:
return
'n'
;
case
-
9
:
*
str
=
'n'
;
break
;
case
-
12
:
return
'p'
;
case
-
12
:
*
str
=
'p'
;
break
;
case
-
15
:
return
'f'
;
case
-
15
:
*
str
=
'f'
;
break
;
case
3
:
return
'k'
;
case
3
:
*
str
=
'k'
;
break
;
case
6
:
return
'M'
;
case
6
:
*
str
=
'M'
;
break
;
case
9
:
return
'G'
;
case
9
:
*
str
=
'G'
;
break
;
case
12
:
return
'T'
;
case
12
:
*
str
=
'T'
;
break
;
case
15
:
return
'P'
;
case
15
:
*
str
=
'P'
;
break
;
default:
return
'\0'
;
default:
*
str
++
=
'E'
;
str
+=
fmt_s32_dec
(
str
,
scale
)
-
1
;
}
}
*++
str
=
'\0'
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment