Home | History | Annotate | Download | only in using_double_on_avr
      1 /* Decodes a double value into a float variable.
      2  * Used to read double values with AVR code, which doesn't support double directly.
      3  */
      4 
      5 #include <stdio.h>
      6 #include <pb_decode.h>
      7 #include "double_conversion.h"
      8 #include "doubleproto.pb.h"
      9 
     10 int main()
     11 {
     12     uint8_t buffer[32];
     13     size_t count = fread(buffer, 1, sizeof(buffer), stdin);
     14     pb_istream_t stream = pb_istream_from_buffer(buffer, count);
     15 
     16     AVRDoubleMessage message;
     17     pb_decode(&stream, AVRDoubleMessage_fields, &message);
     18 
     19     float v1 = double_to_float(message.field1);
     20     float v2 = double_to_float(message.field2);
     21 
     22     printf("Values: %f %f\n", v1, v2);
     23 
     24     if (v1 == 1234.5678f &&
     25         v2 == 0.00001f)
     26     {
     27         return 0;
     28     }
     29     else
     30     {
     31         return 1;
     32     }
     33 }
     34