mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-03-11 17:13:56 -03:00
AP_RSSI: add singleton
This commit is contained in:
parent
a47bda0b41
commit
ac2fe5f042
@ -97,6 +97,10 @@ const AP_Param::GroupInfo AP_RSSI::var_info[] = {
|
|||||||
AP_RSSI::AP_RSSI()
|
AP_RSSI::AP_RSSI()
|
||||||
{
|
{
|
||||||
AP_Param::setup_object_defaults(this, var_info);
|
AP_Param::setup_object_defaults(this, var_info);
|
||||||
|
if (_s_instance) {
|
||||||
|
AP_HAL::panic("Too many RSSI sensors");
|
||||||
|
}
|
||||||
|
_s_instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
@ -104,6 +108,14 @@ AP_RSSI::~AP_RSSI(void)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the AP_RSSI singleton
|
||||||
|
*/
|
||||||
|
AP_RSSI *AP_RSSI::get_instance()
|
||||||
|
{
|
||||||
|
return _s_instance;
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize the rssi object and prepare it for use
|
// Initialize the rssi object and prepare it for use
|
||||||
void AP_RSSI::init()
|
void AP_RSSI::init()
|
||||||
{
|
{
|
||||||
@ -200,3 +212,14 @@ float AP_RSSI::scale_and_constrain_float_rssi(float current_rssi_value, float lo
|
|||||||
// value retrieved falls outside the user-supplied range.
|
// value retrieved falls outside the user-supplied range.
|
||||||
return constrain_float(rssi_value_scaled, 0.0f, 1.0f);
|
return constrain_float(rssi_value_scaled, 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AP_RSSI *AP_RSSI::_s_instance = nullptr;
|
||||||
|
|
||||||
|
namespace AP {
|
||||||
|
|
||||||
|
AP_RSSI *rssi()
|
||||||
|
{
|
||||||
|
return AP_RSSI::get_instance();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
@ -37,6 +37,8 @@ public:
|
|||||||
// destructor
|
// destructor
|
||||||
~AP_RSSI(void);
|
~AP_RSSI(void);
|
||||||
|
|
||||||
|
static AP_RSSI *get_instance();
|
||||||
|
|
||||||
// Initialize the rssi object and prepare it for use
|
// Initialize the rssi object and prepare it for use
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
@ -55,6 +57,9 @@ public:
|
|||||||
static const struct AP_Param::GroupInfo var_info[];
|
static const struct AP_Param::GroupInfo var_info[];
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
static AP_RSSI *_s_instance;
|
||||||
|
|
||||||
// RSSI parameters
|
// RSSI parameters
|
||||||
AP_Int8 rssi_type; // Type of RSSI being used
|
AP_Int8 rssi_type; // Type of RSSI being used
|
||||||
AP_Int8 rssi_analog_pin; // Analog pin RSSI value found on
|
AP_Int8 rssi_analog_pin; // Analog pin RSSI value found on
|
||||||
@ -77,3 +82,7 @@ private:
|
|||||||
// Scale and constrain a float rssi value to 0.0 to 1.0 range
|
// Scale and constrain a float rssi value to 0.0 to 1.0 range
|
||||||
float scale_and_constrain_float_rssi(float current_rssi_value, float low_rssi_range, float high_rssi_range);
|
float scale_and_constrain_float_rssi(float current_rssi_value, float low_rssi_range, float high_rssi_range);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace AP {
|
||||||
|
AP_RSSI *rssi();
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user