Skip to content

Commit 1b9382e

Browse files
committed
define magic numbers
1 parent b43291f commit 1b9382e

File tree

1 file changed

+55
-50
lines changed

1 file changed

+55
-50
lines changed

Source/HamMessenger/HamMessenger.ino

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,11 @@ const char version[] = __DATE__ " " __TIME__;
985985
#include <Adafruit_GFX.h>
986986
#include <Adafruit_SH1106.h>
987987

988+
#define CHAR_WIDTH 6 // number of pixels that one character takes up on the screen
989+
// TODO make this dynamic by getting from the display library
990+
991+
#define MARGIN_LEFT 6 // number of pixels to have as a margin on the left of the display
992+
988993
#define DISPLAY_REFRESH_RATE 100 // 33 is ~30fps | 100 is ~ 10fps
989994
#define DISPLAY_REFRESH_RATE_SCROLL 80 // during testing, i found that anything less than 60 causes performance issues
990995
#define DISPLAY_BLINK_RATE 500
@@ -1078,7 +1083,7 @@ const char version[] = __DATE__ " " __TIME__;
10781083
display.print(text);
10791084

10801085
// Width of text in pixels (6 px per char with default font)
1081-
int textWidth = text.length() * 6;
1086+
int textWidth = text.length() * CHAR_WIDTH;
10821087
int textHeight = 8; // For default font height
10831088

10841089
// Overlay a simulated dimming mask
@@ -1119,7 +1124,7 @@ const char version[] = __DATE__ " " __TIME__;
11191124
display.print("GPS-");
11201125

11211126
//
1122-
int textWidth = 6 * 4; // 6px per char, 4 letters: G P S |
1127+
int textWidth = CHAR_WIDTH * 4; // 6px per char, 4 letters: G P S |
11231128
if (!gpsConnected) {
11241129
// Strikethrough the word "GPS"
11251130
int _x = x; // Cursor X where "G" starts
@@ -1305,8 +1310,8 @@ const char version[] = __DATE__ " " __TIME__;
13051310
if (cursorPosition_X < sizeof(Settings_TypeString100[0]) - 1) {
13061311
Settings_TempDispCharArr[cursorPosition_X] = keyboardInputChar;
13071312
}
1308-
if (cursorPosition_X >= display.width() / 6 - 2) {
1309-
indexPosition_X = (display.width() / 6 - cursorPosition_X) - 2;
1313+
if (cursorPosition_X >= display.width() / CHAR_WIDTH - 2) {
1314+
indexPosition_X = (display.width() / CHAR_WIDTH - cursorPosition_X) - 2;
13101315
}
13111316
}
13121317
break;
@@ -1448,7 +1453,7 @@ const char version[] = __DATE__ " " __TIME__;
14481453
// while scrolling through the settings menu.
14491454
void handleDisplay_PrintValStoredInMem(int SettingsType, int SettingsTypeIndex){
14501455
//
1451-
display.setCursor(cursorPosition_X*6,UI_DISPLAY_ROW_BOTTOM);
1456+
display.setCursor(cursorPosition_X * CHAR_WIDTH,UI_DISPLAY_ROW_BOTTOM);
14521457
//
14531458
switch (SettingsType) {
14541459
case SETTINGS_EDIT_TYPE_ALT1:
@@ -1514,12 +1519,12 @@ const char version[] = __DATE__ " " __TIME__;
15141519
//
15151520
Settings_EditValueSize = sizeof(Settings_TempDispCharArr) - 1;
15161521
//
1517-
display.setCursor(indexPosition_X*6,UI_DISPLAY_ROW_BOTTOM-1);
1522+
display.setCursor(indexPosition_X * CHAR_WIDTH,UI_DISPLAY_ROW_BOTTOM - 1);
15181523
display.print(Settings_TempDispCharArr);
15191524
cursorPosition_X = strlen(Settings_TempDispCharArr);
15201525
//
15211526
if (displayBlink) {
1522-
display.setCursor((cursorPosition_X*6)+(indexPosition_X*6),UI_DISPLAY_ROW_BOTTOM);
1527+
display.setCursor((cursorPosition_X * CHAR_WIDTH) + (indexPosition_X * CHAR_WIDTH),UI_DISPLAY_ROW_BOTTOM);
15231528
display.print('_');
15241529
}
15251530
}
@@ -1729,37 +1734,37 @@ const char version[] = __DATE__ " " __TIME__;
17291734
//display.print(F(">"));
17301735

17311736
// handle header
1732-
display.setCursor(6,UI_DISPLAY_ROW_01);
1737+
display.setCursor(MARGIN_LEFT,UI_DISPLAY_ROW_01);
17331738
display.print(F("[ ]"));
17341739
if(displayBlink || !displayInitialized){
1735-
display.setCursor(6,UI_DISPLAY_ROW_01);
1740+
display.setCursor(MARGIN_LEFT,UI_DISPLAY_ROW_01);
17361741
display.print(F("[ DEBUG ]"));
17371742
}
17381743

17391744
// handle body
1740-
display.setCursor(6,UI_DISPLAY_ROW_02);
1745+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_02);
17411746
display.print(F("Idle:"));
17421747
display.setCursor(36,UI_DISPLAY_ROW_02); // 6 pixels + 6 pixels * 5 chars = 36
17431748
display.print(currentIdleTime);
17441749

1745-
display.setCursor(6,UI_DISPLAY_ROW_03);
1750+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_03);
17461751
display.print(F("Dist:"));
17471752
display.setCursor(36,UI_DISPLAY_ROW_03); // 6 pixels + 6 pixels * 5 chars = 36
17481753
display.print(smartBeaconDistance);
17491754

