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

Implement printSymbolDeg() helper function as method for OLED class #1743

Merged
merged 10 commits into from
Jul 18, 2023
17 changes: 17 additions & 0 deletions source/Core/Drivers/OLED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,23 @@ void OLED::printWholeScreen(const char *string) {
}
}

// Print *F or *C - in font style of Small, Large (by default) or Extra based on input arg
void OLED::printSymbolDeg(const FontStyle fontStyle) {
switch (fontStyle) {
case FontStyle::EXTRAS:
// Picks *F or *C in ExtraFontChars[] from Font.h
OLED::drawSymbol(getSettingValue(SettingsOptions::TemperatureInF) ? 0 : 1);
break;
case FontStyle::LARGE:
OLED::print(getSettingValue(SettingsOptions::TemperatureInF) ? LargeSymbolDegF : LargeSymbolDegC, fontStyle);
break;
case FontStyle::SMALL:
default:
OLED::print(getSettingValue(SettingsOptions::TemperatureInF) ? SmallSymbolDegF : SmallSymbolDegC, fontStyle);
break;
}
}

inline void stripLeaderZeros(char *buffer, uint8_t places) {
// Removing the leading zero's by swapping them to SymbolSpace
// Stop 1 short so that we dont blank entire number if its zero
Expand Down
8 changes: 6 additions & 2 deletions source/Core/Drivers/OLED.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ class OLED {
}
}

