Initial Demo OS
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
#include "apps.h"
|
||||
#include "os_gfx.h"
|
||||
#include "os_status.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "esp_system.h"
|
||||
#include "esp_chip_info.h"
|
||||
#include "esp_flash.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
#define HISTORY_LEN 40
|
||||
static uint8_t s_heap_history[HISTORY_LEN] = {0};
|
||||
static size_t s_history_count = 0;
|
||||
static uint8_t s_view = 0;
|
||||
|
||||
static void sysmon_init(void)
|
||||
{
|
||||
s_history_count = 0;
|
||||
memset(s_heap_history, 50, sizeof(s_heap_history));
|
||||
}
|
||||
|
||||
static void sysmon_enter(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void sysmon_update(uint32_t delta_ms)
|
||||
{
|
||||
sys_status_t status;
|
||||
sys_status_get(&status);
|
||||
sys_gfx_draw_status_bar(&status);
|
||||
|
||||
static uint32_t sample_timer = 0;
|
||||
sample_timer += delta_ms;
|
||||
if (sample_timer >= 200) {
|
||||
sample_timer = 0;
|
||||
uint32_t kb = status.free_heap / 1024;
|
||||
uint8_t norm_val = (kb > 300) ? 100 : (uint8_t)((kb * 100) / 300);
|
||||
|
||||
if (s_history_count < HISTORY_LEN) {
|
||||
s_heap_history[s_history_count++] = norm_val;
|
||||
} else {
|
||||
memmove(&s_heap_history[0], &s_heap_history[1], HISTORY_LEN - 1);
|
||||
s_heap_history[HISTORY_LEN - 1] = norm_val;
|
||||
}
|
||||
}
|
||||
|
||||
char buf[24];
|
||||
|
||||
if (s_view == 0) {
|
||||
snprintf(buf, sizeof(buf), "RAM:%luK", (unsigned long)(status.free_heap / 1024));
|
||||
sys_gfx_draw_str_3x5(3, 9, buf, COLOR_WHITE);
|
||||
|
||||
snprintf(buf, sizeof(buf), "TASKS:%u", (unsigned int)uxTaskGetNumberOfTasks());
|
||||
sys_gfx_draw_str_3x5(40, 9, buf, COLOR_WHITE);
|
||||
|
||||
sys_gfx_draw_sparkline(3, 16, 66, 14, s_heap_history, s_history_count, 100);
|
||||
sys_gfx_draw_action_bar("C:VIEW", "H:HOME");
|
||||
} else {
|
||||
esp_chip_info_t chip;
|
||||
esp_chip_info(&chip);
|
||||
uint32_t flash_size = 0;
|
||||
esp_flash_get_size(NULL, &flash_size);
|
||||
|
||||
sys_gfx_draw_str_3x5(3, 9, "ESP32-C3 RISC-V", COLOR_WHITE);
|
||||
|
||||
snprintf(buf, sizeof(buf), "REV:%d CORES:%d", chip.revision, chip.cores);
|
||||
sys_gfx_draw_str_3x5(3, 16, buf, COLOR_WHITE);
|
||||
|
||||
snprintf(buf, sizeof(buf), "FLASH:%lu MB", (unsigned long)(flash_size / (1024 * 1024)));
|
||||
sys_gfx_draw_str_3x5(3, 23, buf, COLOR_WHITE);
|
||||
|
||||
sys_gfx_draw_action_bar("C:VIEW", "H:HOME");
|
||||
}
|
||||
}
|
||||
|
||||
static void sysmon_handle_input(input_action_t action)
|
||||
{
|
||||
if (action == INPUT_ACTION_CLICK) {
|
||||
s_view = (s_view + 1) % 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void sysmon_exit(void)
|
||||
{
|
||||
}
|
||||
|
||||
const sys_app_t g_app_sysmon = {
|
||||
.id = "sysmon",
|
||||
.name = "Sys Monitor",
|
||||
.init = sysmon_init,
|
||||
.enter = sysmon_enter,
|
||||
.update = sysmon_update,
|
||||
.handle_input = sysmon_handle_input,
|
||||
.exit = sysmon_exit,
|
||||
};
|
||||
Reference in New Issue
Block a user