fixes contiki-ng/contiki-ng#768 simplelink opt3001 wrong value

This commit is contained in:
firmwareguru 2019-01-14 19:35:12 -07:00
parent 284b52c8b6
commit 8203abb2e7

View File

@ -303,9 +303,13 @@ value(int type)
result_value = SWAP16(result_value); result_value = SWAP16(result_value);
uint32_t e = (result_value & 0x0FFF) >> 0; /* formula for computing lux: lux = 0.01 * 2^e * m
uint32_t m = (result_value & 0xF000) >> 12; * scale up by 100 to avoid floating point, then require
uint32_t converted = m * 100 * (1 << e); * users to scale down by same.
*/
uint32_t m = (result_value & 0x0FFF) >> 0;
uint32_t e = (result_value & 0xF000) >> 12;
uint32_t converted = m * (1 << e);
PRINTF("OPT: %04X r=%d (centilux)\n", result_value, PRINTF("OPT: %04X r=%d (centilux)\n", result_value,
(int)(converted)); (int)(converted));