Ver código fonte

New DGUS UI var / definition syntax (#18718)

yufanyufan 3 anos atrás
pai
commit
469f63f74d
Nenhuma conta vinculada ao e-mail do autor do commit

+ 4
- 0
Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp Ver arquivo

107
   WriteVariable(adr, static_cast<const void*>(&value), sizeof(uint8_t));
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
 void DGUSDisplay::WriteVariable(uint16_t adr, long value) {
114
 void DGUSDisplay::WriteVariable(uint16_t adr, long value) {
111
     union { long l; char lb[4]; } endian;
115
     union { long l; char lb[4]; } endian;
112
     char tmp[4];
116
     char tmp[4];

+ 17
- 0
Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.h Ver arquivo

57
   static void WriteVariable(uint16_t adr, int16_t value);
57
   static void WriteVariable(uint16_t adr, int16_t value);
58
   static void WriteVariable(uint16_t adr, uint16_t value);
58
   static void WriteVariable(uint16_t adr, uint16_t value);
59
   static void WriteVariable(uint16_t adr, uint8_t value);
59
   static void WriteVariable(uint16_t adr, uint8_t value);
60
+  static void WriteVariable(uint16_t adr, int8_t value);
60
   static void WriteVariable(uint16_t adr, long value);
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
   // Until now I did not need to actively read from the display. That's why there is no ReadVariable
75
   // Until now I did not need to actively read from the display. That's why there is no ReadVariable
63
   // (I extensively use the auto upload of the display)
76
   // (I extensively use the auto upload of the display)
64
 
77
 
83
   static void WritePGM(const char str[], uint8_t len);
96
   static void WritePGM(const char str[], uint8_t len);
84
   static void ProcessRx();
97
   static void ProcessRx();
85
 
98
 
99
+  static inline uint16_t swap16(const uint16_t value) { return (value & 0xffU) << 8U | (value >> 8U); }
86
   static rx_datagram_state_t rx_datagram_state;
100
   static rx_datagram_state_t rx_datagram_state;
87
   static uint8_t rx_datagram_len;
101
   static uint8_t rx_datagram_len;
88
   static bool Initialized, no_reentrance;
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
 extern DGUSDisplay dgusdisplay;
108
 extern DGUSDisplay dgusdisplay;
92
 
109
 
93
 // compile-time x^y
110
 // compile-time x^y

+ 5
- 2
Marlin/src/lcd/extui/lib/dgus/origin/DGUSDisplayDef.cpp Ver arquivo

35
 #include "../../../../../module/planner.h"
35
 #include "../../../../../module/planner.h"
36
 
36
 
37
 #include "../../../../ultralcd.h"
37
 #include "../../../../ultralcd.h"
38
+#include "../../../ui_api.h"
38
 
39
 
39
 #if ENABLED(DGUS_UI_MOVE_DIS_OPTION)
40
 #if ENABLED(DGUS_UI_MOVE_DIS_OPTION)
40
   uint16_t distanceToMove = 10;
41
   uint16_t distanceToMove = 10;
41
 #endif
42
 #endif
43
+using namespace ExtUI;
42
 
44
 
43
 const uint16_t VPList_Boot[] PROGMEM = {
45
 const uint16_t VPList_Boot[] PROGMEM = {
44
   VP_MARLIN_VERSION,
46
   VP_MARLIN_VERSION,
190
 
192
 
191
   // Temperature Data
193
   // Temperature Data
192
   #if HOTENDS >= 1
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
     VPHELPER(VP_Flowrate_E0, nullptr, ScreenHandler.HandleFlowRateChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay),
198
     VPHELPER(VP_Flowrate_E0, nullptr, ScreenHandler.HandleFlowRateChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay),
196
     VPHELPER(VP_EPos, &destination.e, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>),
199
     VPHELPER(VP_EPos, &destination.e, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>),
197
     VPHELPER(VP_MOVE_E0, nullptr, &ScreenHandler.HandleManualExtrude, nullptr),
200
     VPHELPER(VP_MOVE_E0, nullptr, &ScreenHandler.HandleManualExtrude, nullptr),

Carregando…
Cancelar
Salvar