Skip to content

Commit

Permalink
Added logic to scheduler task to only activate update structs that ma…
Browse files Browse the repository at this point in the history
…tch the current mode. Added bit, trigger func, and handlers in task loop for custom screen update (but with no logic in them yet). Switched logic in nvs save config func to reboot every time we get a new config pushed to us, with TODO with suggestions for improving behavior later
  • Loading branch information
second-string committed Jan 6, 2024
1 parent 866d432 commit 1e92d09
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 60 deletions.
2 changes: 1 addition & 1 deletion configuration_app/spot_check_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def configure():
print()

# TODO :: include 'manual' option to manually set time)
# TODO :: offline mode?
tz_str = ""
tz_display_name = ""
while tz_str == "":
Expand Down Expand Up @@ -192,7 +193,6 @@ def configure():

cursor.close()
db_conn.close()
# TODO :: where to put offline mode option?


def provision():
Expand Down
12 changes: 8 additions & 4 deletions main/http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,17 @@ static esp_err_t configure_post_handler(httpd_req_t *req) {

nvs_save_config(&config);

// Update new time and trigger redraw immediately
sntp_set_tz_str(config.tz_str);
scheduler_trigger_time_update();

// End response
cJSON_Delete(payload);
httpd_resp_send(req, NULL, 0);

// TODO : previously we were setting the tz str and forcing a time redraw through scheduler, but that wouldn't
// properly re render everything else if the spot changed right? For now, reboot in all cases to make things super
// simple, but in the future this could be smarter to only reboot on mode change or gracefully handle all cases
esp_restart();
while (1) {
}

return ESP_OK;
}

Expand Down
1 change: 1 addition & 0 deletions main/include/scheduler_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void scheduler_trigger_both_charts_update();
void scheduler_trigger_ota_check();
void scheduler_trigger_mflt_upload();
void scheduler_trigger_screen_dirty();
void scheduler_trigger_custom_screen_update();
void scheduler_block_until_system_idle();
void scheduler_set_busy(uint32_t system_idle_bitmask);
void scheduler_set_idle(uint32_t system_idle_bitmask);
Expand Down
7 changes: 5 additions & 2 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ void app_main(void) {
app_start();

spot_check_config_t *config = nvs_get_config();
log_printf(LOG_LEVEL_INFO, "Operating mode: '%s'", spot_check_mode_to_string(config->operating_mode));
sntp_set_tz_str(config->tz_str);
display_render_splash_screen(spot_check_get_fw_version(), spot_check_get_hw_version());

Expand Down Expand Up @@ -230,6 +231,9 @@ void app_main(void) {
// make it less likely we render the epoch before it syncs correctly. Sometimes SNTP gets a new value within
// a second, sometimes it takes 45 seconds. If sntp doesn't report fully synced, we also check the date and
// as long as it's not 1970 we call it synced to help speed up the process.
// This could theoretically be skipped in custom mode since that doesn't display the time, but also opens us up
// to stepping on https requests if sntp sync succeeds and launches time forward a huge amount while were
// already doing the initial custom endpoint request after entering online mode.
bool sntp_time_set = false;
uint32_t start_ticks = xTaskGetTickCount();
uint32_t now_ticks = start_ticks;
Expand Down Expand Up @@ -258,8 +262,7 @@ void app_main(void) {
spot_check_clear_checking_connection_screen();
scheduler_set_online_mode();

log_printf(LOG_LEVEL_INFO,
"Boot successful, showing time + last saved conditions / charts and kicked off conditions task");
log_printf(LOG_LEVEL_INFO, "Boot successful, kicking scheduler taks into online mode");
} while (0);

// Delay a minute before we run the on-boot delayed actions. This is because both mflt's http client and the
Expand Down
Loading

0 comments on commit 1e92d09

Please sign in to comment.