sandeepmistry / arduino-LoRa

An Arduino library for sending and receiving data using LoRa radios.
MIT License
1.61k stars 621 forks source link

Add `packetSnrRaw` method to avoid floating-point #570

Open ZacJW opened 2 years ago

ZacJW commented 2 years ago

This patch is motivated by a well known (#459, #460) limitation, that ESP microcontrollers can't use float LoRa.packetSnr() in ISR because that method performs a floating point operation.

My proposed solution is to add a method int LoRa.packetSnrRaw() that returns the REG_PKT_SNR_VALUE register as an int unmodified, rather than as a float divided by 4. I've written documentation for it noting that since it forgoes the division by 4, its value is 4 times the actual SNR.

torntrousers commented 2 years ago

Could you use bit shift instead of the division - https://stackoverflow.com/questions/13577174/can-anyone-explain-why-2-shift-means-divided-by-4-in-c-codes?

ZacJW commented 2 years ago

My thought is to leave it up to the user. I would like to keep the full precision of it, but I'd accept the loss of 2 bits.