Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: FLASH size optimisations for B&W. #4827

Merged
merged 6 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified radio/src/bitmaps/128x64/asterisk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified radio/src/bitmaps/128x64/sleep.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions radio/src/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@
#define PACK(__Declaration__) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) )
#endif

#if defined(SIMU)
#define PACK_NOT_SIMU(__Declaration__) __Declaration__
#else
#define PACK_NOT_SIMU(__Declaration__) PACK(__Declaration__)
#endif

#if defined(SIMU)
#define CONVERT_PTR_UINT(x) ((uint32_t)(uint64_t)(x))
#define CONVERT_UINT_PTR(x) ((uint32_t*)(uint64_t)(x))
Expand Down
22 changes: 22 additions & 0 deletions radio/src/gui/128x64/menu_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,28 @@

#include "opentx.h"

const MenuHandler menuTabModel[MENU_MODEL_PAGES_COUNT] = {
{ menuModelSelect, nullptr },
{ menuModelSetup, nullptr },
#if defined(HELI)
{ menuModelHeli, modelHeliEnabled },
#endif
#if defined(FLIGHT_MODES)
{ menuModelFlightModesAll, modelFMEnabled },
#endif
{ menuModelExposAll, nullptr },
{ menuModelMixAll, nullptr },
{ menuModelLimits, nullptr },
{ menuModelCurvesAll, modelCurvesEnabled },
{ menuModelLogicalSwitches, modelLSEnabled },
{ menuModelSpecialFunctions, modelSFEnabled },
#if defined(LUA_MODEL_SCRIPTS)
{ menuModelCustomScripts, modelCustomScriptsEnabled },
#endif
{ menuModelTelemetry, modelTelemetryEnabled },
{ menuModelDisplay, nullptr }
};

