-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathb_setup.hpp
More file actions
623 lines (551 loc) · 23.7 KB
/
b_setup.hpp
File metadata and controls
623 lines (551 loc) · 23.7 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
// Create the LCD menu variable and initialize the LCD (16x2 characters)
#pragma once
#if defined(OAT_DEBUG_BUILD)
PUSH_NO_WARNINGS
#if BOARD < 1000
#include "avr8-stub.h"
#else
#error "Debugging not supported on this platform"
#endif
POP_NO_WARNINGS
#endif
#if TEST_VERIFY_MODE == 1
#include "testmenu.hpp"
#endif
#ifndef NEW_STEPPER_LIB
#include "InterruptCallback.hpp"
#endif
#include "Utility.hpp"
#include "EPROMStore.hpp"
#include "a_inits.hpp"
#include "LcdMenu.hpp"
#include "LcdButtons.hpp"
#if (INFO_DISPLAY_TYPE == INFO_DISPLAY_TYPE_I2C_SSD1306_128x64)
#include "SSD1306_128x64_Display.hpp"
#endif
LcdMenu lcdMenu(16, 2, MAXMENUITEMS);
#if DISPLAY_TYPE == DISPLAY_TYPE_LCD_KEYPAD
LcdButtons lcdButtons(LCD_KEY_SENSE_PIN, &lcdMenu);
#endif
#if DISPLAY_TYPE == DISPLAY_TYPE_LCD_KEYPAD_I2C_MCP23017 || DISPLAY_TYPE == DISPLAY_TYPE_LCD_KEYPAD_I2C_MCP23008 \
|| DISPLAY_TYPE == DISPLAY_TYPE_LCD_JOY_I2C_SSD1306
LcdButtons lcdButtons(&lcdMenu);
#endif
#ifdef ESP32
DRAM_ATTR Mount mount(&lcdMenu);
#else
Mount mount(&lcdMenu);
#endif
#if (WIFI_ENABLED == 1)
#include "WifiControl.hpp"
WifiControl wifiControl(&mount, &lcdMenu);
#endif
/////////////////////////////////
// Interrupt handling
/////////////////////////////////
/* There are Two possible configurations for periodically servicing the stepper drives:
* 1) If ESP32 is #defined then a periodic task is assigned to Core 0 to service the steppers.
* stepperControlTask() is scheduled to run every 1 ms (1 kHz rate). On ESP32 the default Arduino
* loop() function runs on Core 1, therefore serial and UI activity also runs on Core 1.
* Note that Wifi drivers will be sharing Core 0 with stepperControlTask().
* This configuration decouples stepper servicing from other OAT activities by using both cores.
* 2) By default (e.g. for ATmega2560) a periodic timer is configured for a 500 us (2 kHz rate interval).
* This timr generates interrupts which are handled by stepperControlCallback(). The stepper
* servicing therefore suspends loop() to generate motion, ensuring smooth tracking.
*/
#if defined(ESP32)
TaskHandle_t StepperTask;
// This is the task for simulating periodic interrupts on ESP32 platforms.
// It should do very minimal work, only calling Mount::interruptLoop() to step the stepper motors as needed.
// This task function is run on Core 0 of the ESP32 and never returns
void IRAM_ATTR stepperControlTask(void *payload)
{
Mount *mountCopy = reinterpret_cast<Mount *>(payload);
for (;;)
{
mountCopy->interruptLoop();
}
}
#else
#ifndef NEW_STEPPER_LIB
// This is the callback function for the timer interrupt on ATMega platforms.
// It should do very minimal work, only calling Mount::interruptLoop() to step the stepper motors as needed.
// It is called every 500 us (2 kHz rate)
void stepperControlTimerCallback(void *payload)
{
Mount *mountCopy = reinterpret_cast<Mount *>(payload);
if (mountCopy)
mountCopy->interruptLoop();
}
#endif
#endif
int addConsoleText(String text)
{
#if (INFO_DISPLAY_TYPE != INFO_DISPLAY_TYPE_NONE)
return mount.getInfoDisplay()->addConsoleText(text, false);
#else
return -1;
#endif
}
void updateConsoleText(int line, String newText)
{
#if (INFO_DISPLAY_TYPE != INFO_DISPLAY_TYPE_NONE)
mount.getInfoDisplay()->updateConsoleText(line, newText);
#endif
}
/////////////////////////////////
//
// Main program setup
//
/////////////////////////////////
void setup()
{
#if defined(OAT_DEBUG_BUILD)
#if BOARD < 1000
debug_init(); // Setup avr-stub
breakpoint(); // Set a breakpoint as soon as possible
#else
#error "Debugging not supported on this platform"
#endif
#else
Serial.begin(SERIAL_BAUDRATE);
#if DEBUG_LEVEL > 0 && DEBUG_SEPARATE_SERIAL == 1
DEBUG_SERIAL_PORT.begin(DEBUG_SERIAL_BAUDRATE);
#endif
#endif
#if TEST_VERIFY_MODE == 1
#ifdef OAM
Serial.print(F("Booting OAM Firmware "));
#elif defined(OAE)
Serial.print(F("Booting OAE Firmware "));
#else
Serial.print(F("Booting OAT Firmware "));
#endif
Serial.print(VERSION);
Serial.println(F(" ..."));
#else
#ifdef OAM
LOG(DEBUG_ANY, "[SYSTEM]: Hello, universe, this is OAM Firmware %s!", VERSION);
#else
LOG(DEBUG_ANY, "[SYSTEM]: Hello, universe, this is OAT Firmware %s!", VERSION);
#endif
#endif
#if (INFO_DISPLAY_TYPE != INFO_DISPLAY_TYPE_NONE)
LOG(DEBUG_ANY, "[SYSTEM]: Get OLED info screen ready...");
mount.setupInfoDisplay();
addConsoleText(F("BOOTING " VERSION));
LOG(DEBUG_ANY, "[SYSTEM]: OLED info screen ready!");
#endif
#if USE_GPS == 1
LOG(DEBUG_ANY, "[SYSTEM]: Initializing GPS...");
#if (INFO_DISPLAY_TYPE != INFO_DISPLAY_TYPE_NONE)
int gpsLine = addConsoleText(F("Initialize GPS..."));
#endif
#if defined(ESP32) && defined(GPS_RX_PIN) && defined(GPS_TX_PIN)
GPS_SERIAL_PORT.begin(GPS_BAUD_RATE, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN);
#else
GPS_SERIAL_PORT.begin(GPS_BAUD_RATE);
#endif
#if (INFO_DISPLAY_TYPE != INFO_DISPLAY_TYPE_NONE)
updateConsoleText(gpsLine, F("Initialize GPS... OK"));
#endif
#endif
//Turn on dew heater
#if DEW_HEATER == 1
LOG(DEBUG_ANY, "[SYSTEM]: Initializing dew heater...");
int dewHeaterLine = addConsoleText(F("Enable Dew Heater..."));
#if defined(DEW_HEATER_1_PIN)
digitalWrite(DEW_HEATER_1_PIN, HIGH);
#endif
#if defined(DEW_HEATER_2_PIN)
digitalWrite(DEW_HEATER_2_PIN, HIGH);
#endif
updateConsoleText(dewHeaterLine, F("Enable Dew Heater... OK"));
#endif
#if (USE_RA_END_SWITCH == 1 || USE_DEC_END_SWITCH == 1)
int endSwitchesLine = addConsoleText(F("Init End Switches..."));
LOG(DEBUG_ANY, "[SYSTEM]: Init EndSwitches...");
mount.setupEndSwitches();
updateConsoleText(endSwitchesLine, F("Init End Switches... OK"));
#endif
/////////////////////////////////
// Microstepping/driver pins
/////////////////////////////////
int raLine = addConsoleText(F("Init RA axis..."));
LOG(DEBUG_ANY, "[SYSTEM]: Initializing RA microstepping/driver pins...");
pinMode(RA_EN_PIN, OUTPUT);
digitalWrite(RA_EN_PIN, LOW); // ENABLE, LOW to enable
#if RA_DRIVER_TYPE == DRIVER_TYPE_TMC2209_STANDALONE || RA_DRIVER_TYPE == DRIVER_TYPE_A4988_GENERIC
#if defined(RA_MS0_PIN)
digitalWrite(RA_MS0_PIN, HIGH); // MS0
#endif
#if defined(RA_MS1_PIN)
digitalWrite(RA_MS1_PIN, HIGH); // MS1
#endif
#if defined(RA_MS2_PIN)
digitalWrite(RA_MS2_PIN, HIGH); // MS2
#endif
#endif
#if RA_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
LOG(DEBUG_ANY, "[SYSTEM]: Initializing TMC2209 UART pins and Serial port for RA...");
// include TMC2209 UART pins
#if defined(RA_DIAG_PIN)
pinMode(RA_DIAG_PIN, INPUT);
#endif
#ifdef RA_SERIAL_PORT
#if defined(ESP32) && defined(RA_RX_PIN) && defined(RA_TX_PIN)
RA_SERIAL_PORT.begin(57600, SERIAL_8N1, RA_RX_PIN, RA_TX_PIN);
#else
RA_SERIAL_PORT.begin(57600); // Start HardwareSerial comms with driver
#endif
#endif
#endif
updateConsoleText(raLine, F("Init RA axis... OK"));
int decLine = addConsoleText(F("Init DEC axis..."));
LOG(DEBUG_ANY, "[SYSTEM]: Initializing DEC driver pin %s...", String(DEC_EN_PIN).c_str());
pinMode(DEC_EN_PIN, OUTPUT);
digitalWrite(DEC_EN_PIN, LOW); // ENABLE, LOW to enable
#if DEC_DRIVER_TYPE == DRIVER_TYPE_TMC2209_STANDALONE || DEC_DRIVER_TYPE == DRIVER_TYPE_A4988_GENERIC
#if defined(DEC_MS0_PIN)
digitalWrite(DEC_MS0_PIN, HIGH); // MS1
#endif
#if defined(DEC_MS1_PIN)
digitalWrite(DEC_MS1_PIN, HIGH); // MS2
#endif
#if defined(DEC_MS2_PIN)
digitalWrite(DEC_MS2_PIN, HIGH); // MS3
#endif
#endif
#if DEC_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
LOG(DEBUG_ANY, "[SYSTEM]: Initializing TMC2209 UART pins and Serial port for DEC...");
// include TMC2209 UART pins
#if defined(DEC_DIAG_PIN)
pinMode(DEC_DIAG_PIN, INPUT);
#endif
#ifdef DEC_SERIAL_PORT
#if defined(ESP32) && defined(DEC_RX_PIN) && defined(DEC_TX_PIN)
DEC_SERIAL_PORT.begin(57600, SERIAL_8N1, DEC_RX_PIN, DEC_TX_PIN);
#else
DEC_SERIAL_PORT.begin(57600); // Start HardwareSerial comms with driver
#endif
#endif
#endif
updateConsoleText(decLine, F("Init DEC axis... OK"));
LOG(DEBUG_ANY, "[SYSTEM]: RA/DEC init complete...");
#if (AZ_STEPPER_TYPE != STEPPER_TYPE_NONE)
int azLine = addConsoleText(F("Init AZ axis..."));
LOG(DEBUG_ANY, "[SYSTEM]: Initializing AZ microstepping/driver pins...");
pinMode(AZ_EN_PIN, OUTPUT);
digitalWrite(AZ_EN_PIN, HIGH); // Logic HIGH to disable the driver initally
#if AZ_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
// include TMC2209 UART pins
pinMode(AZ_DIAG_PIN, INPUT);
#ifdef AZ_SERIAL_PORT
AZ_SERIAL_PORT.begin(57600); // Start HardwareSerial comms with driver
#endif
#endif
updateConsoleText(azLine, F("Init AZ axis... OK"));
#endif
#if (ALT_STEPPER_TYPE != STEPPER_TYPE_NONE)
int altLine = addConsoleText(F("Init ALT axis..."));
LOG(DEBUG_ANY, "[SYSTEM]: Initializing ALT microstepping/driver pins...");
pinMode(ALT_EN_PIN, OUTPUT);
digitalWrite(ALT_EN_PIN, HIGH); // Logic HIGH to disable the driver initally
#if ALT_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
// include TMC2209 UART pins
pinMode(ALT_DIAG_PIN, INPUT);
#ifdef ALT_SERIAL_PORT
ALT_SERIAL_PORT.begin(57600); // Start HardwareSerial comms with driver
#endif
#endif
updateConsoleText(altLine, F("Init ALT axis... OK"));
#endif
#if (FOCUS_STEPPER_TYPE != STEPPER_TYPE_NONE)
int focusLine = addConsoleText(F("Init Focuser..."));
LOG(DEBUG_FOCUS, "[FOCUS]: setup(): focus disabling enable pin");
pinMode(FOCUS_EN_PIN, OUTPUT);
digitalWrite(FOCUS_EN_PIN, HIGH); // Logic HIGH to disable the driver initally
#if FOCUS_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
// include TMC2209 UART pins
#ifdef FOCUS_SERIAL_PORT
LOG(DEBUG_FOCUS, "[FOCUS]: setup(): focus TMC2209U starting comms");
FOCUS_SERIAL_PORT.begin(57600); // Start HardwareSerial comms with driver
#endif
#endif
updateConsoleText(focusLine, F("Init Focuser... OK"));
#endif
// end microstepping -------------------
#if USE_HALL_SENSOR_RA_AUTOHOME == 1 || USE_HALL_SENSOR_DEC_AUTOHOME == 1
int homingLine = addConsoleText(F("Init homing sensors..."));
#if USE_HALL_SENSOR_RA_AUTOHOME == 1
pinMode(RA_HOMING_SENSOR_PIN, INPUT);
#endif
#if USE_HALL_SENSOR_DEC_AUTOHOME == 1
pinMode(DEC_HOMING_SENSOR_PIN, INPUT);
#endif
updateConsoleText(homingLine, F("Init homing sensors... OK"));
#endif
LOG(DEBUG_ANY, "[SYSTEM]: Initializing EEPROM store...");
int eepromLine = addConsoleText(F("INIT EEPROM..."));
EEPROMStore::initialize();
LOG(DEBUG_ANY, "[SYSTEM]: EEPROM store ready!");
updateConsoleText(eepromLine, F("INIT EEPROM... OK"));
// Calling the LCD startup here, I2C can't be found if called earlier
#if DISPLAY_TYPE != DISPLAY_TYPE_NONE
LOG(DEBUG_ANY, "[SYSTEM]: Get LCD ready...");
int lcdLine = addConsoleText(F("Init LCD..."));
lcdMenu.startup();
// Show a splash screen
lcdMenu.setCursor(0, 0);
#ifdef OAM
lcdMenu.printMenu(" OpenAstroMount");
#elif defined(OAE)
lcdMenu.printMenu("OpenAstroExplorer");
#else
lcdMenu.printMenu("OpenAstroTracker");
#endif
lcdMenu.setCursor(5, 1);
lcdMenu.printMenu(VERSION);
delay(1000); // Pause on splash screen
// Check for EEPROM reset (Button down during boot)
long lcdCheckStart = millis();
if (lcdButtons.currentState() == btnDOWN)
{
// Wait for button release
lcdMenu.setCursor(13, 1);
lcdMenu.printMenu("CLR");
LOG(DEBUG_INFO, "[SYSTEM]: DOWN pressed, waiting for button release!");
bool timedOut = false;
while (lcdButtons.currentState() != btnNONE)
{
delay(10);
// Wait 3s maximum for button to be released.
if (millis() - lcdCheckStart > 3000)
{
LOG(DEBUG_INFO, "[SYSTEM]: Timedout waiting for button release. LCD not installed?");
timedOut = true;
break;
}
}
if (!timedOut)
{
LOG(DEBUG_INFO, "[SYSTEM]: Erasing configuration in EEPROM!");
mount.clearConfiguration();
LOG(DEBUG_INFO, "[SYSTEM]: Button released, continuing");
}
}
// Create the LCD top-level menu items
lcdMenu.addItem("RA", RA_Menu);
lcdMenu.addItem("DEC", DEC_Menu);
#if SUPPORT_POINTS_OF_INTEREST == 1
lcdMenu.addItem("GO", POI_Menu);
#else
lcdMenu.addItem("GO", Home_Menu);
#endif
lcdMenu.addItem("HA", HA_Menu);
#if SUPPORT_MANUAL_CONTROL == 1
lcdMenu.addItem("CTRL", Control_Menu);
#endif
#if SUPPORT_CALIBRATION == 1
lcdMenu.addItem("CAL", Calibration_Menu);
#endif
#if FOCUS_STEPPER_TYPE != STEPPER_TYPE_NONE
lcdMenu.addItem("FOC", Focuser_Menu);
#endif
#if SUPPORT_INFO_DISPLAY == 1
lcdMenu.addItem("INFO", Status_Menu);
#endif
updateConsoleText(lcdLine, F("Init LCD... OK"));
#endif // DISPLAY_TYPE > 0
LOG(DEBUG_ANY, "[SYSTEM]: Hardware: %s", mount.getMountHardwareInfo().c_str());
// Create the command processor singleton
LOG(DEBUG_ANY, "[SYSTEM]: Initialize LX200 handler...");
int commandProcessorLine = addConsoleText(F("Init MEADE handler..."));
MeadeCommandProcessor::createProcessor(&mount, &lcdMenu);
updateConsoleText(commandProcessorLine, F("Init MEADE handler... OK"));
#if (WIFI_ENABLED == 1)
LOG(DEBUG_ANY, "[SYSTEM]: Setup Wifi...");
wifiControl.setup();
#endif
int stepperLine = addConsoleText(F("Energize Steppers..."));
// Configure the mount
// Delay for a while to get UARTs booted...
delay(1000);
LOG(DEBUG_ANY, "[SYSTEM]: Configure steppers...");
// Set the stepper motor parameters
#if (RA_STEPPER_TYPE != STEPPER_TYPE_NONE)
LOG(DEBUG_ANY, "[STEPPERS]: Configure RA stepper NEMA.");
LOG(DEBUG_ANY, "[STEPPERS]: Slew Microsteps : %d", RA_SLEW_MICROSTEPPING);
LOG(DEBUG_ANY, "[STEPPERS]: Trk Microsteps : %d", RA_TRACKING_MICROSTEPPING);
LOG(DEBUG_ANY, "[STEPPERS]: Stepper SPR : %d", RA_STEPPER_SPR);
LOG(DEBUG_ANY, "[STEPPERS]: Transmission : %f", RA_TRANSMISSION);
#ifdef NEW_STEPPER_LIB
LOG(DEBUG_ANY, "[STEPPERS]: Driver Slew SPR : %l", config::Ra::DRIVER_SPR_SLEW);
LOG(DEBUG_ANY, "[STEPPERS]: Driver Trk SPR : %l", config::Ra::DRIVER_SPR_TRK);
LOG(DEBUG_ANY, "[STEPPERS]: SPR Slew : %f", config::Ra::SPR_SLEW);
LOG(DEBUG_ANY, "[STEPPERS]: SPR Trk : %f", config::Ra::SPR_TRK);
LOG(DEBUG_ANY, "[STEPPERS]: Speed Slew : %f", config::Ra::SPEED_SLEW);
LOG(DEBUG_ANY, "[STEPPERS]: Accel Slew : %f", config::Ra::ACCEL_SLEW);
LOG(DEBUG_ANY, "[STEPPERS]: Speed Trk : %f", config::Ra::SPEED_TRK);
LOG(DEBUG_ANY, "[STEPPERS]: Speed TrkComp : %f", config::Ra::SPEED_COMPENSATION);
LOG(DEBUG_ANY, "[STEPPERS]: Configure RA stepper NEMA...");
mount.configureRAStepper(RAmotorPin1, RAmotorPin2, config::Ra::SPEED_SLEW, config::Ra::ACCEL_SLEW);
#else
LOG(DEBUG_ANY, "[STEPPERS]: Configure RA stepper NEMA...");
mount.configureRAStepper(RAmotorPin1, RAmotorPin2, RA_STEPPER_SPEED, RA_STEPPER_ACCELERATION);
#endif
#endif
#if (DEC_STEPPER_TYPE != STEPPER_TYPE_NONE)
LOG(DEBUG_ANY, "[STEPPERS]: Configure DEC stepper NEMA.");
LOG(DEBUG_ANY, "[STEPPERS]: Slew Microsteps : %d", DEC_SLEW_MICROSTEPPING);
LOG(DEBUG_ANY, "[STEPPERS]: Guide Microsteps : %d", DEC_GUIDE_MICROSTEPPING);
LOG(DEBUG_ANY, "[STEPPERS]: Stepper SPR : %d", DEC_STEPPER_SPR);
LOG(DEBUG_ANY, "[STEPPERS]: Transmission : %f", DEC_TRANSMISSION);
#ifdef NEW_STEPPER_LIB
LOG(DEBUG_ANY, "[STEPPERS]: Driver Slew SPR : %l", config::Dec::DRIVER_SPR_SLEW);
LOG(DEBUG_ANY, "[STEPPERS]: Driver Trk SPR : %l", config::Dec::DRIVER_SPR_TRK);
LOG(DEBUG_ANY, "[STEPPERS]: SPR Slew : %f", config::Dec::SPR_SLEW);
LOG(DEBUG_ANY, "[STEPPERS]: SPR Trk : %f", config::Dec::SPR_TRK);
LOG(DEBUG_ANY, "[STEPPERS]: Speed Slew : %f", config::Dec::SPEED_SLEW);
LOG(DEBUG_ANY, "[STEPPERS]: Accel Slew : %f", config::Dec::ACCEL_SLEW);
LOG(DEBUG_ANY, "[STEPPERS]: Speed Trk : %f", config::Dec::SPEED_TRK);
LOG(DEBUG_ANY, "[STEPPERS]: Configure DEC stepper NEMA...");
mount.configureDECStepper(DECmotorPin1, DECmotorPin2, config::Dec::SPEED_SLEW, config::Dec::ACCEL_SLEW);
#else
LOG(DEBUG_ANY, "[STEPPERS]: Configure DEC stepper NEMA...");
mount.configureDECStepper(DECmotorPin1, DECmotorPin2, DEC_STEPPER_SPEED, DEC_STEPPER_ACCELERATION);
#endif
#endif
#if RA_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
LOG(DEBUG_ANY, "[STEPPERS]: Configure RA driver TMC2209 UART...");
#if SW_SERIAL_UART == 0
mount.configureRAdriver(&RA_SERIAL_PORT, R_SENSE, RA_DRIVER_ADDRESS, RA_RMSCURRENT, RA_STALL_VALUE);
#elif SW_SERIAL_UART == 1
mount.configureRAdriver(RA_SERIAL_PORT_RX, RA_SERIAL_PORT_TX, R_SENSE, RA_DRIVER_ADDRESS, RA_RMSCURRENT, RA_STALL_VALUE);
#endif
#endif
#if DEC_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
LOG(DEBUG_ANY, "[STEPPERS]: Configure DEC driver TMC2209 UART...");
#if SW_SERIAL_UART == 0
mount.configureDECdriver(&DEC_SERIAL_PORT, R_SENSE, DEC_DRIVER_ADDRESS, DEC_RMSCURRENT, DEC_STALL_VALUE);
#elif SW_SERIAL_UART == 1
mount.configureDECdriver(DEC_SERIAL_PORT_RX, DEC_SERIAL_PORT_TX, R_SENSE, DEC_DRIVER_ADDRESS, DEC_RMSCURRENT, DEC_STALL_VALUE);
#endif
#endif
#if (AZ_STEPPER_TYPE != STEPPER_TYPE_NONE)
LOG(DEBUG_ANY, "[STEPPERS]: Configure AZ stepper...");
LOG(DEBUG_ANY, "[STEPPERS]: AZ Microsteps : %d", AZ_MICROSTEPPING);
LOG(DEBUG_ANY, "[STEPPERS]: AZ Stepper SPR : %d", AZ_STEPPER_SPR);
LOG(DEBUG_ANY, "[STEPPERS]: AZ Circumference : %f", AZ_CIRCUMFERENCE);
LOG(DEBUG_ANY, "[STEPPERS]: AZ steps/rev : %f", AZIMUTH_STEPS_PER_REV);
LOG(DEBUG_ANY, "[STEPPERS]: AZ steps/deg : %f", mount.getStepsPerDegree(AZIMUTH_STEPS));
LOG(DEBUG_ANY, "[STEPPERS]: AZ steps/minute : %f", AZIMUTH_STEPS_PER_ARC_MINUTE);
mount.configureAZStepper(AZmotorPin1, AZmotorPin2, AZ_STEPPER_SPEED, AZ_STEPPER_ACCELERATION);
#if AZ_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
LOG(DEBUG_ANY, "[STEPPERS]: Configure AZ driver...");
#if SW_SERIAL_UART == 0
mount.configureAZdriver(&AZ_SERIAL_PORT, R_SENSE, AZ_DRIVER_ADDRESS, AZ_RMSCURRENT, AZ_STALL_VALUE);
#elif SW_SERIAL_UART == 1
mount.configureAZdriver(AZ_SERIAL_PORT_RX, AZ_SERIAL_PORT_TX, R_SENSE, AZ_DRIVER_ADDRESS, AZ_RMSCURRENT, AZ_STALL_VALUE);
#endif
#endif
#endif
#if (ALT_STEPPER_TYPE != STEPPER_TYPE_NONE)
LOG(DEBUG_ANY, "[STEPPERS]: Configure Alt stepper...");
LOG(DEBUG_ANY, "[STEPPERS]: ALT Microsteps : %d", ALT_MICROSTEPPING);
LOG(DEBUG_ANY, "[STEPPERS]: ALT Stepper SPR : %d", ALT_STEPPER_SPR);
LOG(DEBUG_ANY, "[STEPPERS]: ALT Circumference : %f", ALT_CIRCUMFERENCE);
LOG(DEBUG_ANY, "[STEPPERS]: ALT steps/rev : %f", ALTITUDE_STEPS_PER_REV);
LOG(DEBUG_ANY, "[STEPPERS]: ALT steps/deg : %f", mount.getStepsPerDegree(ALTITUDE_STEPS));
LOG(DEBUG_ANY, "[STEPPERS]: ALT steps/minute : %f", ALTITUDE_STEPS_PER_ARC_MINUTE);
mount.configureALTStepper(ALTmotorPin1, ALTmotorPin2, ALT_STEPPER_SPEED, ALT_STEPPER_ACCELERATION);
#if ALT_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
LOG(DEBUG_ANY, "[STEPPERS]: Configure ALT driver...");
#if SW_SERIAL_UART == 0
mount.configureALTdriver(&ALT_SERIAL_PORT, R_SENSE, ALT_DRIVER_ADDRESS, ALT_RMSCURRENT, ALT_STALL_VALUE);
#elif SW_SERIAL_UART == 1
mount.configureALTdriver(ALT_SERIAL_PORT_RX, ALT_SERIAL_PORT_TX, R_SENSE, ALT_DRIVER_ADDRESS, ALT_RMSCURRENT, ALT_STALL_VALUE);
#endif
#endif
#endif
#if (FOCUS_STEPPER_TYPE != STEPPER_TYPE_NONE)
LOG(DEBUG_ANY, "[STEPPERS]: setup(): Configure Focus stepper...");
mount.configureFocusStepper(FOCUSmotorPin1, FOCUSmotorPin2, FOCUS_STEPPER_SPEED, FOCUS_STEPPER_ACCELERATION);
#if FOCUS_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
LOG(DEBUG_ANY, "[STEPPERS]: setup(): Configure Focus driver...");
LOG(DEBUG_FOCUS, "[FOCUS]: setup(): RSense %f, RMS Current %fmA", R_SENSE, FOCUS_RMSCURRENT);
#if SW_SERIAL_UART == 0
mount.configureFocusDriver(&FOCUS_SERIAL_PORT, R_SENSE, FOCUS_DRIVER_ADDRESS, FOCUS_RMSCURRENT, FOCUS_STALL_VALUE);
#elif SW_SERIAL_UART == 1
mount.configureFocusDriver(
FOCUS_SERIAL_PORT_RX, FOCUS_SERIAL_PORT_TX, R_SENSE, FOCUS_DRIVER_ADDRESS, FOCUS_RMSCURRENT, FOCUS_STALL_VALUE);
#endif
#endif
#endif
LOG(DEBUG_ANY, "[SYSTEM]: Energize Steppers... OK");
updateConsoleText(stepperLine, F("Energize Steppers... OK"));
int configureLine = addConsoleText(F("Configure Mount..."));
LOG(DEBUG_ANY, "[SYSTEM]: Read Configuration...");
// The mount uses EEPROM storage locations 0-10 that it reads during construction
// The LCD uses EEPROM storage location 11
mount.readConfiguration();
// Read other persisted values and set in mount
DayTime haTime = EEPROMStore::getHATime();
LOG(DEBUG_INFO, "[SYSTEM]: SpeedCal: %s", String(mount.getSpeedCalibration(), 5).c_str());
LOG(DEBUG_INFO, "[SYSTEM]: TRKSpeed: %s", String(mount.getSpeed(TRACKING), 5).c_str());
mount.setHA(haTime);
// For LCD screen, it's better to initialize the target to where we are (RA)
mount.targetRA() = mount.currentRA();
// Setup service to periodically service the steppers.
#if defined(ESP32)
LOG(DEBUG_ANY, "[SYSTEM]: Setup StepperControlTask on Core 0...");
disableCore0WDT();
xTaskCreatePinnedToCore(stepperControlTask, // Function to run on this core
"StepperControl", // Name of this task
32767, // Stack space in bytes
&mount, // payload
1, // Priority (2 is higher than 1)
&StepperTask, // The location that receives the thread id
0); // The core to run this on
#else
#ifndef NEW_STEPPER_LIB
// 2 kHz updates (higher frequency interferes with serial communications and complete messes up OATControl communications)
if (!InterruptCallback::setInterval(0.5f, stepperControlTimerCallback, &mount))
{
LOG(DEBUG_MOUNT, "[SYSTEM]: CANNOT setup interrupt timer!");
}
#endif
#endif
updateConsoleText(configureLine, F("Configure Mount... OK"));
#if UART_CONNECTION_TEST_TX == 1
int testLine = addConsoleText(F("Test UARTs..."));
#if RA_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
LOG(DEBUG_STEPPERS, "[STEPPERS]: Moving RA axis using UART commands...");
mount.testRA_UART_TX();
LOG(DEBUG_STEPPERS, "[STEPPERS]: Finished moving RA axis using UART commands.");
#endif
#if DEC_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
LOG(DEBUG_STEPPERS, "[STEPPERS]: Moving DEC axis using UART commands...");
mount.testDEC_UART_TX();
LOG(DEBUG_STEPPERS, "[STEPPERS]: Finished moving DEC axis using UART commands.");
#endif
updateConsoleText(testLine, F("Test UARTs... OK"));
#endif
LOG(DEBUG_ANY, "[SYSTEM]: Setting %s hemisphere...", inNorthernHemisphere ? "northern" : "southern");
mount.configureHemisphere(inNorthernHemisphere, true);
#if TRACK_ON_BOOT == 1
// Start the tracker.
LOG(DEBUG_ANY, "[SYSTEM]: Start Tracking...");
mount.startSlewing(TRACKING);
#endif
mount.bootComplete();
LOG(DEBUG_ANY, "[SYSTEM]: Boot complete!");
addConsoleText(F("BOOT COMPLETE!"));
#if (INFO_DISPLAY_TYPE != INFO_DISPLAY_TYPE_NONE)
delay(500);
mount.getInfoDisplay()->setConsoleMode(false);
#endif
#if TEST_VERIFY_MODE == 1
TestMenu::getCurrentMenu()->display();
#endif
}