Legohead259 / OlympianESC-Firmware

Firmware for a novel Micro-ROS based electronic speed controller (ESC)
MIT License
0 stars 0 forks source link

[Feature Request]: Make MicroROS parameters import from file use callback instead of discrete functions #34

Open Legohead259 opened 11 months ago

Legohead259 commented 11 months ago

Is your feature request related to a problem? Please describe. Right now, the following lines of code need to be added for every unique NVS implementation:

    // Iterate through the parameter array in memory and put loaded values there
    for (uint8_t i = 0; i < NUM_PARAMETERS; i++) {
        if (typeid(*params[i]) == typeid(parameter_bool_t)) {
            Serial1.println("Got boolean parameter!"); // Debug
            dynamic_cast<parameter_bool_t*>(params[i])->value = parameterSettings.getBool(params[i]->key);
            params[i]->type = RCLC_PARAMETER_BOOL;
        }
        else if (typeid(*params[i]) == typeid(parameter_int_t)) {
            Serial1.println("Got integer parameter!"); // Debug
            dynamic_cast<parameter_int_t*>(params[i])->value = parameterSettings.getInt(params[i]->key);
            params[i]->type = RCLC_PARAMETER_INT;
        } 
        else if (typeid(*params[i]) == typeid(parameter_double_t)) {
            Serial1.println("Got double parameter!"); // Debug
            dynamic_cast<parameter_double_t*>(params[i])->value = parameterSettings.getDouble(params[i]->key);
            params[i]->type = RCLC_PARAMETER_DOUBLE;
        }
        else {
            params[i]->type = RCLC_PARAMETER_NOT_SET;
        }
    }

This can get very clunky once more NVS solutions are implemented for EEPROM versus Preferences versus JSON, etc.

Describe the solution you'd like The parameter value import line (dynamic_cast<parameter_bool_t*>(params[i])->value = parameterSettings.getBool(params[i]->key);) should be modified to use a callback (e.g. getBoolCB()) that can be changed depending on the NVS implementation. This will make it a single loop for importing all the data, regardless of the NVS solution.