Display memory usage reduction #8

Merged
awonak merged 2 commits from refs/pull/8/head into main 2025-06-22 18:44:02 +00:00
6 changed files with 87 additions and 156 deletions
Showing only changes of commit c72b7108e6 - Show all commits

View File

@ -58,11 +58,11 @@ const PROGMEM uint8_t LARGE_FONT[916] U8G2_FONT_SECTION("stk-l") =
#define play_icon_width 14 #define play_icon_width 14
#define play_icon_height 14 #define play_icon_height 14
static const unsigned char play_icon[] = { static const unsigned char play_icon[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x7C, 0x00, 0xFC, 0x00, 0xFC, 0x03, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x7C, 0x00, 0xFC, 0x00, 0xFC, 0x03,
0xFC, 0x0F, 0xFC, 0x0F, 0xFC, 0x03, 0xFC, 0x00, 0x7C, 0x00, 0x3C, 0x00, 0xFC, 0x0F, 0xFC, 0x0F, 0xFC, 0x03, 0xFC, 0x00, 0x7C, 0x00, 0x3C, 0x00,
0x00, 0x00, 0x00, 0x00}; 0x00, 0x00, 0x00, 0x00};
static const unsigned char pause_icon[] = { static const unsigned char pause_icon[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x38, 0x0E, 0x38, 0x0E, 0x38, 0x0E, 0x38, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x38, 0x0E, 0x38, 0x0E, 0x38, 0x0E, 0x38, 0x0E,
0x38, 0x0E, 0x38, 0x0E, 0x38, 0x0E, 0x38, 0x0E, 0x38, 0x0E, 0x38, 0x0E, 0x38, 0x0E, 0x38, 0x0E, 0x38, 0x0E, 0x38, 0x0E, 0x38, 0x0E, 0x38, 0x0E,
0x38, 0x0E, 0x00, 0x00}; 0x38, 0x0E, 0x00, 0x00};
@ -93,23 +93,23 @@ void drawRightAlignedText(const char* text, int y) {
gravity.display.drawStr(drawX, y, text); gravity.display.drawStr(drawX, y, text);
} }
void drawSelectHero() { void drawMainSelection() {
gravity.display.setDrawColor(1); gravity.display.setDrawColor(1);
const int tickSize = 3; const int tickSize = 3;
const int heroWidth = SCREEN_WIDTH/2; const int mainWidth = SCREEN_WIDTH / 2;
const int heroHeight = 49; const int mainHeight = 49;
gravity.display.drawLine(0, 0, tickSize, 0); gravity.display.drawLine(0, 0, tickSize, 0);
gravity.display.drawLine(0, 0, 0, tickSize); gravity.display.drawLine(0, 0, 0, tickSize);
gravity.display.drawLine(heroWidth, 0, heroWidth-tickSize, 0); gravity.display.drawLine(mainWidth, 0, mainWidth - tickSize, 0);
gravity.display.drawLine(heroWidth, 0, heroWidth, tickSize); gravity.display.drawLine(mainWidth, 0, mainWidth, tickSize);
gravity.display.drawLine(heroWidth, heroHeight, heroWidth, heroHeight-tickSize); gravity.display.drawLine(mainWidth, mainHeight, mainWidth, mainHeight - tickSize);
gravity.display.drawLine(heroWidth, heroHeight, heroWidth-tickSize, heroHeight); gravity.display.drawLine(mainWidth, mainHeight, mainWidth - tickSize, mainHeight);
gravity.display.drawLine(0, heroHeight, tickSize, heroHeight); gravity.display.drawLine(0, mainHeight, tickSize, mainHeight);
gravity.display.drawLine(0, heroHeight, 0, heroHeight-tickSize); gravity.display.drawLine(0, mainHeight, 0, mainHeight - tickSize);
gravity.display.setDrawColor(2); gravity.display.setDrawColor(2);
} }
void drawMenuItems(const char* menu_items[], int menu_size) { void drawMenuItems(String menu_items[], int menu_size) {
// Draw menu items // Draw menu items
gravity.display.setFont(TEXT_FONT); gravity.display.setFont(TEXT_FONT);
@ -128,7 +128,7 @@ void drawMenuItems(const char* menu_items[], int menu_size) {
if (app.editing_param) { if (app.editing_param) {
gravity.display.drawBox(boxX, boxY, boxWidth, boxHeight); gravity.display.drawBox(boxX, boxY, boxWidth, boxHeight);
drawSelectHero(); drawMainSelection();
} else { } else {
gravity.display.drawFrame(boxX, boxY, boxWidth, boxHeight); gravity.display.drawFrame(boxX, boxY, boxWidth, boxHeight);
} }
@ -143,7 +143,7 @@ void drawMenuItems(const char* menu_items[], int menu_size) {
for (int i = 0; i < min(menu_size, VISIBLE_MENU_ITEMS); ++i) { for (int i = 0; i < min(menu_size, VISIBLE_MENU_ITEMS); ++i) {
int idx = start_index + i; int idx = start_index + i;
drawRightAlignedText(menu_items[idx], MENU_ITEM_HEIGHT * (i + 1) - 1); drawRightAlignedText(menu_items[idx].c_str(), MENU_ITEM_HEIGHT * (i + 1) - 1);
} }
} }
@ -155,54 +155,52 @@ void DisplayMainPage() {
gravity.display.setFont(TEXT_FONT); gravity.display.setFont(TEXT_FONT);
// Display selected editable value // Display selected editable value
char mainText[8]; String mainText;
const char* subText; String subText;
switch (app.selected_param) { switch (app.selected_param) {
case PARAM_MAIN_TEMPO: case PARAM_MAIN_TEMPO:
// Serial MIDI is too unstable to display bpm in real time. // Serial MIDI is too unstable to display bpm in real time.
if (app.selected_source == Clock::SOURCE_EXTERNAL_MIDI) { if (app.selected_source == Clock::SOURCE_EXTERNAL_MIDI) {
sprintf(mainText, "%s", "EXT"); mainText = F("EXT");
} else { } else {
sprintf(mainText, "%d", gravity.clock.Tempo()); mainText = String(gravity.clock.Tempo());
} }
subText = "BPM"; subText = F("BPM");
break; break;
case PARAM_MAIN_SOURCE: case PARAM_MAIN_SOURCE:
mainText = F("EXT");
switch (app.selected_source) { switch (app.selected_source) {
case Clock::SOURCE_INTERNAL: case Clock::SOURCE_INTERNAL:
sprintf(mainText, "%s", "INT"); mainText = F("INT");
subText = "CLOCK"; subText = F("CLOCK");
break; break;
case Clock::SOURCE_EXTERNAL_PPQN_24: case Clock::SOURCE_EXTERNAL_PPQN_24:
sprintf(mainText, "%s", "EXT"); subText = F("24 PPQN");
subText = "24 PPQN";
break; break;
case Clock::SOURCE_EXTERNAL_PPQN_4: case Clock::SOURCE_EXTERNAL_PPQN_4:
sprintf(mainText, "%s", "EXT"); subText = F("4 PPQN");
subText = "4 PPQN";
break; break;
case Clock::SOURCE_EXTERNAL_MIDI: case Clock::SOURCE_EXTERNAL_MIDI:
sprintf(mainText, "%s", "EXT"); subText = F("MIDI");
subText = "MIDI";
break; break;
} }
break; break;
case PARAM_MAIN_ENCODER_DIR: case PARAM_MAIN_ENCODER_DIR:
sprintf(mainText, "%s", "DIR"); mainText = F("DIR");
subText = app.selected_sub_param == 0 ? "DEFAULT" : "REVERSED"; subText = app.selected_sub_param == 0 ? F("DEFAULT") : F("REVERSED");
break; break;
case PARAM_MAIN_RESET_STATE: case PARAM_MAIN_RESET_STATE:
sprintf(mainText, "%s", "RST"); mainText = F("RST");
subText = app.selected_sub_param == 0 ? "RESET ALL" : "BACK"; subText = app.selected_sub_param == 0 ? F("RESET ALL") : F("BACK");
break; break;
} }
drawCenteredText(mainText, MAIN_TEXT_Y, LARGE_FONT); drawCenteredText(mainText.c_str(), MAIN_TEXT_Y, LARGE_FONT);
drawCenteredText(subText, SUB_TEXT_Y, TEXT_FONT); drawCenteredText(subText.c_str(), SUB_TEXT_Y, TEXT_FONT);
// Draw Main Page menu items // Draw Main Page menu items
const char* menu_items[PARAM_MAIN_LAST] = {"TEMPO", "SOURCE", "ENCODER DIR", "RESET"}; String menu_items[PARAM_MAIN_LAST] = {F("TEMPO"), F("SOURCE"), F("ENCODER DIR"), F("RESET")};
drawMenuItems(menu_items, PARAM_MAIN_LAST); drawMenuItems(menu_items, PARAM_MAIN_LAST);
} }
@ -213,8 +211,8 @@ void DisplayChannelPage() {
gravity.display.setDrawColor(2); gravity.display.setDrawColor(2);
// Display selected editable value // Display selected editable value
char mainText[5]; String mainText;
const char* subText; String subText;
// When editing a param, just show the base value. When not editing show // When editing a param, just show the base value. When not editing show
// the value with cv mod. // the value with cv mod.
@ -224,76 +222,72 @@ void DisplayChannelPage() {
case PARAM_CH_MOD: { case PARAM_CH_MOD: {
int mod_value = ch.getClockMod(withCvMod); int mod_value = ch.getClockMod(withCvMod);
if (mod_value > 1) { if (mod_value > 1) {
sprintf(mainText, "/%d", mod_value); mainText = F("/");
subText = "DIVIDE"; mainText += String(mod_value);
subText = F("DIVIDE");
} else { } else {
sprintf(mainText, "x%d", abs(mod_value)); mainText = F("x");
subText = "MULTIPLY"; mainText += String(abs(mod_value));
subText = F("MULTIPLY");
} }
break; break;
} }
case PARAM_CH_PROB: case PARAM_CH_PROB:
sprintf(mainText, "%d%%", ch.getProbability(withCvMod)); mainText = String(ch.getProbability(withCvMod)) + F("%");
subText = "HIT CHANCE"; subText = F("HIT CHANCE");
break; break;
case PARAM_CH_DUTY: case PARAM_CH_DUTY:
sprintf(mainText, "%d%%", ch.getDutyCycle(withCvMod)); mainText = String(ch.getDutyCycle(withCvMod)) + F("%");
subText = "PULSE WIDTH"; subText = F("PULSE WIDTH");
break; break;
case PARAM_CH_OFFSET: case PARAM_CH_OFFSET:
sprintf(mainText, "%d%%", ch.getOffset(withCvMod)); mainText = String(ch.getOffset(withCvMod)) + F("%");
subText = "SHIFT HIT"; subText = F("SHIFT HIT");
break; break;
case PARAM_CH_CV_SRC: { case PARAM_CH_CV_SRC: {
switch (ch.getCvSource()) { switch (ch.getCvSource()) {
mainText = F("SRC");
case CV_NONE: case CV_NONE:
sprintf(mainText, "SRC"); subText = F("NONE");
subText = "NONE";
break; break;
case CV_1: case CV_1:
sprintf(mainText, "SRC"); subText = F("CV 1");
subText = "CV 1";
break; break;
case CV_2: case CV_2:
sprintf(mainText, "SRC"); subText = F("CV 2");
subText = "CV 2";
break; break;
} }
break; break;
} }
case PARAM_CH_CV_DEST: { case PARAM_CH_CV_DEST: {
switch (ch.getCvDestination()) { switch (ch.getCvDestination()) {
mainText = F("DEST");
case CV_DEST_NONE: case CV_DEST_NONE:
sprintf(mainText, "DEST"); subText = F("NONE");
subText = "NONE";
break; break;
case CV_DEST_MOD: case CV_DEST_MOD:
sprintf(mainText, "DEST"); subText = F("CLOCK MOD");
subText = "CLOCK MOD";
break; break;
case CV_DEST_PROB: case CV_DEST_PROB:
sprintf(mainText, "DEST"); subText = F("PROBABILITY");
subText = "PROBABILITY";
break; break;
case CV_DEST_DUTY: case CV_DEST_DUTY:
sprintf(mainText, "DEST"); subText = F("DUTY CYCLE");
subText = "DUTY CYCLE";
break; break;
case CV_DEST_OFFSET: case CV_DEST_OFFSET:
sprintf(mainText, "DEST"); subText = F("OFFSET");
subText = "OFFSET";
break; break;
} }
break; break;
} }
} }
drawCenteredText(mainText, MAIN_TEXT_Y, LARGE_FONT); drawCenteredText(mainText.c_str(), MAIN_TEXT_Y, LARGE_FONT);
drawCenteredText(subText, SUB_TEXT_Y, TEXT_FONT); drawCenteredText(subText.c_str(), SUB_TEXT_Y, TEXT_FONT);
// Draw Channel Page menu items // Draw Channel Page menu items
const char* menu_items[PARAM_CH_LAST] = { String menu_items[PARAM_CH_LAST] = {
"MOD", "PROBABILITY", "DUTY", "OFFSET", "CV SOURCE", "CV DEST"}; F("MOD"), F("PROBABILITY"), F("DUTY"), F("OFFSET"), F("CV SOURCE"), F("CV DEST")};
drawMenuItems(menu_items, PARAM_CH_LAST); drawMenuItems(menu_items, PARAM_CH_LAST);
} }
@ -320,7 +314,7 @@ void DisplaySelectedChannel() {
if (i == 0) { if (i == 0) {
gravity.display.setBitmapMode(1); gravity.display.setBitmapMode(1);
auto icon = gravity.clock.IsPaused() ? pause_icon : play_icon; auto icon = gravity.clock.IsPaused() ? pause_icon : play_icon;
gravity.display.drawXBM(2, boxY, play_icon_width, play_icon_height, icon); gravity.display.drawXBMP(2, boxY, play_icon_width, play_icon_height, icon);
} else { } else {
gravity.display.setFont(TEXT_FONT); gravity.display.setFont(TEXT_FONT);
gravity.display.setCursor((i * boxWidth) + textOffset, SCREEN_HEIGHT - 3); gravity.display.setCursor((i * boxWidth) + textOffset, SCREEN_HEIGHT - 3);