diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2013-01-29 22:10:37 +0200 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2013-01-29 22:10:37 +0200 |
commit | e4b55179d1f53c42916f5e62fb83789973bf4b01 (patch) | |
tree | 4505321c4c14bdca6362b1e1bb1054c3588a4543 /example_avr_double/encode_double.c | |
parent | 2392d255749715ad337d3f5e23d3de7f2065e3dd (diff) |
Add an example of handling doubles on AVR platform.
Diffstat (limited to 'example_avr_double/encode_double.c')
-rw-r--r-- | example_avr_double/encode_double.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/example_avr_double/encode_double.c b/example_avr_double/encode_double.c new file mode 100644 index 00000000..cd532d46 --- /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 <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; +} + |