1750-
display.setCursor(6,UI_DISPLAY_ROW_04);
1755+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_04);
17511756
display.print(F("Loc:"));
17521757
display.setCursor(30,UI_DISPLAY_ROW_04); // 6 pixels + 6 pixels * 4 chars = 30
17531758
display.print((gpsLocationHasChanged ? "True" : "False"));
17541759

1755-
display.setCursor(6,UI_DISPLAY_ROW_05);
1760+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_05);
17561761
display.print(F("Spd:"));
17571762
display.setCursor(30,UI_DISPLAY_ROW_05); // 6 pixels + 6 pixels * 4 chars = 30
17581763
display.print(gps.speed.mph());
17591764

1760-
display.setCursor(66,UI_DISPLAY_ROW_05); // 30 pixels + 6 pixels * 6 chars = 66
1765+
display.setCursor(66, UI_DISPLAY_ROW_05); // 30 pixels + 6 pixels * 6 chars = 66
17611766
display.print(F("hdop:"));
1762-
display.setCursor(96,UI_DISPLAY_ROW_05); // 66 pixels + 6 pixels * 5 chars = 96
1767+
display.setCursor(96, UI_DISPLAY_ROW_05); // 66 pixels + 6 pixels * 5 chars = 96
17631768
display.print(gps.hdop.value());
17641769

17651770

@@ -1818,7 +1823,7 @@ const char version[] = __DATE__ " " __TIME__;
18181823
display.setCursor(x_lat,UI_DISPLAY_ROW_BOTTOM);
18191824
display.print(currentLat); // DDMM.mmN
18201825

1821-
int x_lng = x_lat + (8 * 6) + 5; // 8 letters times 6 pixels wide plus a gap of 3 (0000.00N)
1826+
int x_lng = x_lat + (8 * CHAR_WIDTH) + 5; // 8 letters times 6 pixels wide plus a gap of 5 (0000.00N)
18221827
display.setCursor(x_lng, UI_DISPLAY_ROW_BOTTOM);
18231828
display.print(currentLng); // DDDMM.mmW
18241829
}
@@ -1889,19 +1894,19 @@ const char version[] = __DATE__ " " __TIME__;
18891894
display.print(F(">"));
18901895

18911896
// handle header
1892-
display.setCursor(6,UI_DISPLAY_ROW_01);
1897+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_01);
18931898
display.print(F("[ ]"));
18941899
if(displayBlink || !displayInitialized){
1895-
display.setCursor(6,UI_DISPLAY_ROW_01);
1900+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_01);
18961901
display.print(F("[ MAIN ]"));
18971902
}
18981903

18991904
// handle body
1900-
display.setCursor(6,UI_DISPLAY_ROW_02);
1905+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_02);
19011906
display.print(F("Messages"));
1902-
display.setCursor(6,UI_DISPLAY_ROW_03);
1907+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_03);
19031908
display.print(F("Live Feed"));
1904-
display.setCursor(6,UI_DISPLAY_ROW_04);
1909+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_04);
19051910
display.print(F("Settings"));
19061911

19071912
// display all content from buffer
@@ -2143,19 +2148,19 @@ const char version[] = __DATE__ " " __TIME__;
21432148
display.print(F(">"));
21442149

21452150
// handle header
2146-
display.setCursor(6,UI_DISPLAY_ROW_01);
2151+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_01);
21472152
display.print(F("[ ]"));
21482153
if(displayBlink || !displayInitialized){
2149-
display.setCursor(6,UI_DISPLAY_ROW_01);
2154+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_01);
21502155
display.print(F("[ NEW MESSAGE ]"));
21512156
}
21522157

21532158
// handle body
2154-
display.setCursor(6,UI_DISPLAY_ROW_02);
2159+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_02);
21552160
display.print(MenuItems_Settings_APRS[5]);
2156-
display.setCursor(6,UI_DISPLAY_ROW_03);
2161+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_03);
21572162
display.print(MenuItems_Settings_APRS[6]);
2158-
display.setCursor(6,UI_DISPLAY_ROW_04);
2163+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_04);
21592164
display.print(MenuItems_Settings_APRS[7]);
21602165

21612166
// handle edit field
@@ -2348,17 +2353,17 @@ const char version[] = __DATE__ " " __TIME__;
23482353
display.print(F(">"));
23492354

23502355
// handle question
2351-
display.setCursor(6,UI_DISPLAY_ROW_01);
2356+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_01);
23522357
display.print(F("[ ]"));
23532358
if(displayBlink || !displayInitialized){
2354-
display.setCursor(6,UI_DISPLAY_ROW_01);
2359+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_01);
23552360
display.print(F("[ Save changes? ]"));
23562361
}
23572362

2358-
display.setCursor(6,UI_DISPLAY_ROW_02);
2363+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_02);
23592364
display.print(F("No"));
23602365

2361-
display.setCursor(6,UI_DISPLAY_ROW_03);
2366+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_03);
23622367
display.print(F("Yes"));
23632368

23642369
// display all content from buffer
@@ -2429,25 +2434,25 @@ const char version[] = __DATE__ " " __TIME__;
24292434
display.print(F(">"));
24302435

24312436
// handle header
2432-
display.setCursor(6,UI_DISPLAY_ROW_01);
2437+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_01);
24332438
display.print(F("[ ]"));
24342439
if(displayBlink || !displayInitialized){
2435-
display.setCursor(6,UI_DISPLAY_ROW_01);
2440+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_01);
24362441
display.print(F("[ SETTINGS ]"));
24372442
}
24382443

24392444
// handle body
24402445
int NumOfSettings = ARRAY_SIZE(MenuItems_Settings);
24412446
if (NumOfSettings >= 1) {
2442-
display.setCursor(6,UI_DISPLAY_ROW_02);
2447+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_02);
24432448
display.print(MenuItems_Settings[cursorPosition_Y>2 ? cursorPosition_Y-2 : 0]);
24442449
}
24452450
if (NumOfSettings >= 2) {
2446-
display.setCursor(6,UI_DISPLAY_ROW_03);
2451+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_03);
24472452
display.print(MenuItems_Settings[cursorPosition_Y>2 ? cursorPosition_Y-1 : 1]);
24482453
}
24492454
if (NumOfSettings >= 3) {
2450-
display.setCursor(6,UI_DISPLAY_ROW_04);
2455+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_04);
24512456
display.print(MenuItems_Settings[cursorPosition_Y>2 ? cursorPosition_Y-0 : 2]);
24522457
}
24532458

@@ -2542,25 +2547,25 @@ const char version[] = __DATE__ " " __TIME__;
25422547
display.print(F(">"));
25432548

25442549
// handle header
2545-
display.setCursor(6,UI_DISPLAY_ROW_01);
2550+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_01);
25462551
display.print(F("[ ]"));
25472552
if(displayBlink || !displayInitialized){
2548-
display.setCursor(6,UI_DISPLAY_ROW_01);
2553+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_01);
25492554
display.print(F("[ APRS ]"));
25502555
}
25512556

25522557
// handle body
25532558
int NumOfSettings = ARRAY_SIZE(MenuItems_Settings_APRS);
25542559
if (NumOfSettings >= 1) {
2555-
display.setCursor(6,UI_DISPLAY_ROW_02);
2560+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_02);
25562561
display.print(MenuItems_Settings_APRS[cursorPosition_Y>2 ? cursorPosition_Y-2 : 0]);
25572562
}
25582563
if (NumOfSettings >= 2) {
2559-
display.setCursor(6,UI_DISPLAY_ROW_03);
2564+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_03);
25602565
display.print(MenuItems_Settings_APRS[cursorPosition_Y>2 ? cursorPosition_Y-1 : 1]);
25612566
}
25622567
if (NumOfSettings >= 3) {
2563-
display.setCursor(6,UI_DISPLAY_ROW_04);
2568+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_04);
25642569
display.print(MenuItems_Settings_APRS[cursorPosition_Y>2 ? cursorPosition_Y-0 : 2]);
25652570
}
25662571

@@ -2662,25 +2667,25 @@ const char version[] = __DATE__ " " __TIME__;
26622667
display.print(F(">"));
26632668

26642669
// handle header
2665-
display.setCursor(6,UI_DISPLAY_ROW_01);
2670+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_01);
26662671
display.print(F("[ ]"));
26672672
if(displayBlink || !displayInitialized){
2668-
display.setCursor(6,UI_DISPLAY_ROW_01);
2673+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_01);
26692674
display.print(F("[ GPS ]"));
26702675
}
26712676

26722677
// handle body
26732678
int NumOfSettings = ARRAY_SIZE(MenuItems_Settings_GPS);
26742679
if (NumOfSettings >= 1) {
2675-
display.setCursor(6,UI_DISPLAY_ROW_02);
2680+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_02);
26762681
display.print(MenuItems_Settings_GPS[cursorPosition_Y>2 ? cursorPosition_Y-2 : 0]);
26772682
}
26782683
if (NumOfSettings >= 2) {
2679-
display.setCursor(6,UI_DISPLAY_ROW_03);
2684+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_03);
26802685
display.print(MenuItems_Settings_GPS[cursorPosition_Y>2 ? cursorPosition_Y-1 : 1]);
26812686
}
26822687
if (NumOfSettings >= 3) {
2683-
display.setCursor(6,UI_DISPLAY_ROW_04);
2688+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_04);
26842689
display.print(MenuItems_Settings_GPS[cursorPosition_Y>2 ? cursorPosition_Y-0 : 2]);
26852690
}
26862691

@@ -2782,25 +2787,25 @@ const char version[] = __DATE__ " " __TIME__;
27822787
display.print(F(">"));
27832788

27842789
// handle header
2785-
display.setCursor(6,UI_DISPLAY_ROW_01);
2790+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_01);
27862791
display.print(F("[ ]"));
27872792
if(displayBlink || !displayInitialized){
2788-
display.setCursor(6,UI_DISPLAY_ROW_01);
2793+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_01);
27892794
display.print(F("[ DISPLAY ]"));
27902795
}
27912796

27922797
// handle body
27932798
int NumOfSettings = ARRAY_SIZE(MenuItems_Settings_Display);
27942799
if (NumOfSettings >= 1) {
2795-
display.setCursor(6,UI_DISPLAY_ROW_02);
2800+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_02);
27962801
display.print(MenuItems_Settings_Display[cursorPosition_Y>2 ? cursorPosition_Y-2 : 0]);
27972802
}
27982803
if (NumOfSettings >= 2) {
2799-
display.setCursor(6,UI_DISPLAY_ROW_03);
2804+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_03);
28002805
display.print(MenuItems_Settings_Display[cursorPosition_Y>2 ? cursorPosition_Y-1 : 1]);
28012806
}
28022807
if (NumOfSettings >= 3) {
2803-
display.setCursor(6,UI_DISPLAY_ROW_04);
2808+
display.setCursor(MARGIN_LEFT, UI_DISPLAY_ROW_04);
28042809
display.print(MenuItems_Settings_Display[cursorPosition_Y>2 ? cursorPosition_Y-0 : 2]);
28052810
}
28062811

0 commit comments

Comments
 (0)