Merge pull request #792 from Riksu9000/memory_saving

Memory savings by replacing strings
This commit is contained in:
JF 2021-11-06 10:45:17 +01:00 committed by GitHub
commit cfc11ea83b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 17 deletions

View file

@ -209,7 +209,7 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen4() {
static constexpr uint8_t maxTaskCount = 9;
TaskStatus_t tasksStatus[maxTaskCount];
lv_obj_t* infoTask = lv_table_create(lv_scr_act(), NULL);
lv_obj_t* infoTask = lv_table_create(lv_scr_act(), nullptr);
lv_table_set_col_cnt(infoTask, 4);
lv_table_set_row_cnt(infoTask, maxTaskCount + 1);
lv_obj_set_style_local_pad_all(infoTask, LV_TABLE_PART_CELL1, LV_STATE_DEFAULT, 0);
@ -227,35 +227,37 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen4() {
auto nb = uxTaskGetSystemState(tasksStatus, maxTaskCount, nullptr);
std::sort(tasksStatus, tasksStatus + nb, sortById);
for (uint8_t i = 0; i < nb && i < maxTaskCount; i++) {
char buffer[7] = {0};
lv_table_set_cell_value(infoTask, i + 1, 0, std::to_string(tasksStatus[i].xTaskNumber).c_str());
char state[2] = {0};
sprintf(buffer, "%lu", tasksStatus[i].xTaskNumber);
lv_table_set_cell_value(infoTask, i + 1, 0, buffer);
switch (tasksStatus[i].eCurrentState) {
case eReady:
case eRunning:
state[0] = 'R';
buffer[0] = 'R';
break;
case eBlocked:
state[0] = 'B';
buffer[0] = 'B';
break;
case eSuspended:
state[0] = 'S';
buffer[0] = 'S';
break;
case eDeleted:
state[0] = 'D';
buffer[0] = 'D';
break;
default:
state[0] = 'I'; // Invalid
buffer[0] = 'I'; // Invalid
break;
}
lv_table_set_cell_value(infoTask, i + 1, 1, state);
buffer[1] = '\0';
lv_table_set_cell_value(infoTask, i + 1, 1, buffer);
lv_table_set_cell_value(infoTask, i + 1, 2, tasksStatus[i].pcTaskName);
if (tasksStatus[i].usStackHighWaterMark < 20) {
std::string str1 = std::to_string(tasksStatus[i].usStackHighWaterMark) + " low";
lv_table_set_cell_value(infoTask, i + 1, 3, str1.c_str());
sprintf(buffer, "%d low", tasksStatus[i].usStackHighWaterMark);
} else {
lv_table_set_cell_value(infoTask, i + 1, 3, std::to_string(tasksStatus[i].usStackHighWaterMark).c_str());
sprintf(buffer, "%d", tasksStatus[i].usStackHighWaterMark);
}
lv_table_set_cell_value(infoTask, i + 1, 3, buffer);
}
return std::make_unique<Screens::Label>(3, 5, app, infoTask);
}

View file

@ -1,10 +1,10 @@
#include "Twos.h"
#include <lvgl/lvgl.h>
#include <string>
#include <charconv>
#include <array>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <lvgl/lvgl.h>
#include <utility>
#include <vector>
using namespace Pinetime::Applications::Screens;
@ -265,7 +265,9 @@ void Twos::updateGridDisplay(Tile grid[][4]) {
for (int row = 0; row < 4; row++) {
for (int col = 0; col < 4; col++) {
if (grid[row][col].value) {
lv_table_set_cell_value(gridDisplay, row, col, (std::to_string(grid[row][col].value)).c_str());
char buffer[7];
sprintf(buffer, "%d", grid[row][col].value);
lv_table_set_cell_value(gridDisplay, row, col, buffer);
} else {
lv_table_set_cell_value(gridDisplay, row, col, "");
}