diff --git a/source/Core/Threads/UI/drawing/mono_96x16/draw_profile_advanced.cpp b/source/Core/Threads/UI/drawing/mono_96x16/draw_profile_advanced.cpp new file mode 100644 index 00000000..4d3a8c2f --- /dev/null +++ b/source/Core/Threads/UI/drawing/mono_96x16/draw_profile_advanced.cpp @@ -0,0 +1,56 @@ +#include "ui_drawing.hpp" + +void ui_draw_soldering_profile_advanced(TemperatureType_t tipTemp, TemperatureType_t profileCurrentTargetTemp, uint32_t phaseElapsedSeconds, uint32_t phase,const uint32_t phaseTimeGoal) { + // print temperature + if (OLED::getRotation()) { + OLED::setCursor(48, 0); + } else { + OLED::setCursor(0, 0); + } + + 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); + } + + // print phase + if (phase > 0 && phase <= getSettingValue(SettingsOptions::ProfilePhases)) { + if (OLED::getRotation()) { + OLED::setCursor(36, 0); + } else { + OLED::setCursor(55, 0); + } + OLED::printNumber(phase, 1, FontStyle::SMALL); + } + + // print time progress / preheat / cooldown + if (OLED::getRotation()) { + OLED::setCursor(42, 8); + } else { + OLED::setCursor(0, 8); + } + + if (phase == 0) { + OLED::print(translatedString(Tr->ProfilePreheatString), FontStyle::SMALL); + } else if (phase > getSettingValue(SettingsOptions::ProfilePhases)) { + OLED::print(translatedString(Tr->ProfileCooldownString), FontStyle::SMALL); + } else { + OLED::printNumber(phaseElapsedSeconds / 60, 1, FontStyle::SMALL); + OLED::print(SmallSymbolColon, FontStyle::SMALL); + OLED::printNumber(phaseElapsedSeconds % 60, 2, FontStyle::SMALL, false); + + OLED::print(SmallSymbolSlash, FontStyle::SMALL); + + // blink if we can't keep up with the time goal + if (phaseElapsedSeconds < phaseTimeGoal + 2 || (xTaskGetTickCount() / TICKS_SECOND) % 2 == 0) { + OLED::printNumber(phaseTimeGoal / 60, 1, FontStyle::SMALL); + OLED::print(SmallSymbolColon, FontStyle::SMALL); + OLED::printNumber(phaseTimeGoal % 60, 2, FontStyle::SMALL, false); + } + } +} \ No newline at end of file diff --git a/source/Core/Threads/UI/drawing/mono_96x16/draw_soldering_power_status.cpp b/source/Core/Threads/UI/drawing/mono_96x16/draw_soldering_power_status.cpp index 981a30d7..416ccd76 100644 --- a/source/Core/Threads/UI/drawing/mono_96x16/draw_soldering_power_status.cpp +++ b/source/Core/Threads/UI/drawing/mono_96x16/draw_soldering_power_status.cpp @@ -1,7 +1,42 @@ #include "power.hpp" #include "ui_drawing.hpp" +#include + +void ui_draw_soldering_power_status(bool boost_mode_on) { + if (OLED::getRotation()) { + OLED::setCursor(50, 0); + } else { + OLED::setCursor(-1, 0); + } + + ui_draw_tip_temperature(true, FontStyle::LARGE); + + if (boost_mode_on) { // Boost mode is on + if (OLED::getRotation()) { + OLED::setCursor(34, 0); + } else { + OLED::setCursor(50, 0); + } + OLED::print(LargeSymbolPlus, FontStyle::LARGE); + } else { +#ifndef NO_SLEEP_MODE + if (getSettingValue(SettingsOptions::Sensitivity) && getSettingValue(SettingsOptions::SleepTime)) { + if (OLED::getRotation()) { + OLED::setCursor(32, 0); + } else { + OLED::setCursor(47, 0); + } + printCountdownUntilSleep(getSleepTimeout()); + } +#endif + if (OLED::getRotation()) { + OLED::setCursor(32, 8); + } else { + OLED::setCursor(47, 8); + } + OLED::print(PowerSourceNames[getPowerSourceNumber()], FontStyle::SMALL, 2); + } -void ui_draw_soldering_power_status(void) { if (OLED::getRotation()) { OLED::setCursor(0, 0); } else { diff --git a/source/Core/Threads/UI/drawing/mono_96x16/draw_temperature_change.cpp b/source/Core/Threads/UI/drawing/mono_96x16/draw_temperature_change.cpp new file mode 100644 index 00000000..0427408f --- /dev/null +++ b/source/Core/Threads/UI/drawing/mono_96x16/draw_temperature_change.cpp @@ -0,0 +1,21 @@ +#include "ui_drawing.hpp" + +void ui_draw_temperature_change(void) { + + OLED::setCursor(0, 0); + if (OLED::getRotation()) { + OLED::print(getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled) ? LargeSymbolPlus : LargeSymbolMinus, FontStyle::LARGE); + } else { + OLED::print(getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled) ? LargeSymbolMinus : LargeSymbolPlus, FontStyle::LARGE); + } + + OLED::print(LargeSymbolSpace, FontStyle::LARGE); + OLED::printNumber(getSettingValue(SettingsOptions::SolderingTemp), 3, FontStyle::LARGE); + OLED::printSymbolDeg(FontStyle::EXTRAS); + OLED::print(LargeSymbolSpace, FontStyle::LARGE); + if (OLED::getRotation()) { + OLED::print(getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled) ? LargeSymbolMinus : LargeSymbolPlus, FontStyle::LARGE); + } else { + OLED::print(getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled) ? LargeSymbolPlus : LargeSymbolMinus, FontStyle::LARGE); + } +} \ No newline at end of file diff --git a/source/Core/Threads/UI/drawing/mono_96x16/draw_usb_pd_debug.cpp b/source/Core/Threads/UI/drawing/mono_96x16/draw_usb_pd_debug.cpp new file mode 100644 index 00000000..5888cca0 --- /dev/null +++ b/source/Core/Threads/UI/drawing/mono_96x16/draw_usb_pd_debug.cpp @@ -0,0 +1,43 @@ +#include "ui_drawing.hpp" + +void ui_draw_usb_pd_debug_state(const uint16_t vbus_sense_state, const uint8_t stateNumber) { + OLED::setCursor(0, 0); // Position the cursor at the 0,0 (top left) + OLED::print(SmallSymbolPDDebug, FontStyle::SMALL); // Print Title + OLED::setCursor(0, 8); // second line + // Print the PD state machine + OLED::print(SmallSymbolState, FontStyle::SMALL); + OLED::print(SmallSymbolSpace, FontStyle::SMALL); + OLED::printNumber(stateNumber, 2, FontStyle::SMALL, true); + OLED::print(SmallSymbolSpace, FontStyle::SMALL); + + if (vbus_sense_state == 2) { + OLED::print(SmallSymbolNoVBus, FontStyle::SMALL); + } else if (vbus_sense_state == 1) { + OLED::print(SmallSymbolVBus, FontStyle::SMALL); + } +} + +void ui_draw_usb_pd_debug_pdo(const uint8_t entry_num, const uint16_t min_voltage, const uint16_t max_voltage, const uint16_t current_a_x100, const uint16_t wattage) { + + OLED::setCursor(0, 0); // Position the cursor at the 0,0 (top left) + OLED::print(SmallSymbolPDDebug, FontStyle::SMALL); // Print Title + OLED::setCursor(0, 8); // second line + OLED::printNumber(entry_num, 2, FontStyle::SMALL, true); // print the entry number + OLED::print(SmallSymbolSpace, FontStyle::SMALL); + if (min_voltage > 0) { + OLED::printNumber(min_voltage, 2, FontStyle::SMALL, true); // print the voltage + OLED::print(SmallSymbolMinus, FontStyle::SMALL); + } + OLED::printNumber(max_voltage, 2, FontStyle::SMALL, true); // print the voltage + OLED::print(SmallSymbolVolts, FontStyle::SMALL); + OLED::print(SmallSymbolSpace, FontStyle::SMALL); + if (wattage) { + OLED::printNumber(wattage, 3, FontStyle::SMALL, true); // print the current in 0.1A res + OLED::print(SmallSymbolWatts, FontStyle::SMALL); + } else { + OLED::printNumber(current_a_x100 / 100, 2, FontStyle::SMALL, true); // print the current in 0.1A res + OLED::print(SmallSymbolDot, FontStyle::SMALL); + OLED::printNumber(current_a_x100 % 100, 2, FontStyle::SMALL, false); // print the current in 0.1A res + OLED::print(SmallSymbolAmps, FontStyle::SMALL); + } +} \ No newline at end of file diff --git a/source/Core/Threads/UI/drawing/ui_drawing.hpp b/source/Core/Threads/UI/drawing/ui_drawing.hpp index 443b5883..ecfc1ec1 100644 --- a/source/Core/Threads/UI/drawing/ui_drawing.hpp +++ b/source/Core/Threads/UI/drawing/ui_drawing.hpp @@ -17,10 +17,17 @@ void ui_draw_homescreen_detailed(TemperatureType_t tipTemp); // Drawing the void ui_draw_homescreen_simplified(TemperatureType_t tipTemp); // Drawing the home screen -- Simple mode void ui_pre_render_assets(void); // If any assets need to be pre-rendered into ram // Soldering mode -void ui_draw_soldering_power_status(void); +void ui_draw_soldering_power_status(bool boost_mode_on); void ui_draw_soldering_basic_status(bool boostModeOn); void ui_draw_soldering_detailed_sleep(TemperatureType_t tipTemp); void ui_draw_soldering_basic_sleep(TemperatureType_t tipTemp); +void ui_draw_soldering_profile_advanced(TemperatureType_t tipTemp, TemperatureType_t profileCurrentTargetTemp, uint32_t phaseElapsedSeconds, uint32_t phase,const uint32_t phaseTimeGoal); + +//Temp change +void ui_draw_temperature_change(void); +//USB-PD debug +void ui_draw_usb_pd_debug_state(const uint16_t vbus_sense_state, const uint8_t stateNumber) ; +void ui_draw_usb_pd_debug_pdo(const uint8_t entry_num, const uint16_t min_voltage, const uint16_t max_voltage, const uint16_t current_a_x100, const uint16_t wattage) ; // Utils void printVoltage(void); #endif // UI_DRAWING_UI_DRAWING_HPP_ \ No newline at end of file diff --git a/source/Core/Threads/UI/logic/Soldering.cpp b/source/Core/Threads/UI/logic/Soldering.cpp index b065a927..9f6368c2 100644 --- a/source/Core/Threads/UI/logic/Soldering.cpp +++ b/source/Core/Threads/UI/logic/Soldering.cpp @@ -108,41 +108,8 @@ OperatingMode gui_solderingMode(const ButtonState buttons, guiContext *cxt) { // Draw in the screen details if (getSettingValue(SettingsOptions::DetailedSoldering)) { - if (OLED::getRotation()) { - OLED::setCursor(50, 0); - } else { - OLED::setCursor(-1, 0); - } - ui_draw_tip_temperature(true, FontStyle::LARGE); - - if (cxt->scratch_state.state2) { // Boost mode is on - if (OLED::getRotation()) { - OLED::setCursor(34, 0); - } else { - OLED::setCursor(50, 0); - } - OLED::print(LargeSymbolPlus, FontStyle::LARGE); - } else { -#ifndef NO_SLEEP_MODE - if (getSettingValue(SettingsOptions::Sensitivity) && getSettingValue(SettingsOptions::SleepTime)) { - if (OLED::getRotation()) { - OLED::setCursor(32, 0); - } else { - OLED::setCursor(47, 0); - } - printCountdownUntilSleep(getSleepTimeout()); - } -#endif - if (OLED::getRotation()) { - OLED::setCursor(32, 8); - } else { - OLED::setCursor(47, 8); - } - OLED::print(PowerSourceNames[getPowerSourceNumber()], FontStyle::SMALL, 2); - } - - ui_draw_soldering_power_status(); + ui_draw_soldering_power_status(cxt->scratch_state.state2); } else { ui_draw_soldering_basic_status(cxt->scratch_state.state2); diff --git a/source/Core/Threads/UI/logic/SolderingProfile.cpp b/source/Core/Threads/UI/logic/SolderingProfile.cpp index 77ad8333..addea04b 100644 --- a/source/Core/Threads/UI/logic/SolderingProfile.cpp +++ b/source/Core/Threads/UI/logic/SolderingProfile.cpp @@ -126,61 +126,8 @@ OperatingMode gui_solderingProfileMode(const ButtonState buttons, guiContext *cx // Draw in the screen details if (getSettingValue(SettingsOptions::DetailedSoldering)) { - // print temperature - if (OLED::getRotation()) { - OLED::setCursor(48, 0); - } else { - OLED::setCursor(0, 0); - } - - 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); - } - - // print phase - if (cxt->scratch_state.state1 > 0 && cxt->scratch_state.state1 <= getSettingValue(SettingsOptions::ProfilePhases)) { - if (OLED::getRotation()) { - OLED::setCursor(36, 0); - } else { - OLED::setCursor(55, 0); - } - OLED::printNumber(cxt->scratch_state.state1, 1, FontStyle::SMALL); - } - - // print time progress / preheat / cooldown - if (OLED::getRotation()) { - OLED::setCursor(42, 8); - } else { - OLED::setCursor(0, 8); - } - - if (cxt->scratch_state.state1 == 0) { - OLED::print(translatedString(Tr->ProfilePreheatString), FontStyle::SMALL); - } else if (cxt->scratch_state.state1 > getSettingValue(SettingsOptions::ProfilePhases)) { - OLED::print(translatedString(Tr->ProfileCooldownString), FontStyle::SMALL); - } else { - OLED::printNumber(phaseElapsedSeconds / 60, 1, FontStyle::SMALL); - OLED::print(SmallSymbolColon, FontStyle::SMALL); - OLED::printNumber(phaseElapsedSeconds % 60, 2, FontStyle::SMALL, false); - - OLED::print(SmallSymbolSlash, FontStyle::SMALL); - - // blink if we can't keep up with the time goal - if (phaseElapsedSeconds < cxt->scratch_state.state2 + 2 || (xTaskGetTickCount() / TICKS_SECOND) % 2 == 0) { - OLED::printNumber(cxt->scratch_state.state2 / 60, 1, FontStyle::SMALL); - OLED::print(SmallSymbolColon, FontStyle::SMALL); - OLED::printNumber(cxt->scratch_state.state2 % 60, 2, FontStyle::SMALL, false); - } - } - - ui_draw_soldering_power_status(); - + ui_draw_soldering_profile_advanced(tipTemp, profileCurrentTargetTemp, phaseElapsedSeconds, cxt->scratch_state.state1,cxt->scratch_state.state2); + ui_draw_soldering_power_status(false); } else { ui_draw_soldering_basic_status(false); } diff --git a/source/Core/Threads/UI/logic/TemperatureAdjust.cpp b/source/Core/Threads/UI/logic/TemperatureAdjust.cpp index 2a840d78..34a896c3 100644 --- a/source/Core/Threads/UI/logic/TemperatureAdjust.cpp +++ b/source/Core/Threads/UI/logic/TemperatureAdjust.cpp @@ -1,4 +1,6 @@ #include "OperatingModes.h" +#include "ui_drawing.hpp" + OperatingMode gui_solderingTempAdjust(const ButtonState buttonIn, guiContext *cxt) { currentTempTargetDegC = 0; // Turn off heater while adjusting temp @@ -15,8 +17,6 @@ OperatingMode gui_solderingTempAdjust(const ButtonState buttonIn, guiContext *cx } } - OLED::setCursor(0, 0); - int16_t delta = 0; switch (buttons) { case BUTTON_NONE: @@ -81,21 +81,7 @@ OperatingMode gui_solderingTempAdjust(const ButtonState buttonIn, guiContext *cx } setSettingValue(SettingsOptions::SolderingTemp, (uint16_t)newTemp); } - if (OLED::getRotation()) { - OLED::print(getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled) ? LargeSymbolPlus : LargeSymbolMinus, FontStyle::LARGE); - } else { - OLED::print(getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled) ? LargeSymbolMinus : LargeSymbolPlus, FontStyle::LARGE); - } - - OLED::print(LargeSymbolSpace, FontStyle::LARGE); - OLED::printNumber(getSettingValue(SettingsOptions::SolderingTemp), 3, FontStyle::LARGE); - OLED::printSymbolDeg(FontStyle::EXTRAS); - OLED::print(LargeSymbolSpace, FontStyle::LARGE); - if (OLED::getRotation()) { - OLED::print(getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled) ? LargeSymbolMinus : LargeSymbolPlus, FontStyle::LARGE); - } else { - OLED::print(getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled) ? LargeSymbolPlus : LargeSymbolMinus, FontStyle::LARGE); - } + ui_draw_temperature_change(); if (xTaskGetTickCount() - lastButtonTime > (TICKS_SECOND * 3)) { saveSettings(); diff --git a/source/Core/Threads/UI/logic/USBPDDebug_FS2711.cpp b/source/Core/Threads/UI/logic/USBPDDebug_FS2711.cpp index 6d5faea8..ea54b6a5 100644 --- a/source/Core/Threads/UI/logic/USBPDDebug_FS2711.cpp +++ b/source/Core/Threads/UI/logic/USBPDDebug_FS2711.cpp @@ -1,5 +1,6 @@ #include "FS2711.hpp" #include "OperatingModes.h" +#include "ui_drawing.hpp" #include "stdbool.h" #if POW_PD_EXT == 2 #ifdef HAS_POWER_DEBUG_MENU @@ -7,74 +8,42 @@ OperatingMode showPDDebug(const ButtonState buttons, guiContext *cxt) { // Print out the USB-PD state // Basically this is like the Debug menu, but instead we want to print out the PD status - uint8_t screen = 0; - ButtonState b; - for (;;) { - OLED::clearScreen(); // Ensure the buffer starts clean - OLED::setCursor(0, 0); // Position the cursor at the 0,0 (top left) - OLED::print(SmallSymbolPDDebug, FontStyle::SMALL); // Print Title - OLED::setCursor(0, 8); // second line - if (screen > 7) { - screen = 0; - } - if (screen == 0) { - // Print the PD Debug state - OLED::print(SmallSymbolState, FontStyle::SMALL); - OLED::print(SmallSymbolSpace, FontStyle::SMALL); - - fs2711_state_t state = FS2711::debug_get_state(); - - OLED::printNumber(state.pdo_num, 1, FontStyle::SMALL); - OLED::print(SmallSymbolSpace, FontStyle::SMALL); - - // OLED::drawHex(state.req_pdo_num, FontStyle::SMALL, 4); - OLED::printNumber(state.req_pdo_num > 7 ? 0 : state.req_pdo_num + 1, 1, FontStyle::SMALL, true); - OLED::print(SmallSymbolSpace, FontStyle::SMALL); - uint8_t protocol = FS2711::selected_protocol(); - OLED::printNumber(protocol, 2, FontStyle::SMALL); - OLED::print(SmallSymbolSpace, FontStyle::SMALL); - } else { - - // Print out the Proposed power options one by one - uint16_t max_voltage = FS2711::debug_pdo_max_voltage(screen - 1); - if (max_voltage == 0) { - screen += 1; - } else { - uint16_t min_voltage = FS2711::debug_pdo_min_voltage(screen - 1); - uint16_t current = FS2711::debug_pdo_source_current(screen - 1); - uint16_t pdo_type = FS2711::debug_pdo_type(screen - 1); - - OLED::printNumber(screen, 1, FontStyle::SMALL, true); - OLED::print(SmallSymbolSpace, FontStyle::SMALL); - - if (pdo_type == 1) { - OLED::printNumber(min_voltage / 1000, 2, FontStyle::SMALL, true); - OLED::print(SmallSymbolMinus, FontStyle::SMALL); - OLED::printNumber(max_voltage / 1000, 2, FontStyle::SMALL, false); - } else { - OLED::printNumber(max_voltage / 1000, 2, FontStyle::SMALL, true); - } - OLED::print(SmallSymbolVolts, FontStyle::SMALL); - OLED::print(SmallSymbolSpace, FontStyle::SMALL); - - OLED::printNumber(current / 1000, 2, FontStyle::SMALL, true); - OLED::print(SmallSymbolDot, FontStyle::SMALL); - OLED::printNumber(current % 1000, 1, FontStyle::SMALL, false); - OLED::print(SmallSymbolAmps, FontStyle::SMALL); - // OLED::printNumber(currentx100 % 100, 2, FontStyle::SMALL, true); - } - } - - OLED::refresh(); - b = getButtonState(); - if (b == BUTTON_B_SHORT) { - return OperatingMode::InitialisationDone; - } else if (b == BUTTON_F_SHORT) { - screen++; - } - - GUIDelay(); + uint16_t *screen = &(cxt->scratch_state.state1); + + if (*screen > 7) { + *screen = 0; } + if (*screen == 0) { + // Print the PD Debug state + fs2711_state_t state = FS2711::debug_get_state(); + + ui_draw_usb_pd_debug_state(0, state.pdo_num); + } else { + + // Print out the Proposed power options one by one + uint16_t max_voltage = FS2711::debug_pdo_max_voltage(*screen - 1); + if (max_voltage == 0) { + *screen += 1; + } else { + uint16_t min_voltage = FS2711::debug_pdo_min_voltage(*screen - 1); + uint16_t current = FS2711::debug_pdo_source_current(*screen - 1); + uint16_t pdo_type = FS2711::debug_pdo_type(*screen - 1); + if (pdo_type != 1) { + min_voltage = 0; + } + + ui_draw_usb_pd_debug_pdo(*screen, min_voltage / 1000, max_voltage / 1000, current * 1, 0); + } + } + + OLED::refresh(); + + if (buttons == BUTTON_B_SHORT) { + return OperatingMode::InitialisationDone; + } else if (buttons == BUTTON_F_SHORT) { + *screen++; + } + return OperatingMode::UsbPDDebug; } #endif diff --git a/source/Core/Threads/UI/logic/USBPDDebug_FUSB.cpp b/source/Core/Threads/UI/logic/USBPDDebug_FUSB.cpp index 376ebd63..82613491 100644 --- a/source/Core/Threads/UI/logic/USBPDDebug_FUSB.cpp +++ b/source/Core/Threads/UI/logic/USBPDDebug_FUSB.cpp @@ -1,5 +1,5 @@ #include "OperatingModes.h" - +#include "ui_drawing.hpp" #ifdef POW_PD #include "pd.h" #ifdef HAS_POWER_DEBUG_MENU @@ -7,25 +7,20 @@ OperatingMode showPDDebug(const ButtonState buttons, guiContext *cxt) { // Print out the USB-PD state // Basically this is like the Debug menu, but instead we want to print out the PD status uint16_t *screen = &(cxt->scratch_state.state1); - OLED::setCursor(0, 0); // Position the cursor at the 0,0 (top left) - OLED::print(SmallSymbolPDDebug, FontStyle::SMALL); // Print Title - OLED::setCursor(0, 8); // second line + if ((*screen) == 0) { // Print the PD state machine - OLED::print(SmallSymbolState, FontStyle::SMALL); - OLED::print(SmallSymbolSpace, FontStyle::SMALL); - OLED::printNumber(USBPowerDelivery::getStateNumber(), 2, FontStyle::SMALL, true); - OLED::print(SmallSymbolSpace, FontStyle::SMALL); - // Also print vbus mod status - if (USBPowerDelivery::fusbPresent()) { +uint8_t vbusState=0; + if (USBPowerDelivery::fusbPresent()) { if (USBPowerDelivery::negotiationComplete() || (xTaskGetTickCount() > (TICKS_SECOND * 10))) { if (!USBPowerDelivery::isVBUSConnected()) { - OLED::print(SmallSymbolNoVBus, FontStyle::SMALL); + vbusState=2; } else { - OLED::print(SmallSymbolVBus, FontStyle::SMALL); + vbusState=1; } } } + ui_draw_usb_pd_debug_state(vbusState,USBPowerDelivery::getStateNumber()); } else { // Print out the Proposed power options one by one auto lastCaps = USBPowerDelivery::getLastSeenCapabilities(); @@ -63,25 +58,7 @@ OperatingMode showPDDebug(const ButtonState buttons, guiContext *cxt) { if (voltage_mv == 0) { (*screen) += 1; } else { - // print out this entry of the proposal - OLED::printNumber(*screen, 2, FontStyle::SMALL, true); // print the entry number - OLED::print(SmallSymbolSpace, FontStyle::SMALL); - if (min_voltage > 0) { - OLED::printNumber(min_voltage / 1000, 2, FontStyle::SMALL, true); // print the voltage - OLED::print(SmallSymbolMinus, FontStyle::SMALL); - } - OLED::printNumber(voltage_mv / 1000, 2, FontStyle::SMALL, true); // print the voltage - OLED::print(SmallSymbolVolts, FontStyle::SMALL); - OLED::print(SmallSymbolSpace, FontStyle::SMALL); - if (wattage) { - OLED::printNumber(wattage, 3, FontStyle::SMALL, true); // print the current in 0.1A res - OLED::print(SmallSymbolWatts, FontStyle::SMALL); - } else { - OLED::printNumber(current_a_x100 / 100, 2, FontStyle::SMALL, true); // print the current in 0.1A res - OLED::print(SmallSymbolDot, FontStyle::SMALL); - OLED::printNumber(current_a_x100 % 100, 2, FontStyle::SMALL, false); // print the current in 0.1A res - OLED::print(SmallSymbolAmps, FontStyle::SMALL); - } + ui_draw_usb_pd_debug_pdo(*screen, min_voltage / 1000, voltage_mv / 1000, current_a_x100, wattage); } } else { (*screen) = 0; diff --git a/source/Core/Threads/UI/logic/USBPDDebug_HUSB238.cpp b/source/Core/Threads/UI/logic/USBPDDebug_HUSB238.cpp index 173f7ea0..1bdf252a 100644 --- a/source/Core/Threads/UI/logic/USBPDDebug_HUSB238.cpp +++ b/source/Core/Threads/UI/logic/USBPDDebug_HUSB238.cpp @@ -1,56 +1,36 @@ #include "HUB238.hpp" #include "OperatingModes.h" +#include "ui_drawing.hpp" #if POW_PD_EXT == 1 #ifdef HAS_POWER_DEBUG_MENU OperatingMode showPDDebug(const ButtonState buttons, guiContext *cxt) { // Print out the USB-PD state // Basically this is like the Debug menu, but instead we want to print out the PD status - uint8_t screen = 0; - ButtonState b; - for (;;) { - OLED::clearScreen(); // Ensure the buffer starts clean - OLED::setCursor(0, 0); // Position the cursor at the 0,0 (top left) - OLED::print(SmallSymbolPDDebug, FontStyle::SMALL); // Print Title - OLED::setCursor(0, 8); // second line - if (screen > 6) { - screen = 0; - } - if (screen == 0) { - // Print the PD Debug state - OLED::print(SmallSymbolState, FontStyle::SMALL); - OLED::print(SmallSymbolSpace, FontStyle::SMALL); - uint16_t temp = hub238_debug_state(); - OLED::drawHex(temp, FontStyle::SMALL, 4); - OLED::print(SmallSymbolSpace, FontStyle::SMALL); - // Print current selected specs - temp = hub238_source_voltage(); - OLED::printNumber(temp, 2, FontStyle::SMALL, true); - OLED::print(SmallSymbolSpace, FontStyle::SMALL); + uint16_t *screen = &(cxt->scratch_state.state1); - } else { - - // Print out the Proposed power options one by one - const uint8_t voltages[] = {5, 9, 12, 15, 18, 20}; - uint16_t voltage = voltages[screen - 1]; - uint16_t currentx100 = hub238_getVoltagePDOCurrent(voltage); - OLED::printNumber(voltage, 2, FontStyle::SMALL, true); - OLED::print(SmallSymbolSpace, FontStyle::SMALL); - - OLED::printNumber(currentx100 / 100, 1, FontStyle::SMALL, true); - OLED::print(SmallSymbolDot, FontStyle::SMALL); - OLED::printNumber(currentx100 % 100, 2, FontStyle::SMALL, true); - } - - OLED::refresh(); - b = getButtonState(); - if (b == BUTTON_B_SHORT) { - return OperatingMode::InitialisationDone; - } else if (b == BUTTON_F_SHORT) { - screen++; - } - - GUIDelay(); + if (*screen > 6) { + *screen = 0; } + if (*screen == 0) { + // Print the PD Debug state + uint16_t temp = hub238_debug_state(); + ui_draw_usb_pd_debug_state( 0,temp); + } else { + + // Print out the Proposed power options one by one + const uint8_t voltages[] = {5, 9, 12, 15, 18, 20}; + uint16_t voltage = voltages[*screen - 1]; + uint16_t currentx100 = hub238_getVoltagePDOCurrent(voltage); + + ui_draw_usb_pd_debug_pdo(*screen, 0, voltage, currentx100, 0); + } + + if (buttons == BUTTON_B_SHORT) { + return OperatingMode::InitialisationDone; + } else if (buttons == BUTTON_F_SHORT) { + *screen++; + } + return OperatingMode::UsbPDDebug; } #endif