uint8_t editDelay(coord_t y, event_t event, uint8_t attr, const char * str, uint8_t delay, uint8_t prec)
{
lcdDrawTextAlignedLeft(y, str);
Expand Down
14 changes: 14 additions & 0 deletions radio/src/gui/128x64/menu_radio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@

#include "opentx.h"

const MenuHandler menuTabGeneral[MENU_RADIO_PAGES_COUNT] = {
#if defined(RADIO_TOOLS)
{ menuRadioTools, nullptr },
#endif
#if defined(SDCARD)
{ menuRadioSdManager, nullptr },
#endif
{ menuRadioSetup, nullptr },
{ menuRadioSpecialFunctions, radioGFEnabled },
{ menuRadioTrainer, radioTrainerEnabled },
{ menuRadioHardware, nullptr },
{ menuRadioVersion, nullptr }
};

void menuRadioSpecialFunctions(event_t event)
{
#if defined(NAVIGATION_X7)
Expand Down
41 changes: 3 additions & 38 deletions radio/src/gui/128x64/menus.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
* GNU General Public License for more details.
*/

#ifndef _MENUS_H_
#define _MENUS_H_
#pragma once

#include "keys.h"
#include "common/stdlcd/menus.h"
Expand Down Expand Up @@ -82,19 +81,7 @@ void menuGhostModuleConfig(event_t event);
extern bool radioGFEnabled();
extern bool radioTrainerEnabled();

static const MenuHandler menuTabGeneral[MENU_RADIO_PAGES_COUNT] = {
#if defined(RADIO_TOOLS)
{ menuRadioTools, nullptr },
#endif
#if defined(SDCARD)
{ menuRadioSdManager, nullptr },
#endif
{ menuRadioSetup, nullptr },
{ menuRadioSpecialFunctions, radioGFEnabled },
{ menuRadioTrainer, radioTrainerEnabled },
{ menuRadioHardware, nullptr },
{ menuRadioVersion, nullptr }
};
extern const MenuHandler menuTabGeneral[MENU_RADIO_PAGES_COUNT];

enum MenuModelIndexes {
MENU_MODEL_SELECT,
Expand Down Expand Up @@ -150,31 +137,9 @@ extern bool modelSFEnabled();
extern bool modelCustomScriptsEnabled();
extern bool modelTelemetryEnabled();

static const MenuHandler menuTabModel[] = {
{ menuModelSelect, nullptr },
{ menuModelSetup, nullptr },
#if defined(HELI)
{ menuModelHeli, modelHeliEnabled },
#endif
#if defined(FLIGHT_MODES)
{ menuModelFlightModesAll, modelFMEnabled },
#endif
{ menuModelExposAll, nullptr },
{ menuModelMixAll, nullptr },
{ menuModelLimits, nullptr },
{ menuModelCurvesAll, modelCurvesEnabled },
{ menuModelLogicalSwitches, modelLSEnabled },
{ menuModelSpecialFunctions, modelSFEnabled },
#if defined(LUA_MODEL_SCRIPTS)
{ menuModelCustomScripts, modelCustomScriptsEnabled },
#endif
{ menuModelTelemetry, modelTelemetryEnabled },
{ menuModelDisplay, nullptr }
};
extern const MenuHandler menuTabModel[MENU_MODEL_PAGES_COUNT];

void menuStatisticsView(event_t event);
void menuStatisticsDebug(event_t event);
void menuStatisticsDebug2(event_t event);
void menuAboutView(event_t event);

#endif // _MENUS_H_
5 changes: 1 addition & 4 deletions radio/src/gui/128x64/model_curve_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,7 @@ void menuModelCurveOne(event_t event)
case EVT_KEY_LONG(KEY_ENTER):
if (menuVerticalPosition > 1) {
killEvents(event);
POPUP_MENU_ADD_ITEM(STR_CURVE_PRESET);
POPUP_MENU_ADD_ITEM(STR_MIRROR);
POPUP_MENU_ADD_ITEM(STR_CLEAR);
POPUP_MENU_START(onCurveOneMenu);
POPUP_MENU_START(onCurveOneMenu, 3, STR_CURVE_PRESET, STR_MIRROR, STR_CLEAR);
}
break;

Expand Down
6 changes: 1 addition & 5 deletions radio/src/gui/128x64/model_failsafe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ void menuModelFailsafe(event_t event)

if (sub == k && !READ_ONLY() && event == EVT_KEY_LONG(KEY_ENTER)) {
killEvents(event);
POPUP_MENU_ADD_ITEM(STR_NONE);
POPUP_MENU_ADD_ITEM(STR_HOLD);
POPUP_MENU_ADD_ITEM(STR_CHANNEL2FAILSAFE);
POPUP_MENU_ADD_ITEM(STR_CHANNELS2FAILSAFE);
POPUP_MENU_START(onFailsafeMenu);
POPUP_MENU_START(onFailsafeMenu, 4, STR_NONE, STR_HOLD, STR_CHANNEL2FAILSAFE, STR_CHANNELS2FAILSAFE);
}

// Channel
Expand Down
7 changes: 1 addition & 6 deletions radio/src/gui/128x64/model_outputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,7 @@ void menuModelLimits(event_t event)
if (sub==k && event==EVT_KEY_FIRST(KEY_ENTER) && !READ_ONLY() && (k != MAX_OUTPUT_CHANNELS) ) {
killEvents(event);
s_editMode = 0;
POPUP_MENU_ADD_ITEM(STR_EDIT);
POPUP_MENU_ADD_ITEM(STR_RESET);
POPUP_MENU_ADD_ITEM(STR_COPY_TRIMS_TO_OFS);
POPUP_MENU_ADD_ITEM(STR_COPY_STICKS_TO_OFS);
POPUP_MENU_ADD_ITEM(STR_COPY_MIN_MAX_TO_OUTPUTS);
POPUP_MENU_START(onLimitsMenu);
POPUP_MENU_START(onLimitsMenu, 5, STR_EDIT, STR_RESET, STR_COPY_TRIMS_TO_OFS, STR_COPY_STICKS_TO_OFS, STR_COPY_MIN_MAX_TO_OUTPUTS);
}

if (k == MAX_OUTPUT_CHANNELS) {
Expand Down
5 changes: 1 addition & 4 deletions radio/src/gui/128x64/model_telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,7 @@ void menuModelTelemetry(event_t event)
s_currIdx = index;
if (event == EVT_KEY_LONG(KEY_ENTER)) {
killEvents(event);
POPUP_MENU_ADD_ITEM(STR_EDIT);
POPUP_MENU_ADD_ITEM(STR_COPY);
POPUP_MENU_ADD_ITEM(STR_DELETE);
POPUP_MENU_START(onSensorMenu);
POPUP_MENU_START(onSensorMenu, 3, STR_EDIT, STR_COPY, STR_DELETE);
}
else if (event == EVT_KEY_BREAK(KEY_ENTER)) {
pushMenu(menuModelSensor);
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/128x64/popups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const unsigned char ASTERISK_BITMAP[] = {
void drawAlertBox(const char * title, const char * text, const char * action)
{
lcdClear();
lcdDraw1bitBitmap(2, 0, ASTERISK_BITMAP, 0, 0);
lcdDraw1bitBitmap(2, 2, ASTERISK_BITMAP, 0, 0);

#define MESSAGE_LCD_OFFSET 6*FW

Expand Down
4 changes: 2 additions & 2 deletions radio/src/gui/128x64/startup_shutdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include "opentx.h"


#define SLEEP_BITMAP_WIDTH 60
#define SLEEP_BITMAP_HEIGHT 60
#define SLEEP_BITMAP_WIDTH 42
#define SLEEP_BITMAP_HEIGHT 47

const unsigned char bmp_sleep[] = {
#include "sleep.lbm"
Expand Down
82 changes: 28 additions & 54 deletions radio/src/gui/128x64/view_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
#define TRIM_LV_X 3
#define TRIM_RV_X (LCD_W-4)
#define TRIM_RH_X (LCD_W-TRIM_LEN-5)
#define TRIM_LH_NEG (TRIM_LH_X+1*FW)
#define TRIM_LH_POS (TRIM_LH_X-4*FW)
#define TRIM_RH_NEG (TRIM_RH_X+1*FW)
#define TRIM_RH_POS (TRIM_RH_X-4*FW)
#define TRIM_LH_NEG (TRIM_LH_X+3*FW+1)
#define TRIM_LH_POS (TRIM_LH_X-4*FW+3)
#define TRIM_RH_NEG (TRIM_RH_X+3*FW+1)
#define TRIM_RH_POS (TRIM_RH_X-4*FW+3)
#define RSSSI_X (30)
#define RSSSI_Y (31)
#define RSSI_MAX 105
Expand Down Expand Up @@ -148,12 +148,13 @@ void doMainScreenGraphics()

void displayTrims(uint8_t phase)
{
bool squareMarker = (keysGetMaxTrims() <= 4);
for (uint8_t i = 0; i < keysGetMaxTrims(); i++) {
#if defined(SURFACE_RADIO)
static coord_t x[] = {TRIM_RH_X, TRIM_LH_X, TRIM_RV_X, TRIM_LV_X, TRIM_LV_X};
static uint8_t x[] = {TRIM_RH_X, TRIM_LH_X, TRIM_RV_X, TRIM_LV_X, TRIM_LV_X};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the issue in coord_t type definition ? Need to try it by I feel it should be uint8_t for max(LCD_W, LCD_H) < 256

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coord_t can be outside screen bounds (negative and greater than width/height) so it can't be an unsigned value and 8 bits isn't enough.

I tried changing the type for coord_t to int16_t; but this increased code size by ~1K 😕

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, not sure why it should allow off screen values tho, but thats probably opening another can of worm

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the trims are in the right place and all on the MT12... if I were to nitpick, there seems to be a (not related to this PR as it's present in main code also) issue with the trim 'knob' reaching the end at more like 80% travel... whereas on colorlcd the knob stops moving exactly at end of trim travel. This is without any extended trims, etc... new blank model.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@3djc Let me know if you need/want time to look into the coord_t/uint8_t change further... otherwise I think this is ready to merge.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I were to nitpick, there seems to be a (not related to this PR as it's present in main code also) issue with the trim 'knob' reaching the end at more like 80% travel... whereas on colorlcd the knob stops moving exactly at end of trim travel.

Fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on MT12 and Pocket. Thanks :)

static uint8_t vert[] = {0, 0, 1, 1, 1};
#else
static coord_t x[] = {TRIM_LH_X, TRIM_LV_X, TRIM_RV_X, TRIM_RH_X, TRIM_LH_X, TRIM_LV_X, TRIM_RH_X, TRIM_RV_X};
static uint8_t x[] = {TRIM_LH_X, TRIM_LV_X, TRIM_RV_X, TRIM_RH_X, TRIM_LH_X, TRIM_LV_X, TRIM_RH_X, TRIM_RV_X};
static uint8_t vert[] = {0, 1, 1, 0, 0, 1, 0, 1};
#endif
coord_t xm, ym;
Expand All @@ -180,11 +181,14 @@ void displayTrims(uint8_t phase)
val /= 4;
}

uint8_t nx, ny;
LcdFlags nFlg = TINSIZE;

if (vert[i]) {
ym = 31;
if (!getPixel(xm, ym))
lcdDrawSolidVerticalLine(xm, ym - TRIM_LEN, TRIM_LEN * 2 + 1);
if (keysGetMaxTrims() <= 4) {
if (squareMarker) {
if (i != 2 || !g_model.thrTrim) {
lcdDrawSolidVerticalLine(xm - 1, ym - 1, 3);
lcdDrawSolidVerticalLine(xm + 1, ym - 1, 3);
Expand All @@ -200,14 +204,6 @@ void displayTrims(uint8_t phase)
if (exttrim) {
lcdDrawSolidHorizontalLine(xm - 1, ym, 3);
}
if (g_model.displayTrims != DISPLAY_TRIMS_NEVER && dir != 0) {
if (g_model.displayTrims == DISPLAY_TRIMS_ALWAYS ||
(trimsDisplayTimer > 0 && (trimsDisplayMask & (1 << i)))) {
lcdDrawNumber(dir > 0 ? 12 : 40, xm - 2, -abs(dir),
TINSIZE | VERTICAL);
}
}
lcdDrawSquare(xm - 3, ym - 3, 7, att);
}
else {
ym -= val;
Expand All @@ -221,20 +217,16 @@ void displayTrims(uint8_t phase)
lcdDrawSolidVerticalLine(xm + 2, ym - 1, 3);
lcdDrawSolidVerticalLine(xm + 3, ym - 2, 5);
}
if (g_model.displayTrims != DISPLAY_TRIMS_NEVER && dir != 0 && i < 4) {
if (g_model.displayTrims == DISPLAY_TRIMS_ALWAYS ||
(trimsDisplayTimer > 0 && (trimsDisplayMask & (1 << i)))) {
lcdDrawNumber(dir > 0 ? 12 : 40, xm - 2, -abs(dir),
TINSIZE | VERTICAL);
}
}
}
nx = dir > 0 ? 12 : 52;
ny = xm - 2;
nFlg |= VERTICAL;
}
else {
ym = 60;
if (!getPixel(xm, ym))
lcdDrawSolidHorizontalLine(xm - TRIM_LEN, ym, TRIM_LEN * 2 + 1);
if (keysGetMaxTrims() <= 4) {
if (squareMarker) {
lcdDrawSolidHorizontalLine(xm - 1, ym - 1, 3);
lcdDrawSolidHorizontalLine(xm - 1, ym + 1, 3);
xm += val;
Expand All @@ -248,16 +240,6 @@ void displayTrims(uint8_t phase)
if (exttrim) {
lcdDrawSolidVerticalLine(xm, ym - 1, 3);
}
if (g_model.displayTrims != DISPLAY_TRIMS_NEVER && dir != 0) {
if (g_model.displayTrims == DISPLAY_TRIMS_ALWAYS ||
(trimsDisplayTimer > 0 && (trimsDisplayMask & (1 << i)))) {
lcdDrawNumber(
(stickIndex == 0 ? (dir > 0 ? TRIM_LH_POS : TRIM_LH_NEG)
: (dir > 0 ? TRIM_RH_POS : TRIM_RH_NEG)),
ym - 2, -abs(dir), TINSIZE);
}
}
lcdDrawSquare(xm - 3, ym - 3, 7, att);
}
else {
xm += val;
Expand All @@ -271,18 +253,19 @@ void displayTrims(uint8_t phase)
lcdDrawSolidHorizontalLine(xm - 1, ym - 2, 3);
lcdDrawSolidHorizontalLine(xm - 2, ym - 3, 5);
}
if (g_model.displayTrims != DISPLAY_TRIMS_NEVER && dir != 0 && i < 4) {
if (g_model.displayTrims == DISPLAY_TRIMS_ALWAYS ||
(trimsDisplayTimer > 0 && (trimsDisplayMask & (1 << i)))) {
lcdDrawNumber(
(xm < LCD_W / 2 ? (dir > 0 ? TRIM_LH_POS : TRIM_LH_NEG)
: (dir > 0 ? TRIM_RH_POS : TRIM_RH_NEG)),
ym - 2, -abs(dir), TINSIZE);
}
}
}
nx = xm < LCD_W / 2 ? (dir > 0 ? TRIM_LH_POS : TRIM_LH_NEG)
: (dir > 0 ? TRIM_RH_POS : TRIM_RH_NEG);
ny = ym - 2;
}

if (g_model.displayTrims != DISPLAY_TRIMS_NEVER && dir != 0 && i < 4) {
if (g_model.displayTrims == DISPLAY_TRIMS_ALWAYS ||
(trimsDisplayTimer > 0 && (trimsDisplayMask & (1 << i)))) {
lcdDrawNumber(nx, ny, -abs(dir), nFlg | (dir < 0 ? RIGHT : 0));
}
}
if (squareMarker)
lcdDrawSquare(xm - 3, ym - 3, 7, att);
}
}

Expand Down Expand Up @@ -388,12 +371,7 @@ void onMainViewMenu(const char * result)
pushModelNotes();
}
else if (result == STR_RESET_SUBMENU) {
POPUP_MENU_ADD_ITEM(STR_RESET_FLIGHT);
POPUP_MENU_ADD_ITEM(STR_RESET_TIMER1);
POPUP_MENU_ADD_ITEM(STR_RESET_TIMER2);
POPUP_MENU_ADD_ITEM(STR_RESET_TIMER3);
POPUP_MENU_ADD_ITEM(STR_RESET_TELEMETRY);
POPUP_MENU_START(onMainViewMenu);
POPUP_MENU_START(onMainViewMenu, 5, STR_RESET_FLIGHT, STR_RESET_TIMER1, STR_RESET_TIMER2, STR_RESET_TIMER3, STR_RESET_TELEMETRY);
}
else if (result == STR_RESET_TELEMETRY) {
telemetryReset();
Expand Down Expand Up @@ -474,11 +452,7 @@ void menuMainView(event_t event)
POPUP_MENU_ADD_ITEM(STR_VIEW_NOTES);
}

POPUP_MENU_ADD_ITEM(STR_RESET_SUBMENU);

POPUP_MENU_ADD_ITEM(STR_STATISTICS);
POPUP_MENU_ADD_ITEM(STR_ABOUT_US);
POPUP_MENU_START(onMainViewMenu);
POPUP_MENU_START(onMainViewMenu, 3, STR_RESET_SUBMENU, STR_STATISTICS, STR_ABOUT_US);
break;

#if defined(EVT_KEY_LAST_MENU)
Expand Down
5 changes: 1 addition & 4 deletions radio/src/gui/212x64/model_curve_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,7 @@ void menuModelCurveOne(event_t event)
case EVT_KEY_LONG(KEY_ENTER):
if (menuVerticalPosition > 1) {
killEvents(event);
POPUP_MENU_ADD_ITEM(STR_CURVE_PRESET);
POPUP_MENU_ADD_ITEM(STR_MIRROR);
POPUP_MENU_ADD_ITEM(STR_CLEAR);
POPUP_MENU_START(onCurveOneMenu);
POPUP_MENU_START(onCurveOneMenu, 3, STR_CURVE_PRESET, STR_MIRROR, STR_CLEAR);
}
break;

Expand Down
4 changes: 1 addition & 3 deletions radio/src/gui/212x64/model_gvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ void menuModelGVars(event_t event)

if ((menuHorizontalPosition<0 || !modelFMEnabled()) && event==EVT_KEY_LONG(KEY_ENTER)) {
killEvents(event);
POPUP_MENU_ADD_ITEM(STR_EDIT);
POPUP_MENU_ADD_ITEM(STR_CLEAR);
POPUP_MENU_START(onGVARSMenu);
POPUP_MENU_START(onGVARSMenu, 2, STR_EDIT, STR_CLEAR);
}
}
6 changes: 1 addition & 5 deletions radio/src/gui/212x64/model_outputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,7 @@ void menuModelLimits(event_t event)
putsChn(0, y, k+1, (sub==k && menuHorizontalPosition < 0) ? INVERS : 0);
if (sub==k && menuHorizontalPosition < 0 && event==EVT_KEY_LONG(KEY_ENTER) && !READ_ONLY()) {
killEvents(event);
POPUP_MENU_ADD_ITEM(STR_RESET);
POPUP_MENU_ADD_ITEM(STR_COPY_TRIMS_TO_OFS);
POPUP_MENU_ADD_ITEM(STR_COPY_STICKS_TO_OFS);
POPUP_MENU_ADD_ITEM(STR_COPY_MIN_MAX_TO_OUTPUTS);
POPUP_MENU_START(onLimitsMenu);
POPUP_MENU_START(onLimitsMenu, 4, STR_RESET, STR_COPY_TRIMS_TO_OFS, STR_COPY_STICKS_TO_OFS, STR_COPY_MIN_MAX_TO_OUTPUTS);
}

for (int j=0; j<ITEM_LIMITS_COUNT; j++) {
Expand Down
Loading