Skip to content

Commit

Permalink
feat: persist sensor opt to flash
Browse files Browse the repository at this point in the history
  • Loading branch information
nullptr authored and LynnL4 committed May 22, 2024
1 parent 4986c7b commit 13b7544
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions porting/himax/we2/el_camera_we2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ el_err_code_t CameraWE2::get_processed_frame(el_img_t* img) {
}

*img = _drv_get_jpeg();
img->rotate = _rotation_override;
// just assign, not sure whether the img is valid

return EL_OK;
Expand Down
2 changes: 2 additions & 0 deletions sscma/callback/sensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ void set_sensor(
ret = camera->init(opt_id); // TODO: custom resolution
if (ret != EL_OK) [[unlikely]]
goto SensorError;

static_resource->storage->emplace(el_make_storage_kv(SSCMA_STORAGE_KEY_CONF_SENSOR_OPT, opt_id));
}

// set the sensor state to available
Expand Down
1 change: 1 addition & 0 deletions sscma/definations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#define SSCMA_STORAGE_KEY_BOOT_COUNT "sscma#boot_count"
#define SSCMA_STORAGE_KEY_CONF_MODEL_ID "sscma#conf#model_id"
#define SSCMA_STORAGE_KEY_CONF_SENSOR_ID "sscma#conf#sensor_id"
#define SSCMA_STORAGE_KEY_CONF_SENSOR_OPT "sscma#conf#sensor_opt"

#define SSCMA_WIRELESS_NETWORK_NAME_LEN 32
#define SSCMA_WIRELESS_NETWORK_PASSWD_LEN 64
Expand Down
8 changes: 6 additions & 2 deletions sscma/hooks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ void init_model_hook(std::string cmd) {

void init_sensor_hook(std::string cmd) {
if (static_resource->current_sensor_id) [[likely]]
set_sensor(
cmd + "@SENSOR", static_resource->current_sensor_id, true, 0, static_cast<void*>(default_transport()), true);
set_sensor(cmd + "@SENSOR",
static_resource->current_sensor_id,
true,
static_resource->current_sensor_opt,
static_cast<void*>(default_transport()),
true);
}

void init_action_hook(std::string cmd) {
Expand Down
6 changes: 5 additions & 1 deletion sscma/static_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class StaticResource final {
int32_t boot_count;
uint8_t current_model_id;
uint8_t current_sensor_id;
uint16_t current_sensor_opt;
el_algorithm_type_t current_algorithm_type;

// internal states
Expand Down Expand Up @@ -101,7 +102,7 @@ class StaticResource final {
wifi = &v_wifi;

static auto v_mqtt{MQTT(wifi)};
mqtt = &v_mqtt;
mqtt = &v_mqtt;
mqtt->type = EL_TRANSPORT_MQTT;
#endif

Expand Down Expand Up @@ -129,6 +130,7 @@ class StaticResource final {
boot_count = 0;
current_model_id = 1;
current_sensor_id = 1;
current_sensor_opt = 0;
current_algorithm_type = EL_ALGO_TYPE_UNDEFINED;

current_task_id = 0;
Expand Down Expand Up @@ -178,12 +180,14 @@ class StaticResource final {
if (storage->get(kv) && std::strcmp(kv.value, EL_VERSION) == 0) [[likely]]
*storage >> el_make_storage_kv(SSCMA_STORAGE_KEY_CONF_MODEL_ID, current_model_id) >>
el_make_storage_kv(SSCMA_STORAGE_KEY_CONF_SENSOR_ID, current_sensor_id) >>
el_make_storage_kv(SSCMA_STORAGE_KEY_CONF_SENSOR_OPT, current_sensor_opt) >>
el_make_storage_kv_from_type(current_algorithm_type) >>
el_make_storage_kv(SSCMA_STORAGE_KEY_BOOT_COUNT, boot_count);
else { // else init flash storage
std::strncpy(version, EL_VERSION, sizeof(version));
*storage << kv << el_make_storage_kv(SSCMA_STORAGE_KEY_CONF_MODEL_ID, current_model_id)
<< el_make_storage_kv(SSCMA_STORAGE_KEY_CONF_SENSOR_ID, current_sensor_id)
<< el_make_storage_kv(SSCMA_STORAGE_KEY_CONF_SENSOR_OPT, current_sensor_opt)
<< el_make_storage_kv_from_type(current_algorithm_type)
<< el_make_storage_kv(SSCMA_STORAGE_KEY_BOOT_COUNT, boot_count);
}
Expand Down

0 comments on commit 13b7544

Please sign in to comment.