static void setRotation(bool leftHanded); // Set the rotation for the screen
// Set the rotation for the screen
static void setRotation(bool leftHanded);
// Get the current rotation of the LCD
static bool getRotation() {
#ifdef OLED_FLIP
Expand All @@ -115,8 +116,11 @@ class OLED {
static void setBrightness(uint8_t contrast);
static void setInverseDisplay(bool inverted);
static int16_t getCursorX() { return cursor_x; }
static void print(const char *string, FontStyle fontStyle, uint8_t length = 255); // Draw a string to the current location, with selected font; optionally - with MAX length only
// Draw a string to the current location, with selected font; optionally - with MAX length only
static void print(const char *string, FontStyle fontStyle, uint8_t length = 255);
static void printWholeScreen(const char *string);
// Print *F or *C - in font style of Small, Large (by default) or Extra based on input arg
static void printSymbolDeg(FontStyle fontStyle = FontStyle::LARGE);
// Set the cursor location by pixels
static void setCursor(int16_t x, int16_t y) {
cursor_x = x;
Expand Down
2 changes: 1 addition & 1 deletion source/Core/Src/settingsGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ static bool setTempF(void) {
return res;
}

static void displayTempF(void) { OLED::print((getSettingValue(SettingsOptions::TemperatureInF)) ? LargeSymbolDegF : LargeSymbolDegC, FontStyle::LARGE); }
static void displayTempF(void) { OLED::printSymbolDeg(FontStyle::LARGE); }

#ifndef NO_DISPLAY_ROTATE

Expand Down
8 changes: 3 additions & 5 deletions source/Core/Threads/OperatingModes/HomeScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,9 @@ void drawDetailedHomeScreen(uint32_t tipTemp) {
}
// draw set temp
OLED::printNumber(getSettingValue(SettingsOptions::SolderingTemp), 3, FontStyle::SMALL);
if (getSettingValue(SettingsOptions::TemperatureInF)) {
OLED::print(SmallSymbolDegF, FontStyle::SMALL);
} else {
OLED::print(SmallSymbolDegC, FontStyle::SMALL);
}

OLED::printSymbolDeg(FontStyle::SMALL);

if (OLED::getRotation()) {
OLED::setCursor(0, 8);
} else {
Expand Down
3 changes: 2 additions & 1 deletion source/Core/Threads/OperatingModes/OperatingModes.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ void drawHomeScreen(bool buttonLockout) __attribute__((noreturn)); // IDLE / Hom
void renderHomeScreenAssets(void); // Called to act as start delay and used to render out flipped images for home screen graphics

// Common helpers
int8_t getPowerSourceNumber(void); // Returns number ID of power source
int8_t getPowerSourceNumber(void); // Returns number ID of power source
uint16_t getTipTemp(void); // Returns temperature of the tip in *C/*F (based on user settings)
#endif
17 changes: 3 additions & 14 deletions source/Core/Threads/OperatingModes/Sleep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int gui_SolderingSleepingMode(bool stayOff, bool autoStarted) {
}

// draw the lcd
uint16_t tipTemp = getSettingValue(SettingsOptions::TemperatureInF) ? TipThermoModel::getTipInF() : TipThermoModel::getTipInC();
uint16_t tipTemp = getTipTemp();

OLED::clearScreen();
OLED::setCursor(0, 0);
Expand All @@ -34,25 +34,14 @@ int gui_SolderingSleepingMode(bool stayOff, bool autoStarted) {
OLED::setCursor(0, 8);
OLED::print(translatedString(Tr->SleepingTipAdvancedString), FontStyle::SMALL);
OLED::printNumber(tipTemp, 3, FontStyle::SMALL);

if (getSettingValue(SettingsOptions::TemperatureInF)) {
OLED::print(SmallSymbolDegF, FontStyle::SMALL);
} else {
OLED::print(SmallSymbolDegC, FontStyle::SMALL);
}

OLED::printSymbolDeg(FontStyle::SMALL);
OLED::print(SmallSymbolSpace, FontStyle::SMALL);
printVoltage();
OLED::print(SmallSymbolVolts, FontStyle::SMALL);
} else {
OLED::print(translatedString(Tr->SleepingSimpleString), FontStyle::LARGE);
OLED::printNumber(tipTemp, 3, FontStyle::LARGE);

if (getSettingValue(SettingsOptions::TemperatureInF)) {
OLED::drawSymbol(0);
} else {
OLED::drawSymbol(1);
}
OLED::printSymbolDeg(FontStyle::EXTRAS);
}

OLED::refresh();
Expand Down
13 changes: 2 additions & 11 deletions source/Core/Threads/OperatingModes/SolderingProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ void gui_solderingProfileMode() {
break;
}

if (getSettingValue(SettingsOptions::TemperatureInF)) {
tipTemp = TipThermoModel::getTipInF();
} else {
tipTemp = TipThermoModel::getTipInC();
}
tipTemp = getTipTemp();

// if start temp is unknown (preheat), we're setting it now
if (phaseStartTemp == 0) {
Expand Down Expand Up @@ -155,12 +151,7 @@ void gui_solderingProfileMode() {
OLED::printNumber(tipTemp, 3, FontStyle::SMALL);
OLED::print(SmallSymbolSlash, FontStyle::SMALL);
OLED::printNumber(profileCurrentTargetTemp, 3, FontStyle::SMALL);

if (getSettingValue(SettingsOptions::TemperatureInF)) {
OLED::print(SmallSymbolDegF, FontStyle::SMALL);
} else {
OLED::print(SmallSymbolDegC, FontStyle::SMALL);
}
OLED::printSymbolDeg(FontStyle::SMALL);

// print phase
if (profilePhase > 0 && profilePhase <= getSettingValue(SettingsOptions::ProfilePhases)) {
Expand Down
6 changes: 1 addition & 5 deletions source/Core/Threads/OperatingModes/TemperatureAdjust.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@ void gui_solderingTempAdjust(void) {

OLED::print(LargeSymbolSpace, FontStyle::LARGE);
OLED::printNumber(getSettingValue(SettingsOptions::SolderingTemp), 3, FontStyle::LARGE);
if (getSettingValue(SettingsOptions::TemperatureInF)) {
OLED::drawSymbol(0);
} else {
OLED::drawSymbol(1);
}
OLED::printSymbolDeg(FontStyle::EXTRAS);
OLED::print(LargeSymbolSpace, FontStyle::LARGE);
if (OLED::getRotation()) {
OLED::print(getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled) ? LargeSymbolMinus : LargeSymbolPlus, FontStyle::LARGE);
Expand Down
25 changes: 4 additions & 21 deletions source/Core/Threads/OperatingModes/utils/DrawTipTemperature.cpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
#include "OperatingModeUtilities.h"
#include "OperatingModes.h"
#include "TipThermoModel.h"

void gui_drawTipTemp(bool symbol, const FontStyle font) {
// Draw tip temp handling unit conversion & tolerance near setpoint
uint32_t Temp = 0;
if (getSettingValue(SettingsOptions::TemperatureInF)) {
Temp = TipThermoModel::getTipInF();
} else {
Temp = TipThermoModel::getTipInC();
}
uint16_t Temp = getTipTemp();

OLED::printNumber(Temp, 3, font); // Draw the tip temp out
if (symbol) {
if (font == FontStyle::LARGE) {
// Big font, can draw nice symbols
if (getSettingValue(SettingsOptions::TemperatureInF)) {
OLED::drawSymbol(0);
} else {
OLED::drawSymbol(1);
}
} else {
// Otherwise fall back to chars
if (getSettingValue(SettingsOptions::TemperatureInF)) {
OLED::print(SmallSymbolDegF, FontStyle::SMALL);
} else {
OLED::print(SmallSymbolDegC, FontStyle::SMALL);
}
}
// For big font, can draw nice symbols, otherwise fall back to chars
OLED::printSymbolDeg(font == FontStyle::LARGE ? FontStyle::EXTRAS : font);
}
}
2 changes: 1 addition & 1 deletion source/Core/Threads/OperatingModes/utils/PrintVoltage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ void printVoltage(void) {
OLED::printNumber(volt / 10, 2, FontStyle::SMALL);
OLED::print(SmallSymbolDot, FontStyle::SMALL);
OLED::printNumber(volt % 10, 1, FontStyle::SMALL);
}
}
3 changes: 3 additions & 0 deletions source/Core/Threads/OperatingModes/utils/SolderingCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,6 @@ int8_t getPowerSourceNumber(void) {
}
return sourceNumber;
}

// Returns temperature of the tip in *C/*F (based on user settings)
uint16_t getTipTemp(void) { return getSettingValue(SettingsOptions::TemperatureInF) ? TipThermoModel::getTipInF() : TipThermoModel::getTipInC(); }