| 1060 | #endif |
| 1061 | |
| 1062 | void waitForKeypress(String message) { |
| 1063 | KB().setKeyboardState(NORMAL); |
| 1064 | pocketmage::setCpuSpeed(240); // Boost clock for smooth animation |
| 1065 | |
| 1066 | String msg = message; |
| 1067 | String bottomMsg = "Press any key to continue..."; |
| 1068 | |
| 1069 | u8g2.clearBuffer(); |
| 1070 | const uint16_t dw = u8g2.getDisplayWidth(); |
| 1071 | const uint16_t dh = u8g2.getDisplayHeight(); |
| 1072 | |
| 1073 | int y_offset = 0; |
| 1074 | int x_offset = 0; |
| 1075 | const uint8_t* activeFont; |
| 1076 | |
| 1077 | // --- 1. Find the largest font that fits and calculate offsets --- |
| 1078 | u8g2.setFont(u8g2_font_ncenB14_tf); |
| 1079 | if (u8g2.getUTF8Width(msg.c_str()) < dw) { |
| 1080 | y_offset = 16 + 3; |
| 1081 | x_offset = (dw - u8g2.getUTF8Width(msg.c_str())) / 2; |
| 1082 | activeFont = u8g2_font_ncenB14_tf; |
| 1083 | } |
| 1084 | else { |
| 1085 | u8g2.setFont(u8g2_font_ncenB12_tf); |
| 1086 | if (u8g2.getUTF8Width(msg.c_str()) < dw) { |
| 1087 | y_offset = 16 + 2; |
| 1088 | x_offset = (dw - u8g2.getUTF8Width(msg.c_str())) / 2; |
| 1089 | activeFont = u8g2_font_ncenB12_tf; |
| 1090 | } |
| 1091 | else { |
| 1092 | u8g2.setFont(u8g2_font_ncenB10_tf); |
| 1093 | if (u8g2.getUTF8Width(msg.c_str()) < dw) { |
| 1094 | y_offset = 16 + 1; |
| 1095 | x_offset = (dw - u8g2.getUTF8Width(msg.c_str())) / 2; |
| 1096 | activeFont = u8g2_font_ncenB10_tf; |
| 1097 | } |
| 1098 | else { |
| 1099 | u8g2.setFont(u8g2_font_ncenB08_tf); |
| 1100 | if (u8g2.getUTF8Width(msg.c_str()) < dw) { |
| 1101 | y_offset = 16; |
| 1102 | x_offset = (dw - u8g2.getUTF8Width(msg.c_str())) / 2; |
| 1103 | } |
| 1104 | else { |
| 1105 | y_offset = 16; |
| 1106 | x_offset = dw - u8g2.getUTF8Width(msg.c_str()); |
| 1107 | } |
| 1108 | activeFont = u8g2_font_ncenB08_tf; |
| 1109 | } |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | // --- 2. Slide Up Animation --- |
| 1114 | for (int y = dh; y > 0; y-=2) { |
| 1115 | u8g2.clearBuffer(); |
| 1116 | |
| 1117 | // Draw Main Message |
| 1118 | u8g2.setFont(activeFont); |
| 1119 | u8g2.drawUTF8(x_offset, y + y_offset, msg.c_str()); |
no test coverage detected