I‘m developing a light dimmer, I use Mesh Config Entry
to save light state as 16 scene in persistent storage, because the size of each state is 1024 byte, so the live value dmx_scene occupies 16k ram, how can I reduce the memory usage?
nRF SDK FOR Mesh V5.0.0
nRF SDK 17.02
nRF52832
#include <stdint.h>
#include <stdlib.h>
#include "app_config.h"
#if (SCENE_ARRAY_SIZE>0)
#include "dmx_mc.h"
#include "scene_server.h"
#include "access_config.h"
#include "mesh_config_entry.h"
#include "cc_define.h"
#include "log.h"
#define SCENE_ARRAY_SIZE 16
static uint16_t current_scene_number=0;
typedef struct{
uint8_t dmx1[512];
uint8_t dmx2[512]
}dmx_scene_t;
static dmx_scene_t dmx_scene[SCENE_ARRAY_SIZE];
static dmx_scene_t store_entry_scene;
uint32_t dmx_mc_scene_store(const void *p_server , const scene_store_params_t *params,uint16_t transition_100ms,uint16_t model_id){
dmx_status_t *status=dmx_get_status();
store_entry_scene.scene_number=params->scene_number;
store_entry_scene.status=*status;
//save
mesh_config_entry_id_t id = APP_ENTRY_DMX_SCENE_ID;
id.record += (uint16_t) params->position;
uint32_t ret= mesh_config_entry_set(id, &store_entry_scene);
return ret;
}
uint32_t dmx_mc_scene_recall(const void *p_server , const scene_recall_params_t *params){
if(params->scene_number==0 ){
return NRF_ERROR_INVALID_PARAM;
}
for(uint8_t i=0;i<SCENE_ARRAY_SIZE;i++){
dmx_scene_t *a_scene=&dmx_scene[i];
if(a_scene->scene_number == params->scene_number){
current_scene_number=params->scene_number;
dmx_set_setting(&a_scene->setting,&a_scene->status,a_scene->transition_100ms);//
return NRF_SUCCESS;
}
}
return NRF_ERROR_NOT_FOUND;
}
//---------------- Config Entry ------------------------------------------------------------------------
static uint32_t dmx_entry_scene_setter(mesh_config_entry_id_t id, const void *p_entry)
{
const dmx_scene_t * value = (const dmx_scene_t *) p_entry;
dmx_scene[(uint8_t)(id.record-APP_ENTRY_DMX_SCENE_ID.record)]=*value;
return NRF_SUCCESS;
}
static void dmx_entry_scene_getter(mesh_config_entry_id_t id, void *p_entry)
{
dmx_scene_t *value=(dmx_scene_t *)p_entry;
*value=dmx_scene[id.record-APP_ENTRY_DMX_SCENE_ID.record];
}
//---------- Config Stroe ---------------
MESH_CONFIG_ENTRY(dmx_scene_entry,
APP_ENTRY_DMX_SCENE_ID,
SCENE_ARRAY_SIZE,
sizeof(dmx_scene_t),
dmx_entry_scene_setter,
dmx_entry_scene_getter,
NULL);
#endif