My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

M3426.cpp 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #include "../../../inc/MarlinConfig.h"
  23. #if ENABLED(HAS_MCP3426_ADC)
  24. #include "../../gcode.h"
  25. #include "../../../feature/adc/adc_mcp3426.h"
  26. /**
  27. * M3426: Read 16 bit (signed) value from I2C MCP3426 ADC device
  28. *
  29. * M3426 C<byte-1 value in base 10> channel 1 or 2
  30. * M3426 G<byte-1 value in base 10> gain 1, 2, 4 or 8
  31. * M3426 I<byte-2 value in base 10> 0 or 1, invert reply
  32. */
  33. void GcodeSuite::M3426() {
  34. uint8_t channel = parser.byteval('C', 1), // Select the channel 1 or 2
  35. gain = parser.byteval('G', 1);
  36. const bool inverted = parser.byteval('I') == 1;
  37. if (channel <= 2 && (gain == 1 || gain == 2 || gain == 4 || gain == 8)) {
  38. int16_t result = mcp3426.ReadValue(channel, gain);
  39. if (mcp3426.Error == false) {
  40. if (inverted) {
  41. // Should we invert the reading (32767 - ADC value) ?
  42. // Caters to end devices that expect values to increase when in reality they decrease.
  43. // e.g., A pressure sensor in a vacuum when the end device expects a positive pressure.
  44. result = INT16_MAX - result;
  45. }
  46. //SERIAL_ECHOPGM(STR_OK);
  47. SERIAL_ECHOLNPGM("V:", result, " C:", channel, " G:", gain, " I:", inverted ? 1 : 0);
  48. }
  49. else
  50. SERIAL_ERROR_MSG("MCP342X i2c error");
  51. }
  52. else
  53. SERIAL_ERROR_MSG("MCP342X Bad request");
  54. }
  55. #endif // HAS_MCP3426_ADC