Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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"
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ src_build_flags =
-Wno-unused-parameter
; -Wold-style-cast
-Wlogical-op
-Wuseless-cast
; -Wuseless-cast
; Wdouble-promotion can't be enabled until GCC bug 55578 is fixed, since floats are
; implicitly converted to doubles when passed to a variadic function (i.e. a printf-like).
; Else we could disable Wdouble-promotion only for our logv function inside of the LOG macro
Expand Down
94 changes: 70 additions & 24 deletions src/Mount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const char *formatStringsRA[] = {

const float siderealDegreesInHour = 14.95904348958;

Mount *Mount::_instance = nullptr;

/////////////////////////////////
//
// CTOR
Expand All @@ -89,7 +91,8 @@ Mount::Mount(LcdMenu *lcdMenu)
#if (INFO_DISPLAY_TYPE != INFO_DISPLAY_TYPE_NONE)
_loops = 0;
#endif
_lcdMenu = lcdMenu;
_lcdMenu = lcdMenu;
_instance = this;
initializeVariables();
}

Expand Down Expand Up @@ -413,23 +416,66 @@ 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 || defined(TEST_VERIFY_MODE)
bool Mount::connectToDriver(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++)
TMC2209Stepper *driver = nullptr;
if (driverKind == "RA")
{
if (driver->test_connection() == 0)
{
LOG(DEBUG_STEPPERS, "[STEPPERS]: UART connection to %s driver successful.", driverKind);
return true;
}
else
#if RA_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
driver = _driverRA;
#endif
}
else if (driverKind == "DEC")
{
#if DEC_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
driver = _driverDEC;
#endif
}
else if (driverKind == "ALT")
{
#if ALT_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
driver = _driverALT;
#endif
}
else if (driverKind == "AZ")
{
#if AZ_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
driver = _driverAZ;
#endif
}
else if (driverKind == "FOC")
{
#if FOCUS_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
driver = _driverFocus;
#endif
}

if (driver != nullptr)
{
LOG(DEBUG_STEPPERS, "[STEPPERS]: Testing UART Connection to %s driver...", driverKind.c_str());
for (int i = 0; i < UART_CONNECTION_TEST_RETRIES; i++)
{
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 +494,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 +533,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 +577,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 +616,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 +660,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 +698,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 +741,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 +779,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 +824,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 +870,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
6 changes: 4 additions & 2 deletions src/Mount.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class Mount

void initializeVariables();

static Mount instance();
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 Down Expand Up @@ -182,7 +182,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(String driverKind, uint16_t *rmsCurrent = nullptr);

#endif
#if RA_DRIVER_TYPE == DRIVER_TYPE_TMC2209_UART
// Configure the RA Driver (TMC2209 UART only)
Expand Down Expand Up @@ -674,6 +675,7 @@ class Mount
LocalDate _localStartDate;
DayTime _localStartTime;
long _localStartTimeSetMillis;
static Mount *_instance;
};

#endif
48 changes: 48 additions & 0 deletions src/Utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,54 @@ 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 nullptr
array[t] = "";

return array;
}

String rightJustify(String str, int width)
{
while (str.length() < (unsigned int) width)
{
str = " " + str; // Add spaces to the left
}
return str;
}
#if defined(ESP32)
int freeMemory()
{
Expand Down
5 changes: 5 additions & 0 deletions src/Utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,9 @@ int fsign(float num);

#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))

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

String rightJustify(String str, int width);

#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

#ifdef TEST_VERIFY_MODE
#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);
#ifdef TEST_VERIFY_MODE
#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
#ifdef TEST_VERIFY_MODE
TestMenu::getCurrentMenu()->display();
#endif
}
Loading