From 2aca6c64ab5f5b0e8a2255413d4845abee2ba34b Mon Sep 17 00:00:00 2001 From: Jason Short Date: Sat, 21 Apr 2012 15:17:09 -0700 Subject: [PATCH] Added a union for casting floats to ints and back when storing Floats to the DataFlash --- ArduCopter/ArduCopter.pde | 6 ++++++ ArduCopter/Log.pde | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/ArduCopter/ArduCopter.pde b/ArduCopter/ArduCopter.pde index 843d034bea..a71f252727 100644 --- a/ArduCopter/ArduCopter.pde +++ b/ArduCopter/ArduCopter.pde @@ -488,6 +488,12 @@ static const float radius_of_earth = 6378100; // meters // Used by Mavlink for unknow reasons static const float gravity = 9.81; // meters/ sec^2 +// Unions for getting byte values +union float_int{ + int32_t int_value; + float float_value; +} float_int; + //////////////////////////////////////////////////////////////////////////////// // Location & Navigation diff --git a/ArduCopter/Log.pde b/ArduCopter/Log.pde index 0a0b350168..c26a3de017 100644 --- a/ArduCopter/Log.pde +++ b/ArduCopter/Log.pde @@ -43,6 +43,19 @@ const struct Menu::command log_menu_commands[] PROGMEM = { {"disable", select_logs} }; +static int32_t get_int(float f) +{ + float_int.float_value = f; + return float_int.int_value; +} + +static float get_float(int32_t i) +{ + float_int.int_value = i; + return float_int.float_value; +} + + // A Macro to create the Menu MENU2(log_menu, "Log", log_menu_commands, print_log_menu);