Skip to content

Commit

Permalink
fix sign error for strength
Browse files Browse the repository at this point in the history
  • Loading branch information
wrongsyntax committed Feb 8, 2025
1 parent 76a6400 commit f8b7085
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/modules/autopilot/altimeter.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,9 @@ def measure(self) -> List[Dict[str, Tuple[float, float]]]:
strength = self._read_register(self.REG_PEAK0_STRENGTH + i)

if distance is not None and strength is not None:
# Convert strength from 32-bit signed to regular int
if strength & 0x80000000:
strength = -((~strength + 1) & 0xFFFFFFFF)
# Convert strength from 32-bit unsigned to signed int
if strength > 0x7FFFFFFF:
strength = -int(0x100000000 - strength)

self.distance_avg.add(distance)
self.strength_avg.add(strength)
Expand All @@ -332,7 +332,7 @@ def measure(self) -> List[Dict[str, Tuple[float, float]]]:


def main():
sensor = XM125(average_window=10)
sensor = XM125(average_window=5)

try:
if not sensor.begin():
Expand Down

0 comments on commit f8b7085

Please sign in to comment.