Skip to content

Commit 03af68a

Browse files
Add Test mode via terminal (#258)
1 parent 693cbaa commit 03af68a

File tree

12 files changed

+1063
-36
lines changed

12 files changed

+1063
-36
lines changed

Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
**V1.13.12 - Updates**
2+
- Added basic test mode that can be run via terminal connection.
3+
14
**V1.13.11 - Updates**
25
- Fixed DEBUG macro usage.
36
- Clarified some Meade documentation.

Version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
// Also, numbers are interpreted as simple numbers. _ __ _
44
// So 1.8 is actually 1.08, meaning that 1.12 is a later version than 1.8. \_(..)_/
55

6-
#define VERSION "V1.13.11"
6+
#define VERSION "V1.13.12"

matrix_build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"FOCUS_STEPPER_TYPE": STEPPER_TYPES,
5858
"FOCUS_DRIVER_TYPE": DRIVER_TYPES,
5959
"DISPLAY_TYPE": DISPLAY_TYPES,
60+
"TEST_VERIFY_MODE": BOOLEAN_VALUES,
6061
"DEBUG_LEVEL": ["DEBUG_NONE", "DEBUG_ANY"],
6162
"RA_MOTOR_CURRENT_RATING": "1",
6263
"RA_OPERATING_CURRENT_SETTING": "1",

src/Mount.cpp

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -413,23 +413,56 @@ void Mount::configureFocusStepper(byte pin1, byte pin2, int maxSpeed, int maxAcc
413413
#if RA_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART || DEC_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART \
414414
|| AZ_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART || ALT_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART \
415415
|| FOCUS_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
416-
#if UART_CONNECTION_TEST_TXRX == 1
417-
bool Mount::connectToDriver(TMC2209Stepper *driver, const char *driverKind)
416+
#if (UART_CONNECTION_TEST_TXRX == 1) || (TEST_VERIFY_MODE == 1)
417+
bool Mount::connectToDriver(const String &driverKind, uint16_t *rmsCurrent)
418418
{
419-
LOG(DEBUG_STEPPERS, "[STEPPERS]: Testing UART Connection to %s driver...", driverKind);
420-
for (int i = 0; i < UART_CONNECTION_TEST_RETRIES; i++)
419+
MappedDict<String, TMC2209Stepper *>::DictEntry_t lookupTable[] = {
420+
#if RA_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
421+
{"RA", _driverRA},
422+
#endif
423+
#if DEC_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
424+
{"DEC", _driverDEC},
425+
#endif
426+
#if ALT_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
427+
{"ALT", _driverALT},
428+
#endif
429+
#if AZ_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
430+
{"AZ", _driverAZ},
431+
#endif
432+
#if FOCUS_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
433+
{"FOC", _driverFocus},
434+
#endif
435+
};
436+
auto driverLookup = MappedDict<String, TMC2209Stepper *>(lookupTable, ARRAY_SIZE(lookupTable));
437+
438+
TMC2209Stepper *driver = nullptr;
439+
driverLookup.tryGet(driverKind, &driver);
440+
441+
if (driver != nullptr)
421442
{
422-
if (driver->test_connection() == 0)
443+
LOG(DEBUG_STEPPERS, "[STEPPERS]: Testing UART Connection to %s driver...", driverKind.c_str());
444+
for (int i = 0; i < UART_CONNECTION_TEST_RETRIES; i++)
423445
{
424-
LOG(DEBUG_STEPPERS, "[STEPPERS]: UART connection to %s driver successful.", driverKind);
425-
return true;
426-
}
427-
else
428-
{
429-
delay(500);
446+
if (driver->test_connection() == 0)
447+
{
448+
LOG(DEBUG_STEPPERS, "[STEPPERS]: UART connection to %s driver successful.", driverKind.c_str());
449+
if (rmsCurrent != nullptr)
450+
{
451+
*rmsCurrent = driver->rms_current();
452+
}
453+
return true;
454+
}
455+
else
456+
{
457+
delay(500);
458+
}
430459
}
460+
LOG(DEBUG_STEPPERS, "[STEPPERS]: UART connection to %s driver failed.", driverKind.c_str());
461+
}
462+
if (rmsCurrent != nullptr)
463+
{
464+
*rmsCurrent = 0;
431465
}
432-
LOG(DEBUG_STEPPERS, "[STEPPERS]: UART connection to %s driver failed.", driverKind);
433466
return false;
434467
}
435468
#endif
@@ -448,7 +481,7 @@ void Mount::configureRAdriver(Stream *serial, float rsense, byte driveraddress,
448481
_driverRA->begin();
449482
bool UART_Rx_connected = false;
450483
#if UART_CONNECTION_TEST_TXRX == 1
451-
UART_Rx_connected = connectToDriver(_driverRA, "RA");
484+
UART_Rx_connected = connectToDriver("RA");
452485
if (!UART_Rx_connected)
453486
{
454487
digitalWrite(RA_EN_PIN,
@@ -487,7 +520,7 @@ void Mount::configureRAdriver(uint16_t RA_SW_RX, uint16_t RA_SW_TX, float rsense
487520
_driverRA->pdn_disable(true);
488521
bool UART_Rx_connected = false;
489522
#if UART_CONNECTION_TEST_TXRX == 1
490-
UART_Rx_connected = connectToDriver(_driverRA, "RA");
523+
UART_Rx_connected = connectToDriver("RA");
491524
if (!UART_Rx_connected)
492525
{
493526
digitalWrite(RA_EN_PIN,
@@ -531,7 +564,7 @@ void Mount::configureDECdriver(Stream *serial, float rsense, byte driveraddress,
531564
_driverDEC->begin();
532565
bool UART_Rx_connected = false;
533566
#if UART_CONNECTION_TEST_TXRX == 1
534-
UART_Rx_connected = connectToDriver(_driverDEC, "DEC");
567+
UART_Rx_connected = connectToDriver("DEC");
535568
if (!UART_Rx_connected)
536569
{
537570
digitalWrite(DEC_EN_PIN,
@@ -570,7 +603,7 @@ void Mount::configureDECdriver(uint16_t DEC_SW_RX, uint16_t DEC_SW_TX, float rse
570603
_driverDEC->pdn_disable(true);
571604
bool UART_Rx_connected = false;
572605
#if UART_CONNECTION_TEST_TXRX == 1
573-
UART_Rx_connected = connectToDriver(_driverDEC, "DEC");
606+
UART_Rx_connected = connectToDriver("DEC");
574607
if (!UART_Rx_connected)
575608
{
576609
digitalWrite(DEC_EN_PIN,
@@ -614,7 +647,7 @@ void Mount::configureAZdriver(Stream *serial, float rsense, byte driveraddress,
614647
_driverAZ->begin();
615648
bool UART_Rx_connected = false;
616649
#if UART_CONNECTION_TEST_TXRX == 1
617-
UART_Rx_connected = connectToDriver(_driverAZ, "AZ");
650+
UART_Rx_connected = connectToDriver("AZ");
618651
if (!UART_Rx_connected)
619652
{
620653
digitalWrite(AZ_EN_PIN,
@@ -652,7 +685,7 @@ void Mount::configureAZdriver(uint16_t AZ_SW_RX, uint16_t AZ_SW_TX, float rsense
652685
_driverAZ->pdn_disable(true);
653686
bool UART_Rx_connected = false;
654687
#if UART_CONNECTION_TEST_TXRX == 1
655-
UART_Rx_connected = connectToDriver(_driverAZ, "AZ");
688+
UART_Rx_connected = connectToDriver("AZ");
656689
if (!UART_Rx_connected)
657690
{
658691
digitalWrite(AZ_EN_PIN,
@@ -695,7 +728,7 @@ void Mount::configureALTdriver(Stream *serial, float rsense, byte driveraddress,
695728
_driverALT->begin();
696729
bool UART_Rx_connected = false;
697730
#if UART_CONNECTION_TEST_TXRX == 1
698-
UART_Rx_connected = connectToDriver(_driverALT, "ALT");
731+
UART_Rx_connected = connectToDriver("ALT");
699732
if (!UART_Rx_connected)
700733
{
701734
digitalWrite(ALT_EN_PIN,
@@ -733,7 +766,7 @@ void Mount::configureALTdriver(uint16_t ALT_SW_RX, uint16_t ALT_SW_TX, float rse
733766
_driverALT->pdn_disable(true);
734767
#if UART_CONNECTION_TEST_TXRX == 1
735768
bool UART_Rx_connected = false;
736-
UART_Rx_connected = connectToDriver(_driverALT, "ALT");
769+
UART_Rx_connected = connectToDriver("ALT");
737770
if (!UART_Rx_connected)
738771
{
739772
digitalWrite(ALT_EN_PIN,
@@ -778,10 +811,10 @@ void Mount::configureFocusDriver(Stream *serial, float rsense, byte driveraddres
778811
_driverFocus->begin();
779812
#if UART_CONNECTION_TEST_TXRX == 1
780813
bool UART_Rx_connected = false;
781-
UART_Rx_connected = connectToDriver(_driverFocus, "Focus");
814+
UART_Rx_connected = connectToDriver("FOC");
782815
if (!UART_Rx_connected)
783816
{
784-
digitalWrite(ALT_EN_PIN,
817+
digitalWrite(FOCUS_EN_PIN,
785818
HIGH); //Disable motor for safety reasons if UART connection fails to avoid operating at incorrect rms_current
786819
}
787820
#endif
@@ -824,7 +857,7 @@ void Mount::configureFocusDriver(
824857
_driverFocus->pdn_disable(true);
825858
#if UART_CONNECTION_TEST_TXRX == 1
826859
bool UART_Rx_connected = false;
827-
UART_Rx_connected = connectToDriver(_driverFocus, "Focus");
860+
UART_Rx_connected = connectToDriver("FOC");
828861
if (!UART_Rx_connected)
829862
{
830863
digitalWrite(FOCUS_EN_PIN,

src/Mount.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ class Mount
154154

155155
void initializeVariables();
156156

157-
static Mount instance();
158-
159157
// Configure the RA stepper motor. This also sets up the TRK stepper on the same pins.
160158
void configureRAStepper(byte pin1, byte pin2, uint32_t maxSpeed, uint32_t maxAcceleration);
161159

@@ -182,7 +180,8 @@ class Mount
182180
#if RA_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART || DEC_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART \
183181
|| AZ_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART || ALT_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART \
184182
|| FOCUS_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
185-
bool connectToDriver(TMC2209Stepper *driver, const char *driverKind);
183+
bool connectToDriver(const String &driverKind, uint16_t *rmsCurrent = nullptr);
184+
186185
#endif
187186
#if RA_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
188187
// Configure the RA Driver (TMC2209 UART only)

src/Utility.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,46 @@ float atanf(float x)
226226
return static_cast<float>(atan(static_cast<double>(x)));
227227
}
228228

229+
String *splitStringBy(String str, char splitChar)
230+
{
231+
unsigned int count = 1; // At least one string if input is non-empty
232+
233+
// Count occurrences of splitChar to determine the number of splits
234+
for (unsigned int i = 0; i < str.length(); i++)
235+
{
236+
if (str[i] == splitChar)
237+
{
238+
count++;
239+
}
240+
}
241+
242+
// Dynamically allocate memory for the resulting array
243+
String *array = new String[count + 1]; // +1 for the nullptr terminator
244+
unsigned int r = 0; // Start of the substring
245+
unsigned int t = 0; // Index in the result array
246+
247+
// Iterate through the string to split it
248+
for (unsigned int i = 0; i < str.length(); i++)
249+
{
250+
if (str[i] == splitChar)
251+
{
252+
array[t++] = str.substring(r, i); // Store substring
253+
r = i + 1; // Move start to next character
254+
}
255+
}
256+
257+
// Add the last part of the string
258+
if (r < str.length())
259+
{
260+
array[t++] = str.substring(r);
261+
}
262+
263+
// Mark the end of the array with ""
264+
array[t] = "";
265+
266+
return array;
267+
}
268+
229269
#if defined(ESP32)
230270
int freeMemory()
231271
{

src/Utility.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,11 @@ int sign(long num);
173173
int fsign(float num);
174174

175175
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
176+
#define CASERETURN(c, r) \
177+
case c: \
178+
return r
179+
180+
// Return an array of String* with a nullptr sentinel
181+
String *splitStringBy(String str, char splitChar);
176182

177183
#endif

src/b_setup.hpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ PUSH_NO_WARNINGS
1212
POP_NO_WARNINGS
1313
#endif
1414

15+
#if TEST_VERIFY_MODE == 1
16+
#include "testmenu.hpp"
17+
#endif
18+
1519
#ifndef NEW_STEPPER_LIB
1620
#include "InterruptCallback.hpp"
1721
#endif
@@ -111,7 +115,21 @@ void setup()
111115
#endif
112116
#endif
113117

114-
LOG(DEBUG_ANY, "[SYSTEM]: Hello, universe, this is OAT %s!", VERSION);
118+
#if TEST_VERIFY_MODE == 1
119+
#ifdef OAM
120+
Serial.print(F("Booting OAM Firmware "));
121+
#else
122+
Serial.print(F("Booting OAT Firmware "));
123+
#endif
124+
Serial.print(VERSION);
125+
Serial.println(F(" ..."));
126+
#else
127+
#ifdef OAM
128+
LOG(DEBUG_ANY, "[SYSTEM]: Hello, universe, this is OAM Firmware %s!", VERSION);
129+
#else
130+
LOG(DEBUG_ANY, "[SYSTEM]: Hello, universe, this is OAT Firmware %s!", VERSION);
131+
#endif
132+
#endif
115133

116134
#if (INFO_DISPLAY_TYPE != INFO_DISPLAY_TYPE_NONE)
117135
LOG(DEBUG_ANY, "[SYSTEM]: Get OLED info screen ready...");
@@ -522,4 +540,7 @@ void setup()
522540
delay(250);
523541
mount.getInfoDisplay()->setConsoleMode(false);
524542
#endif
543+
#if TEST_VERIFY_MODE == 1
544+
TestMenu::getCurrentMenu()->display();
545+
#endif
525546
}

0 commit comments

Comments
 (0)