Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jul 1, 2023
1 parent 253ae19 commit b74958c
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 87 deletions.
83 changes: 42 additions & 41 deletions Marlin/src/core/endianness.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,51 +25,52 @@
#include "../core/macros.h"

#ifdef __cplusplus
namespace Endianness {
static constexpr uint32_t _dword = 0x01020304;
static constexpr uint8_t _lsb = (const uint8_t&)_dword;

static constexpr bool cpuIsLittleEndian = _lsb == 0x04;
static constexpr bool cpuIsBigEndian = _lsb == 0x01;
static_assert(cpuIsLittleEndian ^ cpuIsBigEndian, "Unknown CPU endianness");
namespace Endianness {
static constexpr uint32_t _dword = 0x01020304;
static constexpr uint8_t _lsb = (const uint8_t&)_dword;

// constexpr byte swapping for integral types
template<typename T> static constexpr typename Private::enable_if<Private::is_integral<T>::value, T>::type swap(T V, T swappedV = (T)0, size_t byteIndex = 0) {
return byteIndex == sizeof(T)
? swappedV
: swap<T>((T)(V >> 8), (swappedV << 8) | (V & (T)0xFF), byteIndex + 1);
}
static constexpr bool cpuIsLittleEndian = _lsb == 0x04;
static constexpr bool cpuIsBigEndian = _lsb == 0x01;
static_assert(cpuIsLittleEndian ^ cpuIsBigEndian, "Unknown CPU endianness");

// constexpr byte swapping for types derived from integral types (e.g. enums)
template<typename T> static constexpr typename Private::enable_if<
Private::is_same<uint16_t, typename Private::underlying_type<T>::type>::value, T>::type swap(T V) { return (T)swap<uint16_t>((uint16_t)V); }
template<typename T> static constexpr typename Private::enable_if<
Private::is_same<uint32_t, typename Private::underlying_type<T>::type>::value, T>::type swap(T V) { return (T)swap<uint32_t>((uint32_t)V); }
template<typename T> static constexpr typename Private::enable_if<
Private::is_same<uint64_t, typename Private::underlying_type<T>::type>::value, T>::type swap(T V) { return (T)swap<uint64_t>((uint64_t)V); }

// generic byte swapping
// CANNOT be used to initialize constexpr declarations
template<typename T> static constexpr typename Private::enable_if<!Private::is_integral<T>::value && !Private::is_enum<T>::value, T>::type swap(T V) {
union {
T val;
char byte[sizeof(T)];
} src{}, dst{};
// constexpr byte swapping for integral types
template<typename T> static constexpr typename Private::enable_if<Private::is_integral<T>::value, T>::type swap(T V, T swappedV=(T)0, size_t byteIndex=0) {
return byteIndex == sizeof(T)
? swappedV
: swap<T>((T)(V >> 8), (swappedV << 8) | (V & (T)0xFF), byteIndex + 1);
}

src.val = V;
for (uint8_t i = 0; i < sizeof(T); ++i) dst.byte[i] = src.byte[sizeof(T) - i - 1];
return dst.val;
}
// constexpr byte swapping for types derived from integral types (e.g. enums)
template<typename T> static constexpr typename Private::enable_if<
Private::is_same<uint16_t, typename Private::underlying_type<T>::type>::value, T>::type swap(T V) { return (T)swap<uint16_t>((uint16_t)V); }
template<typename T> static constexpr typename Private::enable_if<
Private::is_same<uint32_t, typename Private::underlying_type<T>::type>::value, T>::type swap(T V) { return (T)swap<uint32_t>((uint32_t)V); }
template<typename T> static constexpr typename Private::enable_if<
Private::is_same<uint64_t, typename Private::underlying_type<T>::type>::value, T>::type swap(T V) { return (T)swap<uint64_t>((uint64_t)V); }

// Convert to / from known endianness, depending on the host endianness
template<typename T> static constexpr T toBE(T V) { return cpuIsLittleEndian ? swap(V) : V; }
template<typename T> static constexpr T toLE(T V) { return cpuIsLittleEndian ? V : swap(V); }
template<typename T> static constexpr T fromBE(T V) { return cpuIsLittleEndian ? swap(V) : V; }
template<typename T> static constexpr T fromLE(T V) { return cpuIsLittleEndian ? V : swap(V); }
// Generic byte swapping
// CANNOT be used to initialize constexpr declarations
template<typename T> static constexpr typename Private::enable_if<!Private::is_integral<T>::value && !Private::is_enum<T>::value, T>::type swap(T V) {
union {
T val;
char byte[sizeof(T)];
} src{}, dst{};

// Reads a big/little endian from a pointer and converts it to the host endianness
template<typename T> static constexpr T fromBE_P(void* V) { return fromBE(*(T*)V); }
template<typename T> static constexpr T fromLE_P(void* V) { return fromLE(*(T*)V); }
};
src.val = V;
for (uint8_t i = 0; i < sizeof(T); ++i) dst.byte[i] = src.byte[sizeof(T) - i - 1];
return dst.val;
}

#endif
// Convert to / from known endianness, depending on the host endianness
template<typename T> static constexpr T toBE(T V) { return cpuIsLittleEndian ? swap(V) : V; }
template<typename T> static constexpr T toLE(T V) { return cpuIsLittleEndian ? V : swap(V); }
template<typename T> static constexpr T fromBE(T V) { return cpuIsLittleEndian ? swap(V) : V; }
template<typename T> static constexpr T fromLE(T V) { return cpuIsLittleEndian ? V : swap(V); }

// Reads a big/little endian from a pointer and converts it to the host endianness
template<typename T> static constexpr T fromBE_P(void* V) { return fromBE(*(T*)V); }
template<typename T> static constexpr T fromLE_P(void* V) { return fromLE(*(T*)V); }
};

#endif // __cplusplus
2 changes: 0 additions & 2 deletions Marlin/src/lcd/extui/dgus_e3s1pro/DGUSDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
* Updated for STM32G0B1RE by Protomosh in 2022.
*/


#include "config/DGUS_Screen.h"
#include "config/DGUS_Control.h"
#include "definition/DGUS_VP.h"
Expand All @@ -35,7 +34,6 @@
#include "../../../inc/MarlinConfigPre.h"
#include "../../../MarlinCore.h"


//#define DEBUG_DGUSLCD // Uncomment for debug messages
#define DEBUG_OUT ENABLED(DEBUG_DGUSLCD)
#include "../../../core/debug_out.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ void DGUSReturnKeyCodeHandler::Command_CheckOK(DGUS_VP &vp, void *data) {
break;

case DGUS_Data::CheckOKCommand::FilamentLoad_Yes:
if (ExtUI::getFilamentRunoutEnabled() && READ(FIL_RUNOUT1_PIN) == FIL_RUNOUT1_STATE)
{
if (ExtUI::getFilamentRunoutEnabled() && READ(FIL_RUNOUT1_PIN) == FIL_RUNOUT1_STATE) {
screen.triggerScreenChange(DGUS_Screen::FILAMENTLOAD);
break;
}
Expand Down
20 changes: 10 additions & 10 deletions Marlin/src/lcd/extui/dgus_e3s1pro/DGUSRxHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,10 @@ void DGUSRxHandler::extrudeLength(DGUS_VP &vp, void *data) {
const_float_t currentPosition = ExtUI::getAxisPosition_mm(ExtUI::E0);

#if HAS_FILAMENT_SENSOR
if (ExtUI::getFilamentRunoutEnabled() && ExtUI::getFilamentRunoutState())
{
screen.triggerTempScreenChange(DGUS_Screen::FILAMENTCHECK, DGUS_Screen::CONTROL_DEVICE);
return;
}
if (ExtUI::getFilamentRunoutEnabled() && ExtUI::getFilamentRunoutState()) {
screen.triggerTempScreenChange(DGUS_Screen::FILAMENTCHECK, DGUS_Screen::CONTROL_DEVICE);
return;
}
#endif
ExtUI::setAxisPosition_mm(currentPosition+length, ExtUI::E0);
}
Expand All @@ -92,11 +91,10 @@ void DGUSRxHandler::retractLength(DGUS_VP &vp, void *data) {
const_float_t currentPosition = ExtUI::getAxisPosition_mm(ExtUI::E0);

#if HAS_FILAMENT_SENSOR
if (ExtUI::getFilamentRunoutEnabled() && ExtUI::getFilamentRunoutState())
{
screen.triggerTempScreenChange(DGUS_Screen::FILAMENTCHECK, DGUS_Screen::CONTROL_DEVICE);
return;
}
if (ExtUI::getFilamentRunoutEnabled() && ExtUI::getFilamentRunoutState()) {
screen.triggerTempScreenChange(DGUS_Screen::FILAMENTCHECK, DGUS_Screen::CONTROL_DEVICE);
return;
}
#endif
ExtUI::setAxisPosition_mm(currentPosition-length, ExtUI::E0);
}
Expand All @@ -109,6 +107,7 @@ void DGUSRxHandler::setLanguage(DGUS_VP &vp, void *data) {
}

#if ENABLED(PIDTEMPBED)

void DGUSRxHandler::bed_PID_P(DGUS_VP &vp, void *data) {
float pidValue = dgus.fromFixedPoint<int16_t, float, 2>(Endianness::fromBE_P<int16_t>(data));
ExtUI::setBedPID(
Expand All @@ -135,6 +134,7 @@ void DGUSRxHandler::setLanguage(DGUS_VP &vp, void *data) {
pidValue
);
}

#endif // PIDTEMPBED

void DGUSRxHandler::fanSpeed(DGUS_VP &vp, void *data) {
Expand Down
10 changes: 4 additions & 6 deletions Marlin/src/lcd/extui/dgus_e3s1pro/DGUSSDCardHandler_Advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ DGUS_SDCardHandler::page_t DGUS_SDCardHandler::onFirstPage() {
}

DGUS_SDCardHandler::page_t DGUS_SDCardHandler::onLastPage() {
currentVirtualPage = ((fileCount-1) + (fileList.isAtRootDir() ? 0 : 1)) / DGUS_E3S1PRO_BASIC_SDCARD_FILES_PER_PAGE;
currentVirtualPage = (fileCount - 1 + (fileList.isAtRootDir() ? 0 : 1)) / DGUS_E3S1PRO_BASIC_SDCARD_FILES_PER_PAGE;

if (currentVirtualPage >= 4) {
currentPage = page_t::PAGE_4;
Expand All @@ -142,10 +142,8 @@ DGUS_SDCardHandler::page_t DGUS_SDCardHandler::onPreviousPage() {
}

DGUS_SDCardHandler::page_t DGUS_SDCardHandler::onNextPage() {
if (currentVirtualPage < ((fileCount-1) + (fileList.isAtRootDir() ? 0 : 1)) / DGUS_E3S1PRO_BASIC_SDCARD_FILES_PER_PAGE) {
currentVirtualPage += 1;

if (currentVirtualPage >= 4) {
if (currentVirtualPage < (fileCount - 1 + (fileList.isAtRootDir() ? 0 : 1)) / DGUS_E3S1PRO_BASIC_SDCARD_FILES_PER_PAGE) {
if (++currentVirtualPage >= 4) {
currentPage = page_t::PAGE_4;
onPageLoad(page_t::PAGE_4);
}
Expand All @@ -156,4 +154,4 @@ DGUS_SDCardHandler::page_t DGUS_SDCardHandler::onNextPage() {
return currentPage;
}

#endif // DGUS_LCD_UI_E3S1PRO && DGUS_ADVANCED_SDCARD
#endif // DGUS_LCD_UI_E3S1PRO && DGUS_ADVANCED_SDCARD
6 changes: 2 additions & 4 deletions Marlin/src/lcd/extui/dgus_e3s1pro/DGUSScreenHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,8 @@ void DGUSScreenHandler::configurationStoreRead(bool success) {
}

void DGUSScreenHandler::playTone(const uint16_t frequency, const uint16_t duration) {
UNUSED(duration);

if (frequency >= 1 && frequency <= 255) {
if (duration >= 1 && duration <= 255)
if (WITHIN(frequency, 1, 255)) {
if (WITHIN(duration, 1, 255))
dgus.playSound((uint8_t)frequency, (uint8_t)duration);
else
dgus.playSound((uint8_t)frequency);
Expand Down
32 changes: 10 additions & 22 deletions Marlin/src/lcd/extui/dgus_reloaded/DGUSScreenHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ void DGUSScreenHandler::ready() {
}

void DGUSScreenHandler::loop() {
if (!settings_ready || current_screenID == DGUS_ScreenID::KILL) {
if (!settings_ready || current_screenID == DGUS_ScreenID::KILL)
return;
}

const millis_t ms = ExtUI::safe_millis();
static millis_t next_event_ms = 0;
Expand Down Expand Up @@ -226,10 +225,8 @@ void DGUSScreenHandler::configurationStoreRead(bool success) {
}

void DGUSScreenHandler::playTone(const uint16_t frequency, const uint16_t duration) {
UNUSED(duration);

if (frequency >= 1 && frequency <= 255) {
if (duration >= 1 && duration <= 255)
if (WITHIN(frequency, 1, 255)) {
if (WITHIN(duration, 1, 255))
dgus.playSound((uint8_t)frequency, (uint8_t)duration);
else
dgus.playSound((uint8_t)frequency);
Expand Down Expand Up @@ -301,12 +298,10 @@ void DGUSScreenHandler::filamentRunout(const ExtUI::extruder_t extruder) {
#endif // HAS_MEDIA

#if ENABLED(POWER_LOSS_RECOVERY)

void DGUSScreenHandler::powerLossResume() {
moveToScreen(DGUS_ScreenID::POWERLOSS, true);
}

#endif // POWER_LOSS_RECOVERY
#endif

#if HAS_PID_HEATING

Expand Down Expand Up @@ -374,20 +369,18 @@ void DGUSScreenHandler::setMessageLinePGM(PGM_P const msg, const uint8_t line) {

void DGUSScreenHandler::setStatusMessage(const char* msg, const millis_t duration) {
dgus.writeString((uint16_t)DGUS_Addr::MESSAGE_Status, msg, DGUS_STATUS_LEN, false, true);

status_expire = (duration > 0 ? ExtUI::safe_millis() + duration : 0);
}

void DGUSScreenHandler::setStatusMessage(FSTR_P const fmsg, const millis_t duration) {
dgus.writeString((uint16_t)DGUS_Addr::MESSAGE_Status, fmsg, DGUS_STATUS_LEN, false, true);

status_expire = (duration > 0 ? ExtUI::safe_millis() + duration : 0);
}

void DGUSScreenHandler::showWaitScreen(const DGUS_ScreenID return_screenID, const bool has_continue/*=false*/) {
if (return_screenID != DGUS_ScreenID::WAIT) {
if (return_screenID != DGUS_ScreenID::WAIT)
wait_return_screenID = return_screenID;
}

wait_continue = has_continue;

triggerScreenChange(DGUS_ScreenID::WAIT);
Expand Down Expand Up @@ -418,8 +411,7 @@ void DGUSScreenHandler::triggerEEPROMSave() {
}

bool DGUSScreenHandler::isPrinterIdle() {
return (!ExtUI::commandsInQueue()
&& !ExtUI::isMoving());
return (!ExtUI::commandsInQueue() && !ExtUI::isMoving());
}

const DGUS_Addr* DGUSScreenHandler::findScreenAddrList(const DGUS_ScreenID screenID) {
Expand Down Expand Up @@ -453,20 +445,16 @@ bool DGUSScreenHandler::callScreenSetup(const DGUS_ScreenID screenID) {
}

void DGUSScreenHandler::moveToScreen(const DGUS_ScreenID screenID, bool abort_wait) {
if (current_screenID == DGUS_ScreenID::KILL) {
return;
}
if (current_screenID == DGUS_ScreenID::KILL) return;

if (current_screenID == DGUS_ScreenID::WAIT) {
if (screenID != DGUS_ScreenID::WAIT) {
if (screenID != DGUS_ScreenID::WAIT)
wait_return_screenID = screenID;
}

if (!abort_wait) return;

if (wait_continue && wait_for_user) {
if (wait_continue && wait_for_user)
ExtUI::setUserConfirmed();
}
}

if (!callScreenSetup(screenID)) return;
Expand Down

0 comments on commit b74958c

Please sign in to comment.