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.

encoder.h 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2021 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. * @file lcd/e3v2/common/encoder.h
  25. * @brief Rotary encoder functions
  26. ****************************************************************************/
  27. #include "../../../inc/MarlinConfig.h"
  28. /*********************** Encoder Set ***********************/
  29. typedef struct {
  30. bool enabled = false;
  31. int encoderMoveValue = 0;
  32. millis_t lastEncoderTime = 0;
  33. } ENCODER_Rate;
  34. extern ENCODER_Rate EncoderRate;
  35. typedef enum {
  36. ENCODER_DIFF_NO = 0, // no state
  37. ENCODER_DIFF_CW = 1, // clockwise rotation
  38. ENCODER_DIFF_CCW = 2, // counterclockwise rotation
  39. ENCODER_DIFF_ENTER = 3 // click
  40. } EncoderState;
  41. #define ENCODER_WAIT_MS 20
  42. // Encoder initialization
  43. void Encoder_Configuration();
  44. // Analyze encoder value and return state
  45. EncoderState Encoder_ReceiveAnalyze();
  46. inline EncoderState get_encoder_state() {
  47. static millis_t Encoder_ms = 0;
  48. const millis_t ms = millis();
  49. if (PENDING(ms, Encoder_ms)) return ENCODER_DIFF_NO;
  50. const EncoderState state = Encoder_ReceiveAnalyze();
  51. if (state != ENCODER_DIFF_NO) Encoder_ms = ms + ENCODER_WAIT_MS;
  52. return state;
  53. }
  54. template<typename T>
  55. inline bool Apply_Encoder(const EncoderState &encoder_diffState, T &valref) {
  56. if (encoder_diffState == ENCODER_DIFF_CW)
  57. valref += EncoderRate.encoderMoveValue;
  58. else if (encoder_diffState == ENCODER_DIFF_CCW)
  59. valref -= EncoderRate.encoderMoveValue;
  60. return encoder_diffState == ENCODER_DIFF_ENTER;
  61. }
  62. /*********************** Encoder LED ***********************/
  63. #if PIN_EXISTS(LCD_LED)
  64. #define LED_NUM 4
  65. #define LED_DATA_HIGH WRITE(LCD_LED_PIN, 1)
  66. #define LED_DATA_LOW WRITE(LCD_LED_PIN, 0)
  67. #define RGB_SCALE_R10_G7_B5 1
  68. #define RGB_SCALE_R10_G7_B4 2
  69. #define RGB_SCALE_R10_G8_B7 3
  70. #define RGB_SCALE_NEUTRAL_WHITE RGB_SCALE_R10_G7_B5
  71. #define RGB_SCALE_WARM_WHITE RGB_SCALE_R10_G7_B4
  72. #define RGB_SCALE_COOL_WHITE RGB_SCALE_R10_G8_B7
  73. extern unsigned int LED_DataArray[LED_NUM];
  74. // LED light operation
  75. void LED_Action();
  76. // LED initialization
  77. void LED_Configuration();
  78. // LED write data
  79. void LED_WriteData();
  80. // LED control
  81. // RGB_Scale: RGB color ratio
  82. // luminance: brightness (0~0xFF)
  83. void LED_Control(const uint8_t RGB_Scale, const uint8_t luminance);
  84. // LED gradient control
  85. // RGB_Scale: RGB color ratio
  86. // luminance: brightness (0~0xFF)
  87. // change_Time: gradient time (ms)
  88. void LED_GraduallyControl(const uint8_t RGB_Scale, const uint8_t luminance, const uint16_t change_Interval);
  89. #endif // LCD_LED