Skip to content

Commit e1fe93f

Browse files
author
Andrey Hinkov
committed
Fix value sign in mgos_ade7953_get_pf()
1 parent cdd929d commit e1fe93f

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/mgos_ade7953.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,9 @@ bool mgos_ade7953_get_pf(struct mgos_ade7953 *dev, int channel, float *pf) {
244244
if (!mgos_ade7953_read_reg(dev, reg, true, &val)) {
245245
return false;
246246
}
247-
val &= 0x0000FFFF;
248-
// bit 16 of val determines the sign, bits [0:15] represent the absolute part
247+
// bit 31 of val determines the sign, bits [0:30] represent the absolute part
249248
// 2^-15 = 0.000030518
250-
*pf = (val & 0x8000) ? /*negative sign*/ -((val & ~0x8000) * 0.000030518) : /*positive sign*/ (val * 0.000030518);
249+
*pf = (val & (1 << 31)) ? /*negative sign*/ -((val & ~(1 << 31)) * 0.000030518) : /*positive sign*/ (val * 0.000030518);
251250
return true;
252251
}
253252

0 commit comments

Comments
 (0)