AP_Param: add singleton

This commit is contained in:
Peter Hall 2019-11-25 16:21:31 +00:00 committed by Andrew Tridgell
parent b81aa05622
commit 623c1aa3cd
2 changed files with 24 additions and 0 deletions

View File

@ -38,6 +38,9 @@ extern const AP_HAL::HAL &hal;
uint16_t AP_Param::sentinal_offset;
// singleton instance
AP_Param *AP_Param::_singleton;
#define ENABLE_DEBUG 1
#if ENABLE_DEBUG
@ -379,6 +382,14 @@ bool AP_Param::get_base(const struct Info &info, ptrdiff_t &base)
return true;
}
namespace AP {
AP_Param *param()
{
return AP_Param::get_singleton();
}
}
// find the info structure given a header and a group_info table
// return the Info structure and a pointer to the variables storage

View File

@ -197,6 +197,11 @@ public:
uint16_t i;
for (i=0; info[i].type != AP_PARAM_NONE; i++) ;
_num_vars = i;
if (_singleton != nullptr) {
AP_HAL::panic("AP_Param must be singleton");
}
_singleton = this;
}
// empty constructor
@ -479,7 +484,11 @@ public:
AP_HAL::BetterStream *port);
#endif // AP_PARAM_KEY_DUMP
static AP_Param *get_singleton() { return _singleton; }
private:
static AP_Param *_singleton;
/// EEPROM header
///
/// This structure is placed at the head of the EEPROM to indicate
@ -673,6 +682,10 @@ private:
void save_io_handler(void);
};
namespace AP {
AP_Param *param();
};
/// Template class for scalar variables.
///
/// Objects of this type have a value, and can be treated in many ways as though they