summaryrefslogtreecommitdiffstats
path: root/examples/using_double_on_avr/encode_double.c
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-09-13 12:59:31 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-09-13 12:59:31 +0300
commitf47410ea4b8ae43e19facd378be4cf1073e1813b (patch)
tree53fdc4bac6615f07e830d7d538c90abbea1ead4b /examples/using_double_on_avr/encode_double.c
parentfd9a79a06db00c6199a5dcaee22ed2cd8e3c3e9b (diff)
Move examples into subfolders, add READMEs
Diffstat (limited to 'examples/using_double_on_avr/encode_double.c')
-rw-r--r--examples/using_double_on_avr/encode_double.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/using_double_on_avr/encode_double.c b/examples/using_double_on_avr/encode_double.c
new file mode 100644
index 00000000..cd532d46
--- /dev/null
+++ b/examples/using_double_on_avr/encode_double.c
@@ -0,0 +1,25 @@
+/* Encodes a float value into a double on the wire.
+ * Used to emit doubles from AVR code, which doesn't support double directly.
+ */
+
+#include <stdio.h>
+#include <pb_encode.h>
+#include "double_conversion.h"
+#include "doubleproto.pb.h"
+
+int main()
+{
+ AVRDoubleMessage message = {
+ float_to_double(1234.5678f),
+ float_to_double(0.00001f)
+ };
+
+ uint8_t buffer[32];
+ pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
+
+ pb_encode(&stream, AVRDoubleMessage_fields, &message);
+ fwrite(buffer, 1, stream.bytes_written, stdout);
+
+ return 0;
+}
+