Skip to content

Commit

Permalink
Fix value sign in mgos_ade7953_get_pf()
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Hinkov committed Feb 24, 2021
1 parent cdd929d commit e1fe93f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/mgos_ade7953.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,9 @@ bool mgos_ade7953_get_pf(struct mgos_ade7953 *dev, int channel, float *pf) {
if (!mgos_ade7953_read_reg(dev, reg, true, &val)) {
return false;
}
val &= 0x0000FFFF;
// bit 16 of val determines the sign, bits [0:15] represent the absolute part
// bit 31 of val determines the sign, bits [0:30] represent the absolute part
// 2^-15 = 0.000030518
*pf = (val & 0x8000) ? /*negative sign*/ -((val & ~0x8000) * 0.000030518) : /*positive sign*/ (val * 0.000030518);
*pf = (val & (1 << 31)) ? /*negative sign*/ -((val & ~(1 << 31)) * 0.000030518) : /*positive sign*/ (val * 0.000030518);
return true;
}

Expand Down

0 comments on commit e1fe93f

Please sign in to comment.