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.

adjuster_widget.cpp 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /***********************
  2. * adjuster_widget.cpp *
  3. ***********************/
  4. /****************************************************************************
  5. * Written By Marcio Teixeira 2021 - Cocoa Press *
  6. * *
  7. * This program is free software: you can redistribute it and/or modify *
  8. * it under the terms of the GNU General Public License as published by *
  9. * the Free Software Foundation, either version 3 of the License, or *
  10. * (at your option) any later version. *
  11. * *
  12. * This program is distributed in the hope that it will be useful, *
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15. * GNU General Public License for more details. *
  16. * *
  17. * To view a copy of the GNU General Public License, go to the following *
  18. * location: <https://www.gnu.org/licenses/>. *
  19. ****************************************************************************/
  20. #include "../ftdi_eve_lib.h"
  21. #include "../extended/grid_layout.h"
  22. #include "adjuster_widget.h"
  23. #define SUB_COLS 9
  24. #define SUB_ROWS 1
  25. #define VAL_POS SUB_POS(1,1), SUB_SIZE(5,1)
  26. #define INC_POS SUB_POS(6,1), SUB_SIZE(2,1)
  27. #define DEC_POS SUB_POS(8,1), SUB_SIZE(2,1)
  28. void draw_adjuster_value(CommandProcessor& cmd, int16_t x, int16_t y, int16_t w, int16_t h, float value, progmem_str units, int8_t width, uint8_t precision) {
  29. char str[width + precision + 10 + (units ? strlen_P((const char*) units) : 0)];
  30. if (isnan(value))
  31. strcpy_P(str, PSTR("-"));
  32. else
  33. dtostrf(value, width, precision, str);
  34. if (units) {
  35. strcat_P(str, PSTR(" "));
  36. strcat_P(str, (const char*) units);
  37. }
  38. cmd.text(VAL_POS, str);
  39. }
  40. void draw_adjuster(CommandProcessor& cmd, int16_t x, int16_t y, int16_t w, int16_t h, uint8_t tag, float value, progmem_str units, int8_t width, uint8_t precision, draw_mode_t what) {
  41. if (what & BACKGROUND)
  42. cmd.tag(0).button(VAL_POS, F(""), FTDI::OPT_FLAT);
  43. if (what & FOREGROUND) {
  44. draw_adjuster_value(cmd, x, y, w, h, value, units, width, precision);
  45. cmd.tag(tag ).button(INC_POS, F("-"))
  46. .tag(tag+1).button(DEC_POS, F("+"));
  47. }
  48. }