From e4b55179d1f53c42916f5e62fb83789973bf4b01 Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Tue, 29 Jan 2013 22:10:37 +0200 Subject: Add an example of handling doubles on AVR platform. --- example_avr_double/encode_double.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 example_avr_double/encode_double.c (limited to 'example_avr_double/encode_double.c') diff --git a/example_avr_double/encode_double.c b/example_avr_double/encode_double.c new file mode 100644 index 0000000..cd532d4 --- /dev/null +++ b/example_avr_double/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 +#include +#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; +} + -- cgit