File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -164,8 +164,9 @@ const char *phydat_unit_to_str(uint8_t unit);
164164 * etc) otherwise.
165165 *
166166 * @param[in] scale scale factor to convert
167+ * @param[in] unit unit related to scale
167168 */
168- char phydat_scale_to_str (int8_t scale );
169+ char phydat_scale_to_str (int8_t scale , uint8_t unit );
169170
170171#ifdef __cplusplus
171172}
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ void phydat_dump(phydat_t *data, uint8_t dim)
3232 }
3333 printf ("Data:" );
3434 for (uint8_t i = 0 ; i < dim ; i ++ ) {
35- char scale_str = phydat_scale_to_str (data -> scale );
35+ char scale_str = phydat_scale_to_str (data -> scale , data -> unit );
3636
3737 printf ("\t[%i] " , (int )i );
3838
@@ -80,8 +80,28 @@ const char *phydat_unit_to_str(uint8_t unit)
8080 }
8181}
8282
83- char phydat_scale_to_str (int8_t scale )
83+ char phydat_scale_to_str (int8_t scale , uint8_t unit )
8484{
85+ /* extra handling for multi and non dimensional units */
86+ switch (unit ) {
87+ case UNIT_M2 : /* rescale for 2d unit */
88+ if (scale % 2 != 0 ) {
89+ return '\0' ;
90+ }
91+ scale /= 2 ;
92+ break ;
93+ case UNIT_M3 : /* rescale for 3d unit */
94+ if (scale % 3 != 0 ) {
95+ return '\0' ;
96+ }
97+ scale /= 3 ;
98+ break ;
99+ case UNIT_UNDEF :
100+ case UNIT_NONE :
101+ case UNIT_PERCENT :
102+ return '\0' ; /* no scaling */
103+ }
104+
85105 switch (scale ) {
86106 case -3 : return 'm' ;
87107 case -6 : return 'u' ;
You can’t perform that action at this time.
0 commit comments