Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
**V1.13.12 - Updates**
- Added basic test mode that can be run via terminal connection.

**V1.13.11 - Updates**
- Fixed DEBUG macro usage.
- Clarified some Meade documentation.
Expand Down
2 changes: 1 addition & 1 deletion Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
// Also, numbers are interpreted as simple numbers. _ __ _
// So 1.8 is actually 1.08, meaning that 1.12 is a later version than 1.8. \_(..)_/

#define VERSION "V1.13.11"
#define VERSION "V1.13.12"
1 change: 1 addition & 0 deletions matrix_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"FOCUS_STEPPER_TYPE": STEPPER_TYPES,
"FOCUS_DRIVER_TYPE": DRIVER_TYPES,
"DISPLAY_TYPE": DISPLAY_TYPES,
"TEST_VERIFY_MODE": BOOLEAN_VALUES,
"DEBUG_LEVEL": ["DEBUG_NONE", "DEBUG_ANY"],
"RA_MOTOR_CURRENT_RATING": "1",
"RA_OPERATING_CURRENT_SETTING": "1",
Expand Down
79 changes: 56 additions & 23 deletions src/Mount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,23 +413,56 @@ void Mount::configureFocusStepper(byte pin1, byte pin2, int maxSpeed, int maxAcc
#if RA_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART || DEC_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART \
|| AZ_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART || ALT_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART \
|| FOCUS_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
#if UART_CONNECTION_TEST_TXRX == 1
bool Mount::connectToDriver(TMC2209Stepper *driver, const char *driverKind)
#if (UART_CONNECTION_TEST_TXRX == 1) || (TEST_VERIFY_MODE == 1)
bool Mount::connectToDriver(const String &driverKind, uint16_t *rmsCurrent)
{
LOG(DEBUG_STEPPERS, "[STEPPERS]: Testing UART Connection to %s driver...", driverKind);
for (int i = 0; i < UART_CONNECTION_TEST_RETRIES; i++)
MappedDict<String, TMC2209Stepper *>::DictEntry_t lookupTable[] = {
#if RA_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
{"RA", _driverRA},
#endif
#if DEC_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
{"DEC", _driverDEC},
#endif
#if ALT_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
{"ALT", _driverALT},
#endif
#if AZ_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
{"AZ", _driverAZ},
#endif
#if FOCUS_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
{"FOC", _driverFocus},
#endif
};
auto driverLookup = MappedDict<String, TMC2209Stepper *>(lookupTable, ARRAY_SIZE(lookupTable));

TMC2209Stepper *driver = nullptr;
driverLookup.tryGet(driverKind, &driver);

if (driver != nullptr)
{
if (driver->test_connection() == 0)
LOG(DEBUG_STEPPERS, "[STEPPERS]: Testing UART Connection to %s driver...", driverKind.c_str());
for (int i = 0; i < UART_CONNECTION_TEST_RETRIES; i++)
{
LOG(DEBUG_STEPPERS, "[STEPPERS]: UART connection to %s driver successful.", driverKind);
return true;
}
else
{
delay(500);
if (driver->test_connection() == 0)
{
LOG(DEBUG_STEPPERS, "[STEPPERS]: UART connection to %s driver successful.", driverKind.c_str());
if (rmsCurrent != nullptr)
{
*rmsCurrent = driver->rms_current();
}
return true;
}
else
{
delay(500);
}
}
LOG(DEBUG_STEPPERS, "[STEPPERS]: UART connection to %s driver failed.", driverKind.c_str());
}
if (rmsCurrent != nullptr)
{
*rmsCurrent = 0;
}
LOG(DEBUG_STEPPERS, "[STEPPERS]: UART connection to %s driver failed.", driverKind);
return false;
}
#endif
Expand All @@ -448,7 +481,7 @@ void Mount::configureRAdriver(Stream *serial, float rsense, byte driveraddress,
_driverRA->begin();
bool UART_Rx_connected = false;
#if UART_CONNECTION_TEST_TXRX == 1
UART_Rx_connected = connectToDriver(_driverRA, "RA");
UART_Rx_connected = connectToDriver("RA");
if (!UART_Rx_connected)
{
digitalWrite(RA_EN_PIN,
Expand Down Expand Up @@ -487,7 +520,7 @@ void Mount::configureRAdriver(uint16_t RA_SW_RX, uint16_t RA_SW_TX, float rsense
_driverRA->pdn_disable(true);
bool UART_Rx_connected = false;
#if UART_CONNECTION_TEST_TXRX == 1
UART_Rx_connected = connectToDriver(_driverRA, "RA");
UART_Rx_connected = connectToDriver("RA");
if (!UART_Rx_connected)
{
digitalWrite(RA_EN_PIN,
Expand Down Expand Up @@ -531,7 +564,7 @@ void Mount::configureDECdriver(Stream *serial, float rsense, byte driveraddress,
_driverDEC->begin();
bool UART_Rx_connected = false;
#if UART_CONNECTION_TEST_TXRX == 1
UART_Rx_connected = connectToDriver(_driverDEC, "DEC");
UART_Rx_connected = connectToDriver("DEC");
if (!UART_Rx_connected)
{
digitalWrite(DEC_EN_PIN,
Expand Down Expand Up @@ -570,7 +603,7 @@ void Mount::configureDECdriver(uint16_t DEC_SW_RX, uint16_t DEC_SW_TX, float rse
_driverDEC->pdn_disable(true);
bool UART_Rx_connected = false;
#if UART_CONNECTION_TEST_TXRX == 1
UART_Rx_connected = connectToDriver(_driverDEC, "DEC");
UART_Rx_connected = connectToDriver("DEC");
if (!UART_Rx_connected)
{
digitalWrite(DEC_EN_PIN,
Expand Down Expand Up @@ -614,7 +647,7 @@ void Mount::configureAZdriver(Stream *serial, float rsense, byte driveraddress,
_driverAZ->begin();
bool UART_Rx_connected = false;
#if UART_CONNECTION_TEST_TXRX == 1
UART_Rx_connected = connectToDriver(_driverAZ, "AZ");
UART_Rx_connected = connectToDriver("AZ");
if (!UART_Rx_connected)
{
digitalWrite(AZ_EN_PIN,
Expand Down Expand Up @@ -652,7 +685,7 @@ void Mount::configureAZdriver(uint16_t AZ_SW_RX, uint16_t AZ_SW_TX, float rsense
_driverAZ->pdn_disable(true);
bool UART_Rx_connected = false;
#if UART_CONNECTION_TEST_TXRX == 1
UART_Rx_connected = connectToDriver(_driverAZ, "AZ");
UART_Rx_connected = connectToDriver("AZ");
if (!UART_Rx_connected)
{
digitalWrite(AZ_EN_PIN,
Expand Down Expand Up @@ -695,7 +728,7 @@ void Mount::configureALTdriver(Stream *serial, float rsense, byte driveraddress,
_driverALT->begin();
bool UART_Rx_connected = false;
#if UART_CONNECTION_TEST_TXRX == 1
UART_Rx_connected = connectToDriver(_driverALT, "ALT");
UART_Rx_connected = connectToDriver("ALT");
if (!UART_Rx_connected)
{
digitalWrite(ALT_EN_PIN,
Expand Down Expand Up @@ -733,7 +766,7 @@ void Mount::configureALTdriver(uint16_t ALT_SW_RX, uint16_t ALT_SW_TX, float rse
_driverALT->pdn_disable(true);
#if UART_CONNECTION_TEST_TXRX == 1
bool UART_Rx_connected = false;
UART_Rx_connected = connectToDriver(_driverALT, "ALT");
UART_Rx_connected = connectToDriver("ALT");
if (!UART_Rx_connected)
{
digitalWrite(ALT_EN_PIN,
Expand Down Expand Up @@ -778,10 +811,10 @@ void Mount::configureFocusDriver(Stream *serial, float rsense, byte driveraddres
_driverFocus->begin();
#if UART_CONNECTION_TEST_TXRX == 1
bool UART_Rx_connected = false;
UART_Rx_connected = connectToDriver(_driverFocus, "Focus");
UART_Rx_connected = connectToDriver("FOC");
if (!UART_Rx_connected)
{
digitalWrite(ALT_EN_PIN,
digitalWrite(FOCUS_EN_PIN,
HIGH); //Disable motor for safety reasons if UART connection fails to avoid operating at incorrect rms_current
}
#endif
Expand Down Expand Up @@ -824,7 +857,7 @@ void Mount::configureFocusDriver(
_driverFocus->pdn_disable(true);
#if UART_CONNECTION_TEST_TXRX == 1
bool UART_Rx_connected = false;
UART_Rx_connected = connectToDriver(_driverFocus, "Focus");
UART_Rx_connected = connectToDriver("FOC");
if (!UART_Rx_connected)
{
digitalWrite(FOCUS_EN_PIN,
Expand Down
5 changes: 2 additions & 3 deletions src/Mount.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ class Mount

void initializeVariables();

static Mount instance();

// Configure the RA stepper motor. This also sets up the TRK stepper on the same pins.
void configureRAStepper(byte pin1, byte pin2, uint32_t maxSpeed, uint32_t maxAcceleration);

Expand All @@ -182,7 +180,8 @@ class Mount
#if RA_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART || DEC_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART \
|| AZ_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART || ALT_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART \
|| FOCUS_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
bool connectToDriver(TMC2209Stepper *driver, const char *driverKind);
bool connectToDriver(const String &driverKind, uint16_t *rmsCurrent = nullptr);

#endif
#if RA_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
// Configure the RA Driver (TMC2209 UART only)
Expand Down
40 changes: 40 additions & 0 deletions src/Utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,46 @@ float atanf(float x)
return static_cast<float>(atan(static_cast<double>(x)));
}

String *splitStringBy(String str, char splitChar)
{
unsigned int count = 1; // At least one string if input is non-empty

// Count occurrences of splitChar to determine the number of splits
for (unsigned int i = 0; i < str.length(); i++)
{
if (str[i] == splitChar)
{
count++;
}
}

// Dynamically allocate memory for the resulting array
String *array = new String[count + 1]; // +1 for the nullptr terminator
unsigned int r = 0; // Start of the substring
unsigned int t = 0; // Index in the result array

// Iterate through the string to split it
for (unsigned int i = 0; i < str.length(); i++)
{
if (str[i] == splitChar)
{
array[t++] = str.substring(r, i); // Store substring
r = i + 1; // Move start to next character
}
}

// Add the last part of the string
if (r < str.length())
{
array[t++] = str.substring(r);
}

// Mark the end of the array with ""
array[t] = "";

return array;
}

#if defined(ESP32)
int freeMemory()
{
Expand Down
6 changes: 6 additions & 0 deletions src/Utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,11 @@ int sign(long num);
int fsign(float num);

#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#define CASERETURN(c, r) \
case c: \
return r

// Return an array of String* with a nullptr sentinel
String *splitStringBy(String str, char splitChar);

#endif
23 changes: 22 additions & 1 deletion src/b_setup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ PUSH_NO_WARNINGS
POP_NO_WARNINGS
#endif

#if TEST_VERIFY_MODE == 1
#include "testmenu.hpp"
#endif

#ifndef NEW_STEPPER_LIB
#include "InterruptCallback.hpp"
#endif
Expand Down Expand Up @@ -111,7 +115,21 @@ void setup()
#endif
#endif

LOG(DEBUG_ANY, "[SYSTEM]: Hello, universe, this is OAT %s!", VERSION);
#if TEST_VERIFY_MODE == 1
#ifdef OAM
Serial.print(F("Booting OAM 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...");
Expand Down Expand Up @@ -522,4 +540,7 @@ void setup()
delay(250);
mount.getInfoDisplay()->setConsoleMode(false);
#endif
#if TEST_VERIFY_MODE == 1
TestMenu::getCurrentMenu()->display();
#endif
}
Loading