Home | History | Annotate | Download | only in using_double_on_avr
      1 /* Encodes a float value into a double on the wire.
      2  * Used to emit doubles from AVR code, which doesn't support double directly.
      3  */
      4 
      5 #include <stdio.h>
      6 #include <pb_encode.h>
      7 #include "double_conversion.h"
      8 #include "doubleproto.pb.h"
      9 
     10 int main()
     11 {
     12     AVRDoubleMessage message = {
     13         float_to_double(1234.5678f),
     14         float_to_double(0.00001f)
     15     };
     16 
     17     uint8_t buffer[32];
     18     pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
     19 
     20     pb_encode(&stream, AVRDoubleMessage_fields, &message);
     21     fwrite(buffer, 1, stream.bytes_written, stdout);
     22 
     23     return 0;
     24 }
     25 
     26