• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

/home/jgoppert/Projects/ap/libraries/AP_Common/AP_Common.h

Go to the documentation of this file.
00001 // -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*-
00002 //
00003 // This is free software; you can redistribute it and/or modify it under
00004 // the terms of the GNU Lesser General Public License as published by the
00005 // Free Software Foundation; either version 2.1 of the License, or (at
00006 // your option) any later version.
00007 //
00008 
00014 
00015 #ifndef _AP_COMMON_H
00016 #define _AP_COMMON_H
00017 
00018 #include <stdint.h>
00019 #include "include/menu.h"               
00020 #include "c++.h" // c++ additions
00021 #include "AP_Vector.h"
00022 #include "AP_Loop.h"
00023 
00026 
00027 //
00028 // Turn on/off warnings of interest.
00029 //
00030 // These warnings are normally suppressed by the Arduino IDE,
00031 // but with some minor hacks it's possible to have warnings
00032 // emitted.  This helps greatly when diagnosing subtle issues.
00033 //
00034 #pragma GCC diagnostic warning "-Wall"
00035 #pragma GCC diagnostic warning "-Wextra"
00036 #pragma GCC diagnostic warning "-Wlogical-op"
00037 #pragma GCC diagnostic ignored "-Wredundant-decls"
00038 
00039 // Make some dire warnings into errors
00040 //
00041 // Some warnings indicate questionable code; rather than let
00042 // these slide, we force them to become errors so that the
00043 // developer has to find a safer alternative.
00044 //
00045 #pragma GCC diagnostic error "-Wfloat-equal"
00046 
00047 // The following is strictly for type-checking arguments to printf_P calls
00048 // in conjunction with a suitably modified Arduino IDE; never define for
00049 // production as it generates bad code.
00050 //
00051 #if PRINTF_FORMAT_WARNING_DEBUG
00052 # undef PSTR
00053 # define PSTR(_x)               _x              // help the compiler with printf_P
00054 # define float double                   // silence spurious format warnings for %f
00055 #else
00056 // This is a workaround for GCC bug c++/34734.
00057 //
00058 // The C++ compiler normally emits many spurious warnings for the use
00059 // of PSTR (even though it generates correct code).  This workaround
00060 // has an equivalent effect but avoids the warnings, which otherwise
00061 // make finding real issues difficult.
00062 //
00063 # undef PROGMEM 
00064 # define PROGMEM __attribute__(( section(".progmem.data") )) 
00065 # undef PSTR 
00066 # define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); &__c[0];})) 
00067 #endif
00068 
00070 
00076 
00077 
00078 struct Location {
00079         uint8_t         id;                                     
00080         uint8_t         p1;                                     
00081         int32_t         alt;                            
00082         int32_t         lat;                            
00083         int32_t         lng;                            
00084 };
00085 
00091 template  <class type>
00092 class AP_Var
00093 {
00094 public:
00098         AP_Var(const type & data, const char * name = "", const bool & sync=false) : 
00099                 _data(data), _name(name), _sync(sync)
00100         {
00101         }
00102 
00106         void set(const type & val) {
00107                 _data = val; 
00108                 if (_sync) save();
00109         }
00110 
00114         const type & get() {
00115                 if (_sync) load();
00116                 return _data;
00117         }
00118 
00122         void setAsFloat(const float & val) {
00123                 set(val);
00124         }
00125 
00129         const float & getAsFloat() {
00130                 return get();
00131         }
00132 
00133 
00137         virtual void save()
00138         {
00139         }
00140 
00144         virtual void load()
00145         {
00146         }
00147 
00151         const char * getName() { return _name; }
00152 
00157         const bool & getSync() { return _sync; }
00158         void setSync(bool sync) { _sync = sync; }
00159 
00160 protected:
00161         type _data; 
00162         const char * _name; 
00163         bool _sync; 
00164 };
00165 
00167 
00173 
00174 
00177 #define ToDeg(x) (x*57.2957795131)      // *180/pi
00178 
00180 
00181 
00182 #endif // _AP_COMMON_H

Generated for ArduPilot Libraries by doxygen