瀏覽代碼

New DGUS UI var / definition syntax (#18718)

yufanyufan 4 年之前
父節點
當前提交
469f63f74d
No account linked to committer's email address

+ 4
- 0
Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp 查看文件

@@ -107,6 +107,10 @@ void DGUSDisplay::WriteVariable(uint16_t adr, uint8_t value) {
107 107
   WriteVariable(adr, static_cast<const void*>(&value), sizeof(uint8_t));
108 108
 }
109 109
 
110
+void DGUSDisplay::WriteVariable(uint16_t adr, int8_t value) {
111
+  WriteVariable(adr, static_cast<const void*>(&value), sizeof(int8_t));
112
+}
113
+
110 114
 void DGUSDisplay::WriteVariable(uint16_t adr, long value) {
111 115
     union { long l; char lb[4]; } endian;
112 116
     char tmp[4];

+ 17
- 0
Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.h 查看文件

@@ -57,8 +57,21 @@ public:
57 57
   static void WriteVariable(uint16_t adr, int16_t value);
58 58
   static void WriteVariable(uint16_t adr, uint16_t value);
59 59
   static void WriteVariable(uint16_t adr, uint8_t value);
60
+  static void WriteVariable(uint16_t adr, int8_t value);
60 61
   static void WriteVariable(uint16_t adr, long value);
61 62
 
63
+  // Utility functions for bridging ui_api and dbus
64
+  template<typename T, float(*Getter)(const T), T selector, typename WireType=uint16_t>
65
+  static void SetVariable(DGUS_VP_Variable &var) {
66
+    WriteVariable(var.VP, (WireType)Getter(selector));
67
+  }
68
+
69
+  template<typename T, void(*Setter)(const float V, const T), T selector>
70
+  static void GetVariable(DGUS_VP_Variable &var, void *val_ptr) {
71
+    uint16_t newvalue = swap16(*(uint16_t*)val_ptr);
72
+    Setter(newvalue, selector);
73
+  }
74
+
62 75
   // Until now I did not need to actively read from the display. That's why there is no ReadVariable
63 76
   // (I extensively use the auto upload of the display)
64 77
 
@@ -83,11 +96,15 @@ private:
83 96
   static void WritePGM(const char str[], uint8_t len);
84 97
   static void ProcessRx();
85 98
 
99
+  static inline uint16_t swap16(const uint16_t value) { return (value & 0xffU) << 8U | (value >> 8U); }
86 100
   static rx_datagram_state_t rx_datagram_state;
87 101
   static uint8_t rx_datagram_len;
88 102
   static bool Initialized, no_reentrance;
89 103
 };
90 104
 
105
+#define GET_VARIABLE(f, t, V...) (&DGUSDisplay::GetVariable<decltype(t), f, t, ##V>)
106
+#define SET_VARIABLE(f, t, V...) (&DGUSDisplay::SetVariable<decltype(t), f, t, ##V>)
107
+
91 108
 extern DGUSDisplay dgusdisplay;
92 109
 
93 110
 // compile-time x^y

+ 5
- 2
Marlin/src/lcd/extui/lib/dgus/origin/DGUSDisplayDef.cpp 查看文件

@@ -35,10 +35,12 @@
35 35
 #include "../../../../../module/planner.h"
36 36
 
37 37
 #include "../../../../ultralcd.h"
38
+#include "../../../ui_api.h"
38 39
 
39 40
 #if ENABLED(DGUS_UI_MOVE_DIS_OPTION)
40 41
   uint16_t distanceToMove = 10;
41 42
 #endif
43
+using namespace ExtUI;
42 44
 
43 45
 const uint16_t VPList_Boot[] PROGMEM = {
44 46
   VP_MARLIN_VERSION,
@@ -190,8 +192,9 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = {
190 192
 
191 193
   // Temperature Data
192 194
   #if HOTENDS >= 1
193
-    VPHELPER(VP_T_E0_Is, &thermalManager.temp_hotend[0].celsius, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<0>),
194
-    VPHELPER(VP_T_E0_Set, &thermalManager.temp_hotend[0].target, ScreenHandler.HandleTemperatureChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay),
195
+    VPHELPER(VP_T_E0_Is, nullptr, nullptr, SET_VARIABLE(getActualTemp_celsius, E0, long)),
196
+    VPHELPER(VP_T_E0_Set, nullptr, GET_VARIABLE(setTargetTemp_celsius, E0),
197
+                                   SET_VARIABLE(getTargetTemp_celsius, E0)),
195 198
     VPHELPER(VP_Flowrate_E0, nullptr, ScreenHandler.HandleFlowRateChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay),
196 199
     VPHELPER(VP_EPos, &destination.e, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>),
197 200
     VPHELPER(VP_MOVE_E0, nullptr, &ScreenHandler.HandleManualExtrude, nullptr),

Loading…
取消
儲存