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 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. /* DGUS implementation written by coldtobi in 2019 for Marlin */
  24. #include "../../../../inc/MarlinConfigPre.h"
  25. #include "../../../../MarlinCore.h"
  26. #if HAS_BED_PROBE
  27. #include "../../../../module/probe.h"
  28. #endif
  29. #include "DGUSVPVariable.h"
  30. enum DGUSLCD_Screens : uint8_t;
  31. #define DEBUG_OUT ENABLED(DEBUG_DGUSLCD)
  32. #include "../../../../core/debug_out.h"
  33. typedef enum : uint8_t {
  34. DGUS_IDLE, //< waiting for DGUS_HEADER1.
  35. DGUS_HEADER1_SEEN, //< DGUS_HEADER1 received
  36. DGUS_HEADER2_SEEN, //< DGUS_HEADER2 received
  37. DGUS_WAIT_TELEGRAM, //< LEN received, Waiting for to receive all bytes.
  38. } rx_datagram_state_t;
  39. // Low-Level access to the display.
  40. class DGUSDisplay {
  41. public:
  42. DGUSDisplay() = default;
  43. static void InitDisplay();
  44. // Variable access.
  45. static void WriteVariable(uint16_t adr, const void* values, uint8_t valueslen, bool isstr=false);
  46. static void WriteVariablePGM(uint16_t adr, const void* values, uint8_t valueslen, bool isstr=false);
  47. static void WriteVariable(uint16_t adr, uint16_t value);
  48. // Until now I did not need to actively read from the display. That's why there is no ReadVariable
  49. // (I extensively use the auto upload of the display)
  50. // Force display into another screen.
  51. // (And trigger update of containing VPs)
  52. // (to implement a pop up message, which may not be nested)
  53. static void RequestScreen(DGUSLCD_Screens screen);
  54. // Periodic tasks, eg. Rx-Queue handling.
  55. static void loop();
  56. public:
  57. // Helper for users of this class to estimate if an interaction would be blocking.
  58. static size_t GetFreeTxBuffer();
  59. // Checks two things: Can we confirm the presence of the display and has we initiliazed it.
  60. // (both boils down that the display answered to our chatting)
  61. static inline bool isInitialized() { return Initialized; }
  62. private:
  63. static void WriteHeader(uint16_t adr, uint8_t cmd, uint8_t payloadlen);
  64. static void WritePGM(const char str[], uint8_t len);
  65. static void ProcessRx();
  66. static rx_datagram_state_t rx_datagram_state;
  67. static uint8_t rx_datagram_len;
  68. static bool Initialized, no_reentrance;
  69. };
  70. extern DGUSDisplay dgusdisplay;
  71. // compile-time x^y
  72. constexpr float cpow(const float x, const int y) { return y == 0 ? 1.0 : x * cpow(x, y - 1); }
  73. /// Find the flash address of a DGUS_VP_Variable for the VP.
  74. extern const DGUS_VP_Variable* DGUSLCD_FindVPVar(const uint16_t vp);
  75. /// Helper to populate a DGUS_VP_Variable for a given VP. Return false if not found.
  76. extern bool populate_VPVar(const uint16_t VP, DGUS_VP_Variable * const ramcopy);