mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 14:38:30 -04:00
AP_Param: add singleton
This commit is contained in:
parent
b81aa05622
commit
623c1aa3cd
@ -38,6 +38,9 @@ extern const AP_HAL::HAL &hal;
|
|||||||
|
|
||||||
uint16_t AP_Param::sentinal_offset;
|
uint16_t AP_Param::sentinal_offset;
|
||||||
|
|
||||||
|
// singleton instance
|
||||||
|
AP_Param *AP_Param::_singleton;
|
||||||
|
|
||||||
#define ENABLE_DEBUG 1
|
#define ENABLE_DEBUG 1
|
||||||
|
|
||||||
#if ENABLE_DEBUG
|
#if ENABLE_DEBUG
|
||||||
@ -379,6 +382,14 @@ bool AP_Param::get_base(const struct Info &info, ptrdiff_t &base)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace AP {
|
||||||
|
|
||||||
|
AP_Param *param()
|
||||||
|
{
|
||||||
|
return AP_Param::get_singleton();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// find the info structure given a header and a group_info table
|
// find the info structure given a header and a group_info table
|
||||||
// return the Info structure and a pointer to the variables storage
|
// return the Info structure and a pointer to the variables storage
|
||||||
|
@ -197,6 +197,11 @@ public:
|
|||||||
uint16_t i;
|
uint16_t i;
|
||||||
for (i=0; info[i].type != AP_PARAM_NONE; i++) ;
|
for (i=0; info[i].type != AP_PARAM_NONE; i++) ;
|
||||||
_num_vars = i;
|
_num_vars = i;
|
||||||
|
|
||||||
|
if (_singleton != nullptr) {
|
||||||
|
AP_HAL::panic("AP_Param must be singleton");
|
||||||
|
}
|
||||||
|
_singleton = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// empty constructor
|
// empty constructor
|
||||||
@ -479,7 +484,11 @@ public:
|
|||||||
AP_HAL::BetterStream *port);
|
AP_HAL::BetterStream *port);
|
||||||
#endif // AP_PARAM_KEY_DUMP
|
#endif // AP_PARAM_KEY_DUMP
|
||||||
|
|
||||||
|
static AP_Param *get_singleton() { return _singleton; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static AP_Param *_singleton;
|
||||||
|
|
||||||
/// EEPROM header
|
/// EEPROM header
|
||||||
///
|
///
|
||||||
/// This structure is placed at the head of the EEPROM to indicate
|
/// This structure is placed at the head of the EEPROM to indicate
|
||||||
@ -673,6 +682,10 @@ private:
|
|||||||
void save_io_handler(void);
|
void save_io_handler(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace AP {
|
||||||
|
AP_Param *param();
|
||||||
|
};
|
||||||
|
|
||||||
/// Template class for scalar variables.
|
/// Template class for scalar variables.
|
||||||
///
|
///
|
||||||
/// Objects of this type have a value, and can be treated in many ways as though they
|
/// Objects of this type have a value, and can be treated in many ways as though they
|
||||||
|
Loading…
Reference in New Issue
Block a user