|
|
@@ -88,7 +88,8 @@ static void log_dir(const std::string &path) { |
|
|
|
|
|
|
|
|
constexpr char config_path[] = "/spiffs/blinky.json"; |
|
|
constexpr char config_path[] = "/spiffs/blinky.json"; |
|
|
|
|
|
|
|
|
//#define PROFILE |
|
|
|
|
|
|
|
|
//#define PROFILE_PERF |
|
|
|
|
|
//#define PROFILE_MEM |
|
|
|
|
|
|
|
|
// Entry Point |
|
|
// Entry Point |
|
|
|
|
|
|
|
|
@@ -135,7 +136,7 @@ extern "C" void app_main(void) { |
|
|
ESP_LOGI(TAG, "Configuring LEDs"); |
|
|
ESP_LOGI(TAG, "Configuring LEDs"); |
|
|
|
|
|
|
|
|
device.lock(); |
|
|
device.lock(); |
|
|
const std::string &effect = device.get_effect(); |
|
|
|
|
|
|
|
|
const std::string effect = device.get_effect(); |
|
|
bool is_on = device.is_on(); |
|
|
bool is_on = device.is_on(); |
|
|
int length = device.get_strip_length(); |
|
|
int length = device.get_strip_length(); |
|
|
cJSON *json = device.make_json_config_locked(); |
|
|
cJSON *json = device.make_json_config_locked(); |
|
|
@@ -174,24 +175,30 @@ extern "C" void app_main(void) { |
|
|
ESP_LOGI(TAG, "Starting animation"); |
|
|
ESP_LOGI(TAG, "Starting animation"); |
|
|
|
|
|
|
|
|
int period_us = 1000000 / 60; |
|
|
int period_us = 1000000 / 60; |
|
|
int64_t start = time_us(); |
|
|
|
|
|
int64_t target_us = start; |
|
|
|
|
|
#ifdef PROFILE |
|
|
|
|
|
|
|
|
int64_t target_us = time_us(); |
|
|
|
|
|
int64_t profile_start = target_us; |
|
|
|
|
|
#ifdef PROFILE_PERF |
|
|
int64_t total_delay_us = 0; |
|
|
int64_t total_delay_us = 0; |
|
|
int n_delays = 0; |
|
|
int n_delays = 0; |
|
|
int64_t after_sleep_us = 0; |
|
|
int64_t after_sleep_us = 0; |
|
|
int n_processes = 0; |
|
|
int n_processes = 0; |
|
|
int64_t total_process_us = 0; |
|
|
int64_t total_process_us = 0; |
|
|
#endif // PROFILE |
|
|
|
|
|
|
|
|
#endif // PROFILE_PERF |
|
|
while (true) { |
|
|
while (true) { |
|
|
int64_t now = time_us(); |
|
|
int64_t now = time_us(); |
|
|
#ifdef PROFILE |
|
|
|
|
|
|
|
|
#ifdef PROFILE_PERF |
|
|
if (after_sleep_us > 0) { |
|
|
if (after_sleep_us > 0) { |
|
|
total_process_us += now - after_sleep_us; |
|
|
total_process_us += now - after_sleep_us; |
|
|
++n_processes; |
|
|
++n_processes; |
|
|
} |
|
|
} |
|
|
|
|
|
#endif // PROFILE_PERF |
|
|
|
|
|
|
|
|
if (now - start >= 5000000) { |
|
|
|
|
|
|
|
|
if (now - profile_start >= 5000000) { |
|
|
|
|
|
#ifdef PROFILE_MEM |
|
|
|
|
|
heap_caps_print_heap_info(MALLOC_CAP_8BIT); |
|
|
|
|
|
#endif // PROFILE_MEM |
|
|
|
|
|
|
|
|
|
|
|
#ifdef PROFILE_PERF |
|
|
ESP_LOGI(TAG, "Average delay: %f ms", (double)total_delay_us / (n_delays * 1000)); |
|
|
ESP_LOGI(TAG, "Average delay: %f ms", (double)total_delay_us / (n_delays * 1000)); |
|
|
total_delay_us = 0; |
|
|
total_delay_us = 0; |
|
|
n_delays = 0; |
|
|
n_delays = 0; |
|
|
@@ -199,10 +206,11 @@ extern "C" void app_main(void) { |
|
|
ESP_LOGI(TAG, "Average processing: %f us", (double)total_process_us / n_processes); |
|
|
ESP_LOGI(TAG, "Average processing: %f us", (double)total_process_us / n_processes); |
|
|
total_process_us = 0; |
|
|
total_process_us = 0; |
|
|
n_processes = 0; |
|
|
n_processes = 0; |
|
|
|
|
|
#endif // PROFILE_PERF |
|
|
|
|
|
|
|
|
start = now; |
|
|
|
|
|
|
|
|
profile_start = now; |
|
|
} |
|
|
} |
|
|
#endif // PROFILE |
|
|
|
|
|
|
|
|
|
|
|
int64_t delay_us = target_us - now; |
|
|
int64_t delay_us = target_us - now; |
|
|
if (delay_us < 0) delay_us = 0; |
|
|
if (delay_us < 0) delay_us = 0; |
|
|
if (device.wait(delay_us / 1000)) { |
|
|
if (device.wait(delay_us / 1000)) { |
|
|
@@ -211,12 +219,11 @@ extern "C" void app_main(void) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
target_us = now + delay_us + period_us; |
|
|
target_us = now + delay_us + period_us; |
|
|
#ifdef PROFILE |
|
|
|
|
|
|
|
|
#ifdef PROFILE_PERF |
|
|
after_sleep_us = time_us(); |
|
|
after_sleep_us = time_us(); |
|
|
|
|
|
|
|
|
total_delay_us += (after_sleep_us - now); |
|
|
total_delay_us += (after_sleep_us - now); |
|
|
++n_delays; |
|
|
++n_delays; |
|
|
#endif // PROFILE |
|
|
|
|
|
|
|
|
#endif // PROFILE_PERF |
|
|
LEDs->step(); |
|
|
LEDs->step(); |
|
|
LEDs->show(); |
|
|
LEDs->show(); |
|
|
} |
|
|
} |
|
|
|