Frästisch mit elektronischer Höhenverstellung mittels Schrittmotoren.
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.

RouterSetup.cpp 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. doInitialization = true;
  13. 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.getFloat(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.putFloat(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. 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. doInitialization = true;
  150. }
  151. void RouterSetup::onRotaryControlerTurn(RotaryEncoder::Direction turn) {
  152. if (turn != RotaryEncoder::Direction::NOROTATION) {
  153. String value = "";
  154. int sign = (turn == RotaryEncoder::Direction::CLOCKWISE) ? 1 : -1;
  155. String unit = getCfgOptUnitForStepIndex(configStepIndex);
  156. switch (configStepIndex) {
  157. case 0:
  158. setSpeed(getSpeed() + 0.1 * sign);
  159. value = String(getSpeed(), 1);
  160. break;
  161. case 1:
  162. setAcceleration(getAcceleration() + 0.1 * sign);
  163. value = String(getAcceleration(), 1);
  164. break;
  165. case 2:
  166. setStepsPerRev(getStepsPerRev() + 1 * sign);
  167. value = String(getStepsPerRev());
  168. break;
  169. case 3:
  170. setPitch(getPitch() + 0.1 * sign);
  171. value = String(getPitch(), 1);
  172. break;
  173. case 4:
  174. setToolLenghtSensorHeight(getToolLenghtSensorHeight() + 0.01 * sign);
  175. value = String(getToolLenghtSensorHeight(), 2);
  176. break;
  177. case 5:
  178. setEncoderSpeedSlow(getEncoderSpeedSlow() + 1 * sign);
  179. value = String(getEncoderSpeedSlow());
  180. break;
  181. case 6:
  182. setEncoderSpeedFast(getEncoderSpeedFast() + 1 * sign);
  183. value = String(getEncoderSpeedFast());
  184. break;
  185. case 7:
  186. setLevelHeightDiving(getLevelHeightDiving() + 0.1 * sign);
  187. value = String(getLevelHeightDiving(), 1);
  188. break;
  189. case 8:
  190. setToolChangOnPowerOn(sign > 0 ? true : false);
  191. value = isToolChangOnPowerOn() ? "JA" : "NEIN";
  192. break;
  193. default:
  194. break;
  195. }
  196. display.setConfigOption(value + " " + unit);
  197. }
  198. }
  199. String RouterSetup::getCfgOptForStepIndex(byte configStepIndex) {
  200. String value = "";
  201. String unit = getCfgOptUnitForStepIndex(configStepIndex);
  202. switch (configStepIndex) {
  203. case 0:
  204. value = String(getSpeed(), 1);
  205. break;
  206. case 1:
  207. value = String(getAcceleration(), 1);
  208. break;
  209. case 2:
  210. value = String(getStepsPerRev());
  211. break;
  212. case 3:
  213. value = String(getPitch(), 1);
  214. break;
  215. case 4:
  216. value = String(getToolLenghtSensorHeight(), 2);
  217. break;
  218. case 5:
  219. value = String(getEncoderSpeedSlow());
  220. break;
  221. case 6:
  222. value = String(getEncoderSpeedFast());
  223. break;
  224. case 7:
  225. value = String(getLevelHeightDiving(), 1);
  226. break;
  227. case 8:
  228. value = isToolChangOnPowerOn() ? "JA" : "NEIN";
  229. break;
  230. default:
  231. break;
  232. }
  233. return value + " " + unit;
  234. }
  235. String RouterSetup::getCfgOptUnitForStepIndex(byte configStepIndex) {
  236. String value = "";
  237. switch (configStepIndex) {
  238. case 0:
  239. value = "U/sec";
  240. break;
  241. case 1:
  242. value = "U/sec2";
  243. break;
  244. case 3:
  245. value = "mm";
  246. break;
  247. case 4:
  248. value = "mm";
  249. break;
  250. case 5:
  251. value = "mm/100";
  252. break;
  253. case 6:
  254. value = "mm/100";
  255. break;
  256. case 7:
  257. value = "mm";
  258. break;
  259. default:
  260. break;
  261. }
  262. return value;
  263. }