My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

main.cpp 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #ifdef __PLAT_LINUX__
  23. //#define GPIO_LOGGING // Full GPIO and Positional Logging
  24. #include "../../inc/MarlinConfig.h"
  25. #include "../shared/Delay.h"
  26. #include "hardware/IOLoggerCSV.h"
  27. #include "hardware/Heater.h"
  28. #include "hardware/LinearAxis.h"
  29. #include <stdio.h>
  30. #include <stdarg.h>
  31. #include <thread>
  32. #include <iostream>
  33. #include <fstream>
  34. extern void setup();
  35. extern void loop();
  36. // simple stdout / stdin implementation for fake serial port
  37. void write_serial_thread() {
  38. for (;;) {
  39. for (std::size_t i = usb_serial.transmit_buffer.available(); i > 0; i--) {
  40. fputc(usb_serial.transmit_buffer.read(), stdout);
  41. }
  42. std::this_thread::yield();
  43. }
  44. }
  45. void read_serial_thread() {
  46. char buffer[255] = {};
  47. for (;;) {
  48. std::size_t len = _MIN(usb_serial.receive_buffer.free(), 254U);
  49. if (fgets(buffer, len, stdin))
  50. for (std::size_t i = 0; i < strlen(buffer); i++)
  51. usb_serial.receive_buffer.write(buffer[i]);
  52. std::this_thread::yield();
  53. }
  54. }
  55. void simulation_loop() {
  56. Heater hotend(HEATER_0_PIN, TEMP_0_PIN);
  57. Heater bed(HEATER_BED_PIN, TEMP_BED_PIN);
  58. LinearAxis x_axis(X_ENABLE_PIN, X_DIR_PIN, X_STEP_PIN, X_MIN_PIN, X_MAX_PIN);
  59. LinearAxis y_axis(Y_ENABLE_PIN, Y_DIR_PIN, Y_STEP_PIN, Y_MIN_PIN, Y_MAX_PIN);
  60. LinearAxis z_axis(Z_ENABLE_PIN, Z_DIR_PIN, Z_STEP_PIN, Z_MIN_PIN, Z_MAX_PIN);
  61. LinearAxis extruder0(E0_ENABLE_PIN, E0_DIR_PIN, E0_STEP_PIN, P_NC, P_NC);
  62. #ifdef GPIO_LOGGING
  63. IOLoggerCSV logger("all_gpio_log.csv");
  64. Gpio::attachLogger(&logger);
  65. std::ofstream position_log;
  66. position_log.open("axis_position_log.csv");
  67. int32_t x,y,z;
  68. #endif
  69. for (;;) {
  70. hotend.update();
  71. bed.update();
  72. x_axis.update();
  73. y_axis.update();
  74. z_axis.update();
  75. extruder0.update();
  76. #ifdef GPIO_LOGGING
  77. if (x_axis.position != x || y_axis.position != y || z_axis.position != z) {
  78. uint64_t update = _MAX(x_axis.last_update, y_axis.last_update, z_axis.last_update);
  79. position_log << update << ", " << x_axis.position << ", " << y_axis.position << ", " << z_axis.position << std::endl;
  80. position_log.flush();
  81. x = x_axis.position;
  82. y = y_axis.position;
  83. z = z_axis.position;
  84. }
  85. // flush the logger
  86. logger.flush();
  87. #endif
  88. std::this_thread::yield();
  89. }
  90. }
  91. int main() {
  92. std::thread write_serial (write_serial_thread);
  93. std::thread read_serial (read_serial_thread);
  94. #ifdef MYSERIAL1
  95. MYSERIAL1.begin(BAUDRATE);
  96. SERIAL_ECHOLNPGM("x86_64 Initialized");
  97. SERIAL_FLUSHTX();
  98. #endif
  99. Clock::setFrequency(F_CPU);
  100. Clock::setTimeMultiplier(1.0); // some testing at 10x
  101. HAL_timer_init();
  102. std::thread simulation (simulation_loop);
  103. DELAY_US(10000);
  104. setup();
  105. for (;;) {
  106. loop();
  107. std::this_thread::yield();
  108. }
  109. simulation.join();
  110. write_serial.join();
  111. read_serial.join();
  112. }
  113. #endif // __PLAT_LINUX__