Frästisch mit elektronischer Höhenverstellung mittels Schrittmotoren.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

RouterSetup.cpp 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * RouterSetup.cpp
  3. *
  4. * Created on: 25.01.2022
  5. * Author: FSmilari
  6. */
  7. #include "RouterSetup.h"
  8. /******************
  9. ** Constructors
  10. *****************/
  11. RouterSetup::RouterSetup(Display &_display) : display(_display) {
  12. this->doInitialization = true;
  13. this->configStepIndex = 0;
  14. }
  15. /******************
  16. ** Public methods
  17. *****************/
  18. float RouterSetup::getSpeed() const {
  19. return speed;
  20. }
  21. void RouterSetup::setSpeed(float speed) {
  22. this->speed = speed;
  23. }
  24. float RouterSetup::getAcceleration() const {
  25. return accelleration;
  26. }
  27. void RouterSetup::setAcceleration(float accelleration) {
  28. this->accelleration = accelleration;
  29. }
  30. uint8_t RouterSetup::getEncoderSpeedFast() const {
  31. return encoderSpeedFast;
  32. }
  33. void RouterSetup::setEncoderSpeedFast(uint8_t encoderSpeedFast) {
  34. this->encoderSpeedFast = encoderSpeedFast;
  35. }
  36. uint8_t RouterSetup::getEncoderSpeedSlow() const {
  37. return encoderSpeedSlow;
  38. }
  39. void RouterSetup::setEncoderSpeedSlow(uint8_t encoderSpeedSlow) {
  40. this->encoderSpeedSlow = encoderSpeedSlow;
  41. }
  42. float RouterSetup::getLevelHeightDiving() const {
  43. return levelHeightDiving;
  44. }
  45. void RouterSetup::setLevelHeightDiving(float levelHeightDiving) {
  46. this->levelHeightDiving = levelHeightDiving;
  47. }
  48. float RouterSetup::getPitch() const {
  49. return pitch;
  50. }
  51. void RouterSetup::setPitch(float pitch) {
  52. this->pitch = pitch;
  53. }
  54. uint16_t RouterSetup::getStepsPerRev() const {
  55. return stepsPerRev;
  56. }
  57. void RouterSetup::setStepsPerRev(uint16_t stepsPerRev) {
  58. this->stepsPerRev = stepsPerRev;
  59. }
  60. float RouterSetup::getToolLenghtSensorHeight() const {
  61. return toolLenghtSensorHeight;
  62. }
  63. void RouterSetup::setToolLenghtSensorHeight(float toolLenghtSensorHeight) {
  64. this->toolLenghtSensorHeight = toolLenghtSensorHeight;
  65. }
  66. bool RouterSetup::isToolChangOnPowerOn() const {
  67. return toolChangeOnPowerOn;
  68. }
  69. void RouterSetup::setToolChangOnPowerOn(bool toolChangOnPowerOn) {
  70. this->toolChangeOnPowerOn = toolChangOnPowerOn;
  71. }
  72. void RouterSetup::clear() {
  73. speed = 0;
  74. accelleration = 0;
  75. stepsPerRev = 0;
  76. pitch = 0;
  77. toolLenghtSensorHeight = 0;
  78. encoderSpeedSlow = 0;
  79. encoderSpeedFast = 0;
  80. levelHeightDiving = 0;
  81. toolChangeOnPowerOn = true;
  82. }
  83. /**
  84. * Reads the RouterSetup from EEPROM
  85. */
  86. void RouterSetup::readFromEEPROM() {
  87. clear();
  88. eeprom.begin(ROUTER_NAMESPACE, false);
  89. setSpeed(eeprom.getFloat(SPEED, 1.0));
  90. setAcceleration(eeprom.getFloat(ACCELERATION, 1.0));
  91. setStepsPerRev(eeprom.getUInt(STEPSPERREV, 1600));
  92. setPitch(eeprom.getInt(PITCH, 3.0));
  93. setToolLenghtSensorHeight(eeprom.getFloat(TOOLLENGHTSNHT, 10.0));
  94. setEncoderSpeedSlow(eeprom.getInt(ENCSPEEDSLOW, 1));
  95. setEncoderSpeedFast(eeprom.getInt(ENCSPEEDFAST, 20));
  96. setLevelHeightDiving(eeprom.getFloat(LVLHEIGHTDIVE, 3.0));
  97. setToolChangOnPowerOn(eeprom.getBool(TOOLCHGONPWRON, true));
  98. eeprom.end();
  99. }
  100. /**
  101. * Writes the RouterSetup to EEPROM
  102. */
  103. void RouterSetup::saveToEEPROM() {
  104. eeprom.begin(ROUTER_NAMESPACE, false);
  105. eeprom.putFloat(SPEED, getSpeed());
  106. eeprom.putFloat(ACCELERATION, getAcceleration());
  107. eeprom.putUInt(STEPSPERREV, getStepsPerRev());
  108. eeprom.putInt(PITCH, getPitch());
  109. eeprom.putFloat(TOOLLENGHTSNHT, getToolLenghtSensorHeight());
  110. eeprom.putInt(ENCSPEEDSLOW, getEncoderSpeedSlow());
  111. eeprom.putInt(ENCSPEEDFAST, getEncoderSpeedFast());
  112. eeprom.putFloat(LVLHEIGHTDIVE, getLevelHeightDiving());
  113. eeprom.putBool(TOOLCHGONPWRON, isToolChangOnPowerOn());
  114. eeprom.end();
  115. }
  116. void RouterSetup::printValues() {
  117. Serial.print(String(SPEED) + ": " + String(getSpeed(), 1) + ", ");
  118. Serial.print(String(ACCELERATION) + ": " + String(getAcceleration(), 1) + ", ");
  119. Serial.print(String(STEPSPERREV) + ": " + String(getStepsPerRev()) + ", ");
  120. Serial.print(String(PITCH) + ": " + String(getPitch(), 1) + ", ");
  121. Serial.print(String(TOOLLENGHTSNHT) + ": " + String(getToolLenghtSensorHeight(), 2) + ", ");
  122. Serial.print(String(ENCSPEEDSLOW) + ": " + String(getEncoderSpeedSlow()) + ", ");
  123. Serial.print(String(ENCSPEEDFAST) + ": " + String(getEncoderSpeedFast()) + ", ");
  124. Serial.print(String(LVLHEIGHTDIVE) + ": " + String(getLevelHeightDiving(), 2) + ", ");
  125. Serial.println(String(TOOLCHGONPWRON) + ": " + String(isToolChangOnPowerOn()));
  126. }
  127. void RouterSetup::initialize() {
  128. if (doInitialization) {
  129. configStepIndex = 0;
  130. String stepTxt = ConfigStep[configStepIndex];
  131. String option = getCfgOptForStepIndex(configStepIndex);
  132. option.trim();
  133. display.setConfigText(stepTxt);
  134. display.setConfigOption(option);
  135. this->doInitialization = false;
  136. }
  137. }
  138. void RouterSetup::onRotaryControlerSwitch() {
  139. configStepIndex++;
  140. configStepIndex = configStepIndex % 9;
  141. String stepTxt = ConfigStep[configStepIndex];
  142. String option = getCfgOptForStepIndex(configStepIndex);
  143. option.trim();
  144. display.setConfigText(stepTxt);
  145. display.setConfigOption(option);
  146. }
  147. void RouterSetup::onRotaryControlerLongSwitch() {
  148. saveToEEPROM();
  149. this->doInitialization = true;
  150. }
  151. void RouterSetup::onRotaryControlerTurn(RotaryEncoder::Direction turn) {
  152. switch (turn) {
  153. case RotaryEncoder::Direction::CLOCKWISE:
  154. break;
  155. case RotaryEncoder::Direction::COUNTERCLOCKWISE:
  156. break;
  157. default:
  158. break;
  159. }
  160. }
  161. String RouterSetup::getCfgOptForStepIndex(byte configStepIndex) {
  162. String value = "";
  163. String unit = getCfgOptUnitForStepIndex(configStepIndex);
  164. switch (configStepIndex) {
  165. case 0:
  166. value = String(getSpeed(), 1);
  167. break;
  168. case 1:
  169. value = String(getAcceleration(), 1);
  170. break;
  171. case 2:
  172. value = String(getStepsPerRev());
  173. break;
  174. case 3:
  175. value = String(getPitch(), 1);
  176. break;
  177. case 4:
  178. value = String(getToolLenghtSensorHeight(), 2);
  179. break;
  180. case 5:
  181. value = String(getEncoderSpeedSlow());
  182. break;
  183. case 6:
  184. value = String(getEncoderSpeedFast());
  185. break;
  186. case 7:
  187. value = String(getLevelHeightDiving(), 1);
  188. break;
  189. case 8:
  190. value = isToolChangOnPowerOn() ? "JA" : "NEIN";
  191. break;
  192. default:
  193. break;
  194. }
  195. return value + " " + unit;
  196. }
  197. String RouterSetup::getCfgOptUnitForStepIndex(byte configStepIndex) {
  198. String value = "";
  199. switch (configStepIndex) {
  200. case 0:
  201. value = "U/sec";
  202. break;
  203. case 1:
  204. value = "U/sec2";
  205. break;
  206. case 3:
  207. value = "mm";
  208. break;
  209. case 4:
  210. value = "mm";
  211. break;
  212. case 5:
  213. value = "mm/100";
  214. break;
  215. case 6:
  216. value = "mm/100";
  217. break;
  218. case 7:
  219. value = "mm";
  220. break;
  221. default:
  222. break;
  223. }
  224. return value;
  225. }