From b21593f245e1e08d20269707d74e922dd3616c25 Mon Sep 17 00:00:00 2001 From: chibiegg Date: Fri, 16 Nov 2018 11:28:48 +0900 Subject: [PATCH] Check sizeof(double) --- README.md | 2 ++ src/SakuraIO.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/README.md b/README.md index a40e9b1..49ade0a 100644 --- a/README.md +++ b/README.md @@ -167,7 +167,9 @@ Please see example code. * [Shell](./examples/Shell/Shell.ino) * [Send illminance (CdS)](./examples/CdS/CdS.ino) +# Notes +* On the Uno and other ATMEGA based boards, Values ​​of type double are sent as float type. (Please see [Arduino Reference]( https://www.arduino.cc/reference/en/language/variables/data-types/double/).) # License diff --git a/src/SakuraIO.cpp b/src/SakuraIO.cpp index 7cfa567..1bdf8f3 100644 --- a/src/SakuraIO.cpp +++ b/src/SakuraIO.cpp @@ -164,6 +164,18 @@ uint8_t SakuraIO::enqueueTx(uint8_t ch, float value, uint64_t offset){ } uint8_t SakuraIO::enqueueTx(uint8_t ch, double value, uint64_t offset){ + + // check sizeof(double) + // + // On the Uno and other ATMEGA based boards, + // this occupies 4 bytes. That is, the double + // implementation is exactly the same as the float, + // with no gain in precision. + // https://www.arduino.cc/reference/en/language/variables/data-types/double/ + if (sizeof(double) == 4){ + return enqueueTx(ch, (float)value, offset); + } + return enqueueTxRaw(ch, 'd', 8, (uint8_t *)&value, offset); }