MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / configured

Method configured

libraries/AP_Compass/AP_Compass.cpp:2086–2129  ·  view source on GitHub ↗

Returns True if the compasses have been configured (i.e. offsets saved) @returns True if compass has been configured

Source from the content-addressed store, hash-verified

2084/// @returns True if compass has been configured
2085///
2086bool Compass::configured(uint8_t i)
2087{
2088 // exit immediately if instance is beyond the number of compasses we have available
2089 if (i > get_count()) {
2090 return false;
2091 }
2092
2093 // exit immediately if all offsets are zero
2094 if (is_zero(get_offsets(i).length())) {
2095 return false;
2096 }
2097
2098 StateIndex id = _get_state_id(Priority(i));
2099 // exit immediately if dev_id hasn't been detected
2100 if (_state[id].detected_dev_id == 0 ||
2101 id == COMPASS_MAX_INSTANCES) {
2102 return false;
2103 }
2104
2105#ifdef HAL_USE_EMPTY_STORAGE
2106 // the load() call below returns zeroes on empty storage, so the
2107 // check-stored-value check here will always fail. Since nobody
2108 // really cares about the empty-storage case, shortcut out here
2109 // for simplicity.
2110 return true;
2111#endif
2112
2113 // back up cached value of dev_id
2114 int32_t dev_id_cache_value = _state[id].dev_id;
2115
2116 // load dev_id from eeprom
2117 _state[id].dev_id.load();
2118
2119 // if dev_id loaded from eeprom is different from detected dev id or dev_id loaded from eeprom is different from cached dev_id, compass is unconfigured
2120 if (_state[id].dev_id != _state[id].detected_dev_id || _state[id].dev_id != dev_id_cache_value) {
2121 // restore cached value
2122 _state[id].dev_id.set(dev_id_cache_value);
2123 // return failure
2124 return false;
2125 }
2126
2127 // if we got here then it must be configured
2128 return true;
2129}
2130
2131bool Compass::configured(char *failure_msg, uint8_t failure_msg_len)
2132{

Callers 2

convert_paramsMethod · 0.45
convertMethod · 0.45

Calls 4

loadMethod · 0.80
is_zeroFunction · 0.50
lengthMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected