1
0
forked from me/IronOS

Refactor font style to be set when printing

Removes the font setting as a global state.
This commit is contained in:
Alvin Wong
2021-03-21 21:46:12 +08:00
parent a9ddcd1d9b
commit b2f9eab7fb
5 changed files with 224 additions and 262 deletions

View File

@@ -43,20 +43,19 @@ static uint16_t min(uint16_t a, uint16_t b) {
else
return a;
}
void warnUser(const char *warning, const int font, const int timeout) {
OLED::setFont(font);
void warnUser(const char *warning, const FontStyle font, const int timeout) {
OLED::clearScreen();
OLED::setCursor(0, 0);
OLED::print(warning);
OLED::print(warning, font);
OLED::refresh();
waitForButtonPressOrTimeout(timeout);
}
void printVoltage() {
uint32_t volt = getInputVoltageX10(systemSettings.voltageDiv, 0);
OLED::printNumber(volt / 10, 2);
OLED::print(SymbolDot);
OLED::printNumber(volt % 10, 1);
OLED::printNumber(volt / 10, 2, FontStyle::SMALL);
OLED::print(SymbolDot, FontStyle::SMALL);
OLED::printNumber(volt % 10, 1, FontStyle::SMALL);
}
void GUIDelay() {
// Called in all UI looping tasks,
@@ -65,7 +64,7 @@ void GUIDelay() {
// prevent the movement detection from running
osDelay(50);
}
void gui_drawTipTemp(bool symbol) {
void gui_drawTipTemp(bool symbol, const FontStyle font) {
// Draw tip temp handling unit conversion & tolerance near setpoint
uint32_t Temp = 0;
if (systemSettings.temperatureInF) {
@@ -74,9 +73,9 @@ void gui_drawTipTemp(bool symbol) {
Temp = TipThermoModel::getTipInC();
}
OLED::printNumber(Temp, 3); // Draw the tip temp out
OLED::printNumber(Temp, 3, font); // Draw the tip temp out
if (symbol) {
if (OLED::getFont() == 0) {
if (font == FontStyle::LARGE) {
// Big font, can draw nice symbols
if (systemSettings.temperatureInF)
OLED::drawSymbol(0);
@@ -85,9 +84,9 @@ void gui_drawTipTemp(bool symbol) {
} else {
// Otherwise fall back to chars
if (systemSettings.temperatureInF)
OLED::print(SymbolDegF);
OLED::print(SymbolDegF, FontStyle::SMALL);
else
OLED::print(SymbolDegC);
OLED::print(SymbolDegC, FontStyle::SMALL);
}
}
}
@@ -108,15 +107,13 @@ static bool checkVoltageForExit() {
OLED::clearScreen();
OLED::setCursor(0, 0);
if (systemSettings.detailedSoldering) {
OLED::setFont(1);
OLED::print(UndervoltageString);
OLED::print(UndervoltageString, FontStyle::SMALL);
OLED::setCursor(0, 8);
OLED::print(InputVoltageString);
OLED::print(InputVoltageString, FontStyle::SMALL);
printVoltage();
OLED::print(SymbolVolts);
OLED::print(SymbolVolts, FontStyle::SMALL);
} else {
OLED::setFont(0);
OLED::print(UVLOWarningString);
OLED::print(UVLOWarningString, FontStyle::LARGE);
}
OLED::refresh();
@@ -140,14 +137,12 @@ static void gui_drawBatteryIcon() {
V = V / 10;
if (V >= 10) {
int16_t xPos = OLED::getCursorX();
OLED::setFont(1);
OLED::printNumber(V / 10, 1);
OLED::printNumber(V / 10, 1, FontStyle::SMALL);
OLED::setCursor(xPos, 8);
OLED::printNumber(V % 10, 1);
OLED::setFont(0);
OLED::printNumber(V % 10, 1, FontStyle::SMALL);
OLED::setCursor(xPos + 12, 0); // need to reset this as if we drew a wide char
} else {
OLED::printNumber(V, 1);
OLED::printNumber(V, 1, FontStyle::LARGE);
}
return;
}
@@ -185,7 +180,6 @@ static void gui_solderingTempAdjust() {
for (;;) {
OLED::setCursor(0, 0);
OLED::clearScreen();
OLED::setFont(0);
buttons = getButtonState();
if (buttons) {
if (waitForRelease) {
@@ -264,27 +258,27 @@ static void gui_solderingTempAdjust() {
#else
if (OLED::getRotation()) {
#endif
OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolPlus : SymbolMinus);
OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolPlus : SymbolMinus, FontStyle::LARGE);
} else {
OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolMinus : SymbolPlus);
OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolMinus : SymbolPlus, FontStyle::LARGE);
}
OLED::print(SymbolSpace);
OLED::printNumber(systemSettings.SolderingTemp, 3);
OLED::print(SymbolSpace, FontStyle::LARGE);
OLED::printNumber(systemSettings.SolderingTemp, 3, FontStyle::LARGE);
if (systemSettings.temperatureInF)
OLED::drawSymbol(0);
else {
OLED::drawSymbol(1);
}
OLED::print(SymbolSpace);
OLED::print(SymbolSpace, FontStyle::LARGE);
#ifdef OLED_FLIP
if (!OLED::getRotation()) {
#else
if (OLED::getRotation()) {
#endif
OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolMinus : SymbolPlus);
OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolMinus : SymbolPlus, FontStyle::LARGE);
} else {
OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolPlus : SymbolMinus);
OLED::print(systemSettings.ReverseButtonTempChangeEnabled ? SymbolPlus : SymbolMinus, FontStyle::LARGE);
}
OLED::refresh();
GUIDelay();
@@ -332,24 +326,22 @@ static int gui_SolderingSleepingMode(bool stayOff, bool autoStarted) {
OLED::clearScreen();
OLED::setCursor(0, 0);
if (systemSettings.detailedSoldering) {
OLED::setFont(1);
OLED::print(SleepingAdvancedString);
OLED::print(SleepingAdvancedString, FontStyle::SMALL);
OLED::setCursor(0, 8);
OLED::print(SleepingTipAdvancedString);
OLED::printNumber(tipTemp, 3);
OLED::print(SleepingTipAdvancedString, FontStyle::SMALL);
OLED::printNumber(tipTemp, 3, FontStyle::SMALL);
if (systemSettings.temperatureInF)
OLED::print(SymbolDegF);
OLED::print(SymbolDegF, FontStyle::SMALL);
else {
OLED::print(SymbolDegC);
OLED::print(SymbolDegC, FontStyle::SMALL);
}
OLED::print(SymbolSpace);
OLED::print(SymbolSpace, FontStyle::SMALL);
printVoltage();
OLED::print(SymbolVolts);
OLED::print(SymbolVolts, FontStyle::SMALL);
} else {
OLED::setFont(0);
OLED::print(SleepingSimpleString);
OLED::printNumber(tipTemp, 3);
OLED::print(SleepingSimpleString, FontStyle::LARGE);
OLED::printNumber(tipTemp, 3, FontStyle::LARGE);
if (systemSettings.temperatureInF)
OLED::drawSymbol(0);
else {
@@ -379,11 +371,11 @@ static void display_countdown(int sleepThres) {
int lastEventTime = lastButtonTime < lastMovementTime ? lastMovementTime : lastButtonTime;
TickType_t downCount = sleepThres - xTaskGetTickCount() + lastEventTime;
if (downCount > (99 * TICKS_SECOND)) {
OLED::printNumber(downCount / 60000 + 1, 2);
OLED::print(SymbolMinutes);
OLED::printNumber(downCount / 60000 + 1, 2, FontStyle::SMALL);
OLED::print(SymbolMinutes, FontStyle::SMALL);
} else {
OLED::printNumber(downCount / 1000 + 1, 2);
OLED::print(SymbolSeconds);
OLED::printNumber(downCount / 1000 + 1, 2, FontStyle::SMALL);
OLED::print(SymbolSeconds, FontStyle::SMALL);
}
}
static uint32_t getSleepTimeout() {
@@ -470,7 +462,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
case BUTTON_BOTH_LONG:
// Unlock buttons
buttonsLocked = false;
warnUser(UnlockingKeysString, 0, TICKS_SECOND);
warnUser(UnlockingKeysString, FontStyle::LARGE, TICKS_SECOND);
break;
case BUTTON_F_LONG:
// if boost mode is enabled turn it on
@@ -484,7 +476,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
case BUTTON_F_SHORT:
case BUTTON_B_SHORT:
// Do nothing and display a lock warming
warnUser(WarningKeysLockedString, 0, TICKS_SECOND / 2);
warnUser(WarningKeysLockedString, FontStyle::LARGE, TICKS_SECOND / 2);
break;
default:
break;
@@ -519,7 +511,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
if (systemSettings.lockingMode != 0) {
// Lock buttons
buttonsLocked = true;
warnUser(LockingKeysString, 0, TICKS_SECOND);
warnUser(LockingKeysString, FontStyle::LARGE, TICKS_SECOND);
}
break;
default:
@@ -529,47 +521,45 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
// else we update the screen information
OLED::setCursor(0, 0);
OLED::clearScreen();
OLED::setFont(0);
// Draw in the screen details
if (systemSettings.detailedSoldering) {
OLED::setFont(1);
OLED::print(SolderingAdvancedPowerPrompt); // Power:
OLED::printNumber(x10WattHistory.average() / 10, 2);
OLED::print(SymbolDot);
OLED::printNumber(x10WattHistory.average() % 10, 1);
OLED::print(SymbolWatts);
OLED::print(SolderingAdvancedPowerPrompt, FontStyle::SMALL); // Power:
OLED::printNumber(x10WattHistory.average() / 10, 2, FontStyle::SMALL);
OLED::print(SymbolDot, FontStyle::SMALL);
OLED::printNumber(x10WattHistory.average() % 10, 1, FontStyle::SMALL);
OLED::print(SymbolWatts, FontStyle::SMALL);
if (systemSettings.sensitivity && systemSettings.SleepTime) {
OLED::print(SymbolSpace);
OLED::print(SymbolSpace, FontStyle::SMALL);
display_countdown(getSleepTimeout());
}
OLED::setCursor(0, 8);
OLED::print(SleepingTipAdvancedString);
gui_drawTipTemp(true);
OLED::print(SleepingTipAdvancedString, FontStyle::SMALL);
gui_drawTipTemp(true, FontStyle::SMALL);
if (boostModeOn) {
OLED::print(SymbolPlus);
OLED::print(SymbolPlus, FontStyle::SMALL);
} else {
OLED::print(SymbolSpace);
OLED::print(SymbolSpace, FontStyle::SMALL);
}
printVoltage();
OLED::print(SymbolVolts);
OLED::print(SymbolVolts, FontStyle::SMALL);
} else {
// We switch the layout direction depending on the orientation of the oled
if (OLED::getRotation()) {
// battery
gui_drawBatteryIcon();
OLED::print(SymbolSpace); // Space out gap between battery <-> temp
gui_drawTipTemp(true); // Draw current tip temp
OLED::print(SymbolSpace, FontStyle::LARGE); // Space out gap between battery <-> temp
gui_drawTipTemp(true, FontStyle::LARGE); // Draw current tip temp
// We draw boost arrow if boosting, or else gap temp <-> heat
// indicator
if (boostModeOn)
OLED::drawSymbol(2);
else
OLED::print(SymbolSpace);
OLED::print(SymbolSpace, FontStyle::LARGE);
// Draw heating/cooling symbols
OLED::drawHeatSymbol(X10WattsToPWM(x10WattHistory.average()));
@@ -581,10 +571,10 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
if (boostModeOn)
OLED::drawSymbol(2);
else
OLED::print(SymbolSpace);
gui_drawTipTemp(true); // Draw current tip temp
OLED::print(SymbolSpace, FontStyle::LARGE);
gui_drawTipTemp(true, FontStyle::LARGE); // Draw current tip temp
OLED::print(SymbolSpace); // Space out gap between battery <-> temp
OLED::print(SymbolSpace, FontStyle::LARGE); // Space out gap between battery <-> temp
gui_drawBatteryIcon();
}
@@ -627,47 +617,46 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
void showDebugMenu(void) {
uint8_t screen = 0;
ButtonState b;
OLED::setFont(1); // small font
for (;;) {
OLED::clearScreen(); // Ensure the buffer starts clean
OLED::setCursor(0, 0); // Position the cursor at the 0,0 (top left)
OLED::print(SymbolVersionNumber); // Print version number
OLED::setCursor(0, 8); // second line
OLED::print(DebugMenu[screen]);
OLED::clearScreen(); // Ensure the buffer starts clean
OLED::setCursor(0, 0); // Position the cursor at the 0,0 (top left)
OLED::print(SymbolVersionNumber, FontStyle::SMALL); // Print version number
OLED::setCursor(0, 8); // second line
OLED::print(DebugMenu[screen], FontStyle::SMALL);
switch (screen) {
case 0: // Just prints date
break;
case 1:
// High water mark for GUI
OLED::printNumber(uxTaskGetStackHighWaterMark(GUITaskHandle), 5);
OLED::printNumber(uxTaskGetStackHighWaterMark(GUITaskHandle), 5, FontStyle::SMALL);
break;
case 2:
// High water mark for the Movement task
OLED::printNumber(uxTaskGetStackHighWaterMark(MOVTaskHandle), 5);
OLED::printNumber(uxTaskGetStackHighWaterMark(MOVTaskHandle), 5, FontStyle::SMALL);
break;
case 3:
// High water mark for the PID task
OLED::printNumber(uxTaskGetStackHighWaterMark(PIDTaskHandle), 5);
OLED::printNumber(uxTaskGetStackHighWaterMark(PIDTaskHandle), 5, FontStyle::SMALL);
break;
case 4:
// system up time stamp
OLED::printNumber(xTaskGetTickCount() / TICKS_100MS, 5);
OLED::printNumber(xTaskGetTickCount() / TICKS_100MS, 5, FontStyle::SMALL);
break;
case 5:
// Movement time stamp
OLED::printNumber(lastMovementTime / TICKS_100MS, 5);
OLED::printNumber(lastMovementTime / TICKS_100MS, 5, FontStyle::SMALL);
break;
case 6:
// Raw Tip
{ OLED::printNumber(TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0), true), 6); }
{ OLED::printNumber(TipThermoModel::convertTipRawADCTouV(getTipRawTemp(0), true), 6, FontStyle::SMALL); }
break;
case 7:
// Temp in C
OLED::printNumber(TipThermoModel::getTipInC(), 5);
OLED::printNumber(TipThermoModel::getTipInC(), 5, FontStyle::SMALL);
break;
case 8:
// Handle Temp
OLED::printNumber(getHandleTemperature(), 3);
OLED::printNumber(getHandleTemperature(), 3, FontStyle::SMALL);
break;
case 9:
// Voltage input
@@ -675,12 +664,12 @@ void showDebugMenu(void) {
break;
case 10:
// Print PCB ID number
OLED::printNumber(DetectedAccelerometerVersion, 2);
OLED::printNumber(DetectedAccelerometerVersion, 2, FontStyle::SMALL);
break;
case 11:
// Power negotiation status
if (getIsPoweredByDCIN()) {
OLED::printNumber(0, 1);
OLED::printNumber(0, 1, FontStyle::SMALL);
} else {
// We are not powered via DC, so want to display the appropriate state for PD or QC
bool poweredbyPD = false;
@@ -694,16 +683,16 @@ void showDebugMenu(void) {
}
#endif
if (poweredbyPD) {
OLED::printNumber(2, 1);
OLED::printNumber(2, 1, FontStyle::SMALL);
} else {
OLED::printNumber(1, 1);
OLED::printNumber(1, 1, FontStyle::SMALL);
}
}
break;
case 12:
// Max deg C limit
OLED::printNumber(TipThermoModel::getTipMaxInC(), 3);
OLED::printNumber(TipThermoModel::getTipMaxInC(), 3, FontStyle::SMALL);
break;
default:
break;
@@ -726,9 +715,9 @@ void showWarnings() {
if (settingsWereReset) {
if (SettingsResetMessage[0] == '\x01') { // `\x01` is used as newline.
// Empty first line means that this uses large font (for CJK).
warnUser(SettingsResetMessage + 1, 0, 10 * TICKS_SECOND);
warnUser(SettingsResetMessage + 1, FontStyle::LARGE, 10 * TICKS_SECOND);
} else {
warnUser(SettingsResetMessage, 1, 10 * TICKS_SECOND);
warnUser(SettingsResetMessage, FontStyle::SMALL, 10 * TICKS_SECOND);
}
}
#ifndef NO_WARN_MISSING
@@ -743,7 +732,7 @@ void showWarnings() {
if (systemSettings.accelMissingWarningCounter < 2) {
systemSettings.accelMissingWarningCounter++;
saveSettings();
warnUser(NoAccelerometerMessage, 1, 10 * TICKS_SECOND);
warnUser(NoAccelerometerMessage, FontStyle::SMALL, 10 * TICKS_SECOND);
}
}
#ifdef POW_PD
@@ -752,7 +741,7 @@ void showWarnings() {
if (systemSettings.pdMissingWarningCounter < 2) {
systemSettings.pdMissingWarningCounter++;
saveSettings();
warnUser(NoPowerDeliveryMessage, 1, 10 * TICKS_SECOND);
warnUser(NoPowerDeliveryMessage, FontStyle::SMALL, 10 * TICKS_SECOND);
}
}
#endif
@@ -802,7 +791,6 @@ void startGUITask(void const *argument __unused) {
ButtonState buttons = getButtonState();
if (buttons != BUTTON_NONE) {
OLED::setDisplayState(OLED::DisplayState::ON);
OLED::setFont(0);
}
if (tempWarningState == 2)
buttons = BUTTON_F_SHORT;
@@ -860,22 +848,20 @@ void startGUITask(void const *argument __unused) {
OLED::clearScreen();
OLED::setCursor(0, 0);
if (systemSettings.detailedIDLE) {
OLED::setFont(1);
if (tipTemp > tipDisconnectedThres) {
OLED::print(TipDisconnectedString);
OLED::print(TipDisconnectedString, FontStyle::SMALL);
} else {
OLED::print(IdleTipString);
gui_drawTipTemp(false);
OLED::print(IdleSetString);
OLED::printNumber(systemSettings.SolderingTemp, 3);
OLED::print(IdleTipString, FontStyle::SMALL);
gui_drawTipTemp(false, FontStyle::SMALL);
OLED::print(IdleSetString, FontStyle::SMALL);
OLED::printNumber(systemSettings.SolderingTemp, 3, FontStyle::SMALL);
}
OLED::setCursor(0, 8);
OLED::print(InputVoltageString);
OLED::print(InputVoltageString, FontStyle::SMALL);
printVoltage();
} else {
OLED::setFont(0);
#ifdef OLED_FLIP
if (!OLED::getRotation()) {
#else
@@ -919,7 +905,7 @@ void startGUITask(void const *argument __unused) {
if (!tipDisconnectedDisplay) {
// draw in the temp
if (!(systemSettings.coolingTempBlink && (xTaskGetTickCount() % 260 < 160)))
gui_drawTipTemp(false); // draw in the temp
gui_drawTipTemp(false, FontStyle::LARGE); // draw in the temp
} else {
// Draw in missing tip symbol