|
|
|
@ -1832,6 +1832,65 @@ void AP_Param::convert_parent_class(uint8_t param_key, void *object_pointer,
@@ -1832,6 +1832,65 @@ void AP_Param::convert_parent_class(uint8_t param_key, void *object_pointer,
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
convert width of a parameter, allowing update to wider scalar values |
|
|
|
|
without changing the parameter indexes |
|
|
|
|
*/ |
|
|
|
|
bool AP_Param::convert_parameter_width(ap_var_type old_ptype) |
|
|
|
|
{ |
|
|
|
|
if (configured_in_storage()) { |
|
|
|
|
// already converted or set by the user
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
uint32_t group_element = 0; |
|
|
|
|
const struct GroupInfo *ginfo; |
|
|
|
|
struct GroupNesting group_nesting {}; |
|
|
|
|
uint8_t idx; |
|
|
|
|
const struct AP_Param::Info *info = find_var_info(&group_element, ginfo, group_nesting, &idx); |
|
|
|
|
|
|
|
|
|
if (info == nullptr) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// remember the type
|
|
|
|
|
ap_var_type new_ptype; |
|
|
|
|
if (ginfo != nullptr) { |
|
|
|
|
new_ptype = (ap_var_type)ginfo->type; |
|
|
|
|
} else { |
|
|
|
|
new_ptype = (ap_var_type)info->type; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// create the header we will use to scan for the variable
|
|
|
|
|
struct Param_header phdr; |
|
|
|
|
phdr.type = old_ptype; |
|
|
|
|
set_key(phdr, info->key); |
|
|
|
|
phdr.group_element = group_element; |
|
|
|
|
|
|
|
|
|
// scan EEPROM to find the right location
|
|
|
|
|
uint16_t pofs; |
|
|
|
|
if (!scan(&phdr, &pofs)) { |
|
|
|
|
// it isn't in storage
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// load the old value from EEPROM
|
|
|
|
|
uint8_t old_value[type_size(old_ptype)]; |
|
|
|
|
_storage.read_block(old_value, pofs+sizeof(phdr), sizeof(old_value)); |
|
|
|
|
|
|
|
|
|
AP_Param *old_ap = (AP_Param *)&old_value[0]; |
|
|
|
|
|
|
|
|
|
// going via float is safe as the only time we would be converting
|
|
|
|
|
// from AP_Int32 is when converting to float
|
|
|
|
|
float old_float_value = old_ap->cast_to_float(old_ptype); |
|
|
|
|
set_value(new_ptype, this, old_float_value); |
|
|
|
|
|
|
|
|
|
// force save as the new type
|
|
|
|
|
save(true); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
set a parameter to a float value |
|
|
|
|