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