OnStepX.ino 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Title OnStepX
  3. * by Howard Dutton
  4. *
  5. * Copyright (C) 2021-2024 Howard Dutton
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. * Description:
  21. * Full featured telescope control for
  22. * Equatorial and Alt-Az mounts
  23. * Rotator
  24. * Focusers
  25. * Accessories (automatic covers, dew heaters, etc.)
  26. *
  27. * Author: Howard Dutton
  28. * http://www.stellarjourney.com
  29. * hjd1964@gmail.com
  30. *
  31. * Revision history, and newer versions:
  32. * See GitHub: https://github.com/hjd1964/OnStep
  33. *
  34. * Documentation:
  35. * https://groups.io/g/onstep/wiki/home
  36. *
  37. * Discussion, Questions, ...etc
  38. * https://groups.io/g/onstep
  39. */
  40. // Use tabs "Config..." to configure OnStep to your requirements
  41. // Firmware version ----------------------------------------------------------------------------------------------------------------
  42. #define FirmwareName "On-Step"
  43. #define FirmwareVersionMajor 10
  44. #define FirmwareVersionMinor 25 // minor version 00 to 99
  45. #define FirmwareVersionPatch "c" // for example major.minor patch: 10.03c
  46. #define FirmwareVersionConfig 6 // internal, for tracking configuration file changes
  47. #include "src/Common.h"
  48. NVS nv;
  49. #include "src/Validate.h"
  50. #include "src/lib/sense/Sense.h"
  51. #include "src/lib/tasks/OnTask.h"
  52. #include "src/telescope/Telescope.h"
  53. extern Telescope telescope;
  54. #include "src/plugins/Plugins.config.h"
  55. #if DEBUG == PROFILER
  56. extern void profiler();
  57. #endif
  58. void systemServices() {
  59. if (!xBusy) nv.poll(false);
  60. }
  61. void sensesPoll() {
  62. sense.poll();
  63. }
  64. void setup() {
  65. #if ADDON_SELECT_PIN != OFF
  66. pinMode(ADDON_SELECT_PIN, OUTPUT);
  67. digitalWrite(ADDON_SELECT_PIN, HIGH);
  68. #endif
  69. #if DEBUG != OFF
  70. SERIAL_DEBUG.begin(SERIAL_DEBUG_BAUD);
  71. delay(2000);
  72. #endif
  73. // let any special processing the pinmap needs happen
  74. #ifdef PIN_INIT
  75. PIN_INIT();
  76. #endif
  77. // say hello
  78. VLF("");
  79. VF("MSG: OnStepX, version "); V(FirmwareVersionMajor); V("."); V(FirmwareVersionMinor); VL(FirmwareVersionPatch);
  80. VF("MSG: OnStepX, MCU "); VLF(MCU_STR);
  81. VF("MSG: OnStepX, pinmap "); VLF(PINMAP_STR);
  82. // start low level hardware
  83. VLF("MSG: Setup, HAL initialize");
  84. HAL_INIT();
  85. if (!HAL_NV_INIT()) {
  86. DLF("WRN: Setup, NV (EEPROM/FRAM/FlashMem/etc.) device not found!");
  87. nv.initError = true;
  88. }
  89. delay(2000);
  90. // start system service task
  91. VF("MSG: Setup, start system service task (rate 10ms priority 7)... ");
  92. // add task for system services, runs at 10ms intervals so commiting 1KB of NV takes about 10 seconds
  93. // the cache is scanned (for writing) at 2000 bytes/second but can be slower while reading data into the cache at startup
  94. if (tasks.add(10, 0, true, 7, systemServices, "SysSvcs")) { VLF("success"); } else { VLF("FAILED!"); }
  95. // start input sense polling task
  96. int pollingRate = round((1000.0F/HAL_FRACTIONAL_SEC)/2.0F);
  97. if (pollingRate < 1) pollingRate = 1;
  98. VF("MSG: Setup, start input sense polling task (rate "); V(pollingRate); VF("ms priority 7)... ");
  99. if (tasks.add(pollingRate, 0, true, 7, sensesPoll, "SenPoll")) { VLF("success"); } else { VLF("FAILED!"); }
  100. // start telescope object
  101. telescope.init(FirmwareName, FirmwareVersionMajor, FirmwareVersionMinor, FirmwareVersionPatch, FirmwareVersionConfig);
  102. // start command channel tasks
  103. commandChannelInit();
  104. tasks.yield(2000);
  105. // start any plugins
  106. #if PLUGIN1 != OFF
  107. PLUGIN1.init();
  108. #endif
  109. #if PLUGIN2 != OFF
  110. PLUGIN2.init();
  111. #endif
  112. #if PLUGIN3 != OFF
  113. PLUGIN3.init();
  114. #endif
  115. #if PLUGIN4 != OFF
  116. PLUGIN4.init();
  117. #endif
  118. #if PLUGIN5 != OFF
  119. PLUGIN5.init();
  120. #endif
  121. #if PLUGIN6 != OFF
  122. PLUGIN6.init();
  123. #endif
  124. #if PLUGIN7 != OFF
  125. PLUGIN7.init();
  126. #endif
  127. #if PLUGIN8 != OFF
  128. PLUGIN8.init();
  129. #endif
  130. // start task manager debug events
  131. #if DEBUG == PROFILER
  132. tasks.add(142, 0, true, 7, profiler, "Profilr");
  133. #endif
  134. sense.poll();
  135. telescope.ready = true;
  136. }
  137. void loop() {
  138. tasks.yield();
  139. }