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

Propose a new syntax to define UI for dgus #18718

Merged
merged 3 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ void DGUSDisplay::WriteVariable(uint16_t adr, uint8_t value) {
WriteVariable(adr, static_cast<const void*>(&value), sizeof(uint8_t));
}

void DGUSDisplay::WriteVariable(uint16_t adr, int8_t value) {
WriteVariable(adr, static_cast<const void*>(&value), sizeof(int8_t));
}

void DGUSDisplay::WriteVariable(uint16_t adr, long value) {
union { long l; char lb[4]; } endian;
char tmp[4];
Expand Down
17 changes: 17 additions & 0 deletions Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,21 @@ class DGUSDisplay {
static void WriteVariable(uint16_t adr, int16_t value);
static void WriteVariable(uint16_t adr, uint16_t value);
static void WriteVariable(uint16_t adr, uint8_t value);
static void WriteVariable(uint16_t adr, int8_t value);
static void WriteVariable(uint16_t adr, long value);

// Utility functions for bridging ui_api and dbus
template<typename T, float(*Getter)(const T), T selector, typename WireType=uint16_t>
static void SetVariable(DGUS_VP_Variable &var) {
WriteVariable(var.VP, (WireType)Getter(selector));
}

template<typename T, void(*Setter)(const float V, const T), T selector>
static void GetVariable(DGUS_VP_Variable &var, void *val_ptr) {
uint16_t newvalue = swap16(*(uint16_t*)val_ptr);
Setter(newvalue, selector);
}

// Until now I did not need to actively read from the display. That's why there is no ReadVariable
// (I extensively use the auto upload of the display)

Expand All @@ -83,11 +96,15 @@ class DGUSDisplay {
static void WritePGM(const char str[], uint8_t len);
static void ProcessRx();

static inline uint16_t swap16(const uint16_t value) { return (value & 0xffU) << 8U | (value >> 8U); }
static rx_datagram_state_t rx_datagram_state;
static uint8_t rx_datagram_len;
static bool Initialized, no_reentrance;
};

#define GET_VARIABLE(f, t, V...) (&DGUSDisplay::GetVariable<decltype(t), f, t, ##V>)
#define SET_VARIABLE(f, t, V...) (&DGUSDisplay::SetVariable<decltype(t), f, t, ##V>)

extern DGUSDisplay dgusdisplay;

// compile-time x^y
Expand Down
7 changes: 5 additions & 2 deletions Marlin/src/lcd/extui/lib/dgus/origin/DGUSDisplayDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
#include "../../../../../module/planner.h"

#include "../../../../ultralcd.h"
#include "../../../ui_api.h"

#if ENABLED(DGUS_UI_MOVE_DIS_OPTION)
uint16_t distanceToMove = 10;
#endif
using namespace ExtUI;

const uint16_t VPList_Boot[] PROGMEM = {
VP_MARLIN_VERSION,
Expand Down Expand Up @@ -190,8 +192,9 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = {

// Temperature Data
#if HOTENDS >= 1
VPHELPER(VP_T_E0_Is, &thermalManager.temp_hotend[0].celsius, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<0>),
VPHELPER(VP_T_E0_Set, &thermalManager.temp_hotend[0].target, ScreenHandler.HandleTemperatureChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay),
VPHELPER(VP_T_E0_Is, nullptr, nullptr, SET_VARIABLE(getActualTemp_celsius, E0, long)),
VPHELPER(VP_T_E0_Set, nullptr, GET_VARIABLE(setTargetTemp_celsius, E0),
SET_VARIABLE(getTargetTemp_celsius, E0)),
VPHELPER(VP_Flowrate_E0, nullptr, ScreenHandler.HandleFlowRateChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay),
VPHELPER(VP_EPos, &destination.e, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>),
VPHELPER(VP_MOVE_E0, nullptr, &ScreenHandler.HandleManualExtrude, nullptr),
Expand Down