1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

phydat: Add Tesla unit

While this is equivalent to the existing Gs (1 T = 10^-4 Gs), this is
the SI (and thus preferred) unit.
This commit is contained in:
chrysn 2022-01-25 13:46:08 +01:00
parent fca7ed3943
commit 206bea0a1d
5 changed files with 7 additions and 0 deletions

View File

@ -97,6 +97,7 @@ enum {
UNIT_V, /**< Volts */
UNIT_W, /**< Watt */
UNIT_GS, /**< gauss */
UNIT_T, /**< Tesla */
UNIT_DBM, /**< decibel-milliwatts */
UNIT_COULOMB, /**< coulomb */
UNIT_F, /**< Farad */

View File

@ -114,6 +114,7 @@ const char *phydat_unit_to_str(uint8_t unit)
case UNIT_W: return "W";
case UNIT_DBM: return "dBm";
case UNIT_GS: return "Gs";
case UNIT_T: return "T";
case UNIT_BAR: return "Bar";
case UNIT_PA: return "Pa";
case UNIT_PERMILL: return "permille";

View File

@ -45,6 +45,7 @@ _phydat_test_t _test_vector[] =
{ .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_V, .scale = 6 } },
{ .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_W, .scale = 7 } },
{ .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_GS, .scale = -1 } },
{ .dim = 3, .dat = { .val = { 123, 456, 789 }, .unit = UNIT_T, .scale = -9 } },
{ .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_DBM, .scale = -3 } },
{ .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_COULOMB, .scale = 0 } },
{ .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_F, .scale = -6 } },

View File

@ -44,6 +44,9 @@ def testfunc(child):
child.expect(r'Data:\t 12345 MV\r\n')
child.expect(r'Data:\t 12345e7 W\r\n')
child.expect(r'Data:\t 1234.5 Gs\r\n')
child.expect(r'Data:\t\[0\] 123 nT\r\n')
child.expect(r'\t\[1\] 456 nT\r\n')
child.expect(r'\t\[2\] 789 nT\r\n')
child.expect(r'Data:\t 12.345 dBm\r\n')
child.expect(r'Data:\t 12345 C\r\n')
child.expect(r'Data:\t 12345 uF\r\n')

View File

@ -212,6 +212,7 @@ static void test_unitstr__success(void)
TEST_ASSERT_EQUAL_STRING("W", phydat_unit_to_str_verbose(UNIT_W));
TEST_ASSERT_EQUAL_STRING("dBm", phydat_unit_to_str_verbose(UNIT_DBM));
TEST_ASSERT_EQUAL_STRING("Gs", phydat_unit_to_str_verbose(UNIT_GS));
TEST_ASSERT_EQUAL_STRING("T", phydat_unit_to_str_verbose(UNIT_T));
TEST_ASSERT_EQUAL_STRING("Bar", phydat_unit_to_str_verbose(UNIT_BAR));
TEST_ASSERT_EQUAL_STRING("Pa", phydat_unit_to_str_verbose(UNIT_PA));
TEST_ASSERT_EQUAL_STRING("permille", phydat_unit_to_str_verbose(UNIT_PERMILL));