My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DGUSDisplay.h 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. /**
  24. * lcd/extui/dgus/DGUSDisplay.h
  25. */
  26. #include "../../../inc/MarlinConfigPre.h"
  27. #include <stdlib.h> // size_t
  28. #if HAS_BED_PROBE
  29. #include "../../../module/probe.h"
  30. #endif
  31. #include "DGUSVPVariable.h"
  32. enum DGUSLCD_Screens : uint8_t;
  33. //#define DEBUG_DGUSLCD
  34. #define DEBUG_OUT ENABLED(DEBUG_DGUSLCD)
  35. #include "../../../core/debug_out.h"
  36. typedef enum : uint8_t {
  37. DGUS_IDLE, //< waiting for DGUS_HEADER1.
  38. DGUS_HEADER1_SEEN, //< DGUS_HEADER1 received
  39. DGUS_HEADER2_SEEN, //< DGUS_HEADER2 received
  40. DGUS_WAIT_TELEGRAM, //< LEN received, Waiting for to receive all bytes.
  41. } rx_datagram_state_t;
  42. // Low-Level access to the display.
  43. class DGUSDisplay {
  44. public:
  45. DGUSDisplay() = default;
  46. static void InitDisplay();
  47. // Variable access.
  48. static void WriteVariable(uint16_t adr, const void *values, uint8_t valueslen, bool isstr=false);
  49. static void WriteVariablePGM(uint16_t adr, const void *values, uint8_t valueslen, bool isstr=false);
  50. static void WriteVariable(uint16_t adr, int16_t value);
  51. static void WriteVariable(uint16_t adr, uint16_t value);
  52. static void WriteVariable(uint16_t adr, uint8_t value);
  53. static void WriteVariable(uint16_t adr, int8_t value);
  54. static void WriteVariable(uint16_t adr, long value);
  55. static void MKS_WriteVariable(uint16_t adr, uint8_t value);
  56. // Utility functions for bridging ui_api and dbus
  57. template<typename T, float(*Getter)(const T), T selector, typename WireType=uint16_t>
  58. static void SetVariable(DGUS_VP_Variable &var) {
  59. WriteVariable(var.VP, (WireType)Getter(selector));
  60. }
  61. template<typename T, void(*Setter)(const float V, const T), T selector>
  62. static void GetVariable(DGUS_VP_Variable &var, void *val_ptr) {
  63. uint16_t newvalue = swap16(*(uint16_t*)val_ptr);
  64. Setter(newvalue, selector);
  65. }
  66. // Until now I did not need to actively read from the display. That's why there is no ReadVariable
  67. // (I extensively use the auto upload of the display)
  68. // Force display into another screen.
  69. // (And trigger update of containing VPs)
  70. // (to implement a pop up message, which may not be nested)
  71. static void RequestScreen(DGUSLCD_Screens screen);
  72. // Periodic tasks, eg. Rx-Queue handling.
  73. static void loop();
  74. public:
  75. // Helper for users of this class to estimate if an interaction would be blocking.
  76. static size_t GetFreeTxBuffer();
  77. // Checks two things: Can we confirm the presence of the display and has we initialized it.
  78. // (both boils down that the display answered to our chatting)
  79. static inline bool isInitialized() { return Initialized; }
  80. private:
  81. static void WriteHeader(uint16_t adr, uint8_t cmd, uint8_t payloadlen);
  82. static void WritePGM(const char str[], uint8_t len);
  83. static void ProcessRx();
  84. static inline uint16_t swap16(const uint16_t value) { return (value & 0xFFU) << 8U | (value >> 8U); }
  85. static rx_datagram_state_t rx_datagram_state;
  86. static uint8_t rx_datagram_len;
  87. static bool Initialized, no_reentrance;
  88. };
  89. extern DGUSDisplay dgusdisplay;
  90. // compile-time x^y
  91. constexpr float cpow(const float x, const int y) { return y == 0 ? 1.0 : x * cpow(x, y - 1); }
  92. ///
  93. const uint16_t* DGUSLCD_FindScreenVPMapList(uint8_t screen);
  94. /// Find the flash address of a DGUS_VP_Variable for the VP.
  95. const DGUS_VP_Variable* DGUSLCD_FindVPVar(const uint16_t vp);
  96. /// Helper to populate a DGUS_VP_Variable for a given VP. Return false if not found.
  97. bool populate_VPVar(const uint16_t VP, DGUS_VP_Variable * const ramcopy);