Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
fix float precision issue on hm310t driver
Browse files Browse the repository at this point in the history
  • Loading branch information
XdoctorwhoZ committed Sep 8, 2023
1 parent cdd6c6e commit dfa0204
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ async def _PZA_DRV_BPC_read_voltage_value(self):

async def _PZA_DRV_BPC_write_voltage_value(self, v):
addr = 0x0030
int16_value = int(v * 100)
self.log.info(f"write value voltage addr={hex(addr)} valuex100={int16_value}")
int16_value = int(round(v * 100)) # Do not let 'int' cast round the result for you
self.log.info(f"write voltage value={v} addr={hex(addr)} valuex100={int16_value}")
await self.modbus.write_register(addr, int16_value, self.modbus_unit)

# ---
Expand All @@ -114,7 +114,7 @@ async def _PZA_DRV_BPC_read_current_value(self):

async def _PZA_DRV_BPC_write_current_value(self, v):
addr = 0x0031
int16_value = int(v * 1000.0)
int16_value = int(round(v * 1000.0))
self.log.info(f"write value current addr={hex(addr)} valuex1000={int16_value}")
await self.modbus.write_register(addr, int16_value, self.modbus_unit)

Expand Down

0 comments on commit dfa0204

Please sign in to comment.