diff options
Diffstat (limited to 'example_avr_double/decode_double.c')
-rw-r--r-- | example_avr_double/decode_double.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/example_avr_double/decode_double.c b/example_avr_double/decode_double.c new file mode 100644 index 00000000..5802eca7 --- /dev/null +++ b/example_avr_double/decode_double.c @@ -0,0 +1,33 @@ +/* Decodes a double value into a float variable. + * Used to read double values with AVR code, which doesn't support double directly. + */ + +#include <stdio.h> +#include <pb_decode.h> +#include "double_conversion.h" +#include "doubleproto.pb.h" + +int main() +{ + uint8_t buffer[32]; + size_t count = fread(buffer, 1, sizeof(buffer), stdin); + pb_istream_t stream = pb_istream_from_buffer(buffer, count); + + AVRDoubleMessage message; + pb_decode(&stream, AVRDoubleMessage_fields, &message); + + float v1 = double_to_float(message.field1); + float v2 = double_to_float(message.field2); + + printf("Values: %f %f\n", v1, v2); + + if (v1 == 1234.5678f && + v2 == 0.00001f) + { + return 0; + } + else + { + return 1; + } +} |