DataFlash: allow access to DataFlash instance as a static singleton

This commit is contained in:
Andrew Tridgell 2016-05-03 16:33:15 +10:00
parent 11dd254498
commit 9a1cbff850
2 changed files with 14 additions and 0 deletions

View File

@ -2,6 +2,8 @@
#include "DataFlash_Backend.h"
DataFlash_Class *DataFlash_Class::_instance;
const AP_Param::GroupInfo DataFlash_Class::var_info[] = {
// @Param: _BACKEND_TYPE
// @DisplayName: DataFlash Backend Storage type

View File

@ -56,6 +56,15 @@ public:
_firmware_string(firmware_string)
{
AP_Param::setup_object_defaults(this, var_info);
if (_instance != nullptr) {
AP_HAL::panic("DataFlash must be singleton");
}
_instance = this;
}
// get singleton instance
static DataFlash_Class *instance(void) {
return _instance;
}
void set_mission(const AP_Mission *mission);
@ -230,4 +239,7 @@ private:
// calculate the length of a message using fields specified in
// fmt; includes the message header
int16_t Log_Write_calc_msg_len(const char *fmt) const;
private:
static DataFlash_Class *_instance;
};