Storing the default properties and capabilities

Hello,

I am currently working on a C++ project for a range of embedded devices which have several similarities. I am trying to keep the code common as much as possible.

Each device has capabilities and should be assigned with one value from the capabilities and default property. Since the project details are confidential, I am giving similar application as the reference.

For example, assume that we need to write an application for a range of mobile phones and want to have the same firmware. Assume all phones have the same processor and the difference is only in the interfacing devices like sensors, camera resolution, etc.

Assume that I am going to create classes for the proximity sensor, camera, gyroscope.

When booted, the application should get predefined capability based on the model(assuming the application can somehow fetch model). Once the model is known, it should initialize the objects with default values.

I was thinking to do this in the following fashion.

typedef enum _model_e {
eMOB12MP,
eMOB8MP,
eLASTMODEL
}

typedef struct _camera_info_t {
resolution_e res;
..........
}

typedef struct _prox_sensor_t {
bool supported;
........
}

typedef struct _config_t {
camera_info_t cam;
prox_sensor_t prox;
gyroscope_t gyro;
....
}config_t;

static const config_t configs[] =
{
{ // model eMOB12MP
.cam = {
.res = 12MP,
........
},
.prox = {
.supported = false,
............
},
........
},
{ //eMOB8MP
.cam = {
.res = 8MP,
........
},
.prox = {
.supported = true,
............
},
........
},
}

config_t *get_config(model_e model)
{
config_t *ptr = NULL;

if (model < eLASTMODEL && model >= 0) {
ptr = configs[(int)model];
}

return ptr;
}

In the main function, I will call get_config() and initialize all the objects based on the config. Is this a correct approach?

Thanks,
Subbarao
Topic archived. No new replies allowed.