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.

LinearAxis.cpp 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2019 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. #ifdef __PLAT_LINUX__
  23. #include <random>
  24. #include <stdio.h>
  25. #include "Clock.h"
  26. #include "LinearAxis.h"
  27. LinearAxis::LinearAxis(pin_type enable, pin_type dir, pin_type step, pin_type end_min, pin_type end_max) {
  28. enable_pin = enable;
  29. dir_pin = dir;
  30. step_pin = step;
  31. min_pin = end_min;
  32. max_pin = end_max;
  33. min_position = 50;
  34. max_position = (200*80) + min_position;
  35. position = rand() % ((max_position - 40) - min_position) + (min_position + 20);
  36. last_update = Clock::nanos();
  37. Gpio::attachPeripheral(step_pin, this);
  38. }
  39. LinearAxis::~LinearAxis() {
  40. }
  41. void LinearAxis::update() {
  42. }
  43. void LinearAxis::interrupt(GpioEvent ev) {
  44. if (ev.pin_id == step_pin && !Gpio::pin_map[enable_pin].value){
  45. if (ev.event == GpioEvent::RISE) {
  46. last_update = ev.timestamp;
  47. position += -1 + 2 * Gpio::pin_map[dir_pin].value;
  48. Gpio::pin_map[min_pin].value = (position < min_position);
  49. //Gpio::pin_map[max_pin].value = (position > max_position);
  50. //if (position < min_position) printf("axis(%d) endstop : pos: %d, mm: %f, min: %d\n", step_pin, position, position / 80.0, Gpio::pin_map[min_pin].value);
  51. }
  52. }
  53. }
  54. #endif // __PLAT_LINUX__