Skip to content

Commit d46ba33

Browse files
V1.6.51 - Updates
- FIxed a bug that was preventing correct EEPROM reads. - Removed a redundant menu active item variable. - Fixed a crash caused by a switch statement (compiler bug?). - Added and removed some debug logging statements. - Changed LCD display to display RA and DEC coordinates instead of stepper position.
1 parent 8f9ac8a commit d46ba33

File tree

8 files changed

+85
-68
lines changed

8 files changed

+85
-68
lines changed

Software/Arduino code/OpenAstroTracker/LcdMenu.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
LcdMenu::LcdMenu(byte cols, byte rows, int maxItems) : _lcd(8, 9, 4, 5, 6, 7) {
1010
//_lcd = new LiquidCrystal(8, 9, 4, 5, 6, 7);
1111
_lcd.begin(cols, rows);
12-
_activeId = 0;
1312
_numMenuItems = 0;
1413
_activeMenuIndex = 0;
1514
_longestDisplay = 0;
@@ -48,12 +47,11 @@ void LcdMenu::addItem(const char* disp, byte id) {
4847

4948
// Get the currently active item ID
5049
byte LcdMenu::getActive() {
51-
return _activeId;
50+
return _menuItems[_activeMenuIndex]->id();
5251
}
5352

5453
// Set the active menu item
5554
void LcdMenu::setActive(byte id) {
56-
_activeId = id;
5755
for (byte i = 0; i < _numMenuItems; i++) {
5856
if (_menuItems[i]->id() == id) {
5957
_activeMenuIndex = i;
@@ -77,7 +75,6 @@ void LcdMenu::clear() {
7775
void LcdMenu::setNextActive() {
7876

7977
_activeMenuIndex = adjustWrap(_activeMenuIndex, 1, 0, _numMenuItems - 1);
80-
_activeId = _menuItems[_activeMenuIndex]->id();
8178

8279
// Update the display
8380
updateDisplay();
@@ -105,7 +102,7 @@ void LcdMenu::updateDisplay() {
105102
// Build the entire menu string
106103
for (byte i = 0; i < _numMenuItems; i++) {
107104
MenuItem* item = _menuItems[i];
108-
bool isActive = item->id() == _activeId;
105+
bool isActive = i == _activeMenuIndex;
109106
sprintf(scratchBuffer, "%c%s%c", isActive ? '>' : ' ', item->display(), isActive ? '<' : ' ');
110107

111108
// For the active item remember where it starts in the string and insert selector arrows

Software/Arduino code/OpenAstroTracker/LcdMenu.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ class LcdMenu {
7474
MenuItem** _menuItems; // The first menu item (linked list)
7575
byte _numMenuItems;
7676
byte _activeMenuIndex;
77-
byte _activeId; // The id of the currently active menu item
7877
byte _longestDisplay; // The number of characters in the longest menu item
7978
byte _columns; // The number of columns in the LCD display
8079
byte _activeRow; // The row that the LCD cursor is on

Software/Arduino code/OpenAstroTracker/Mount.cpp

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,30 @@ void Mount::readPersistentData()
8888
{
8989
// Read the magic marker byte and state
9090
int marker = EEPROM.read(4) + EEPROM.read(5) * 256;
91-
92-
if (marker & 0xFF01 == 0xBE01) {
91+
#ifdef DEBUG_MODE
92+
logv("EEPROM: Marker is %d", marker);
93+
#endif
94+
if ((marker & 0xFF01) == 0xBE01) {
9395
_stepsPerRADegree = EEPROM.read(6) + EEPROM.read(7) * 256;
96+
#ifdef DEBUG_MODE
97+
logv("EEPROM: RA Marker OK! RA steps/deg is %d", _stepsPerRADegree);
98+
#endif
9499
}
95100

96-
if (marker & 0xFF02 == 0xBE02) {
101+
if ((marker & 0xFF02) == 0xBE02) {
97102
_stepsPerDECDegree = EEPROM.read(8) + EEPROM.read(9) * 256;
103+
#ifdef DEBUG_MODE
104+
logv("EEPROM: DEC Marker OK! DEC steps/deg is %d", _stepsPerDECDegree);
105+
#endif
98106
}
99107

100108
float speed = 1.0;
101-
if (marker & 0xFF04 == 0xBE04) {
109+
if ((marker & 0xFF04) == 0xBE04) {
102110
int adjust = EEPROM.read(0) + EEPROM.read(3) * 256;
103111
speed = 1.0 + adjust / 10000;
112+
#ifdef DEBUG_MODE
113+
logv("EEPROM: Speed Marker OK! Speed adjust is %d", adjust);
114+
#endif
104115
}
105116

106117
setSpeedCalibration(speed, false);
@@ -274,7 +285,7 @@ void Mount::setHA(const DayTime& haTime) {
274285
// HA
275286
//
276287
/////////////////////////////////
277-
const DayTime& Mount::HA() const {
288+
const DayTime Mount::HA() const {
278289
#ifdef DEBUG_MODE
279290
logv("Mount: Get HA.");
280291
logv("Mount: Polaris adjust: %d:%d:%d", PolarisRAHour,PolarisRAMinute, PolarisRASecond);
@@ -342,21 +353,11 @@ const DayTime Mount::currentRA() const {
342353
// How many steps moves the RA ring one sidereal hour along. One sidereal hour moves just shy of 15 degrees
343354
float stepsPerSiderealHour = _stepsPerRADegree * siderealDegreesInHour;
344355
float hourPos = _stepperRA->currentPosition() / stepsPerSiderealHour / 2.0;
345-
#ifdef DEBUG_MODE
346-
logv("currentRA: hourPos: %s", String(hourPos, 4).c_str());
347-
logv("currentRA: adding zeroPosRA: %s", String(_zeroPosRA.getTotalHours(), 4).c_str());
348-
#endif
349356
hourPos += _zeroPosRA.getTotalHours();
350-
#ifdef DEBUG_MODE
351-
logv("currentRA: hourPos: %s", String(hourPos, 4).c_str());
352-
#endif
353357
if (_stepperDEC->currentPosition() > 0)
354358
{
355359
hourPos += 12;
356360
if (hourPos > 24) hourPos -= 24;
357-
#ifdef DEBUG_MODE
358-
logv("currentRA: Dec is %d (>0), so adding 12. New hourPos: %s", _stepperDEC->currentPosition(), String(hourPos, 4).c_str());
359-
#endif
360361
}
361362

362363
return hourPos;
@@ -964,7 +965,7 @@ void Mount::loop() {
964965

965966
unsigned long now = millis();
966967
#ifdef DEBUG_MODE
967-
if (now - _lastMountPrint > 100) {
968+
if (now - _lastMountPrint > 1000) {
968969
Serial.println(getStatusString());
969970
_lastMountPrint = now;
970971
}
@@ -1216,14 +1217,14 @@ void Mount::displayStepperPosition() {
12161217
sprintf(scratchBuffer, "R %s %d%%", RAString(LCD_STRING | CURRENT_STRING).c_str(), (int)raDist);
12171218
_lcdMenu->setCursor(0, 0);
12181219
_lcdMenu->printMenu(String(scratchBuffer));
1219-
sprintf(scratchBuffer, "D %s %d%%", DECString(LCD_STRING | CURRENT_STRING).c_str(), (int)decDist);
1220+
sprintf(scratchBuffer, "D%s %d%%", DECString(LCD_STRING | CURRENT_STRING).c_str(), (int)decDist);
12201221
_lcdMenu->setCursor(0, 1);
12211222
_lcdMenu->printMenu(String(scratchBuffer));
12221223
return;
12231224
}
12241225
else if (abs(_totalDECMove) > 0.001) {
12251226
float decDist = 100.0 - 100.0 * _stepperDEC->distanceToGo() / _totalDECMove;
1226-
sprintf(scratchBuffer, "D %s %d%%", DECString(LCD_STRING | CURRENT_STRING).c_str(), (int)decDist);
1227+
sprintf(scratchBuffer, "D%s %d%%", DECString(LCD_STRING | CURRENT_STRING).c_str(), (int)decDist);
12271228
_lcdMenu->setCursor(0, 1);
12281229
_lcdMenu->printMenu(String(scratchBuffer));
12291230
}
@@ -1245,20 +1246,14 @@ void Mount::displayStepperPosition() {
12451246
_lcdMenu->printMenu(scratchBuffer);
12461247
}
12471248
else {
1248-
disp = "R:" + String(_stepperRA->currentPosition());
1249+
sprintf(scratchBuffer, "R%s D%s", RAString(COMPACT_STRING | CURRENT_STRING).c_str(), DECString(COMPACT_STRING | CURRENT_STRING).c_str());
12491250
_lcdMenu->setCursor(0, 1);
1250-
_lcdMenu->printMenu(disp);
1251-
disp = "D:" + String(_stepperDEC->currentPosition());
1252-
_lcdMenu->setCursor(8, 1);
1253-
_lcdMenu->printMenu(disp);
1251+
_lcdMenu->printMenu(scratchBuffer);
12541252
}
12551253
#else
1256-
disp = "R:" + String(_stepperRA->currentPosition());
1254+
sprintf(scratchBuffer, "R%s D%s", RAString(COMPACT_STRING | CURRENT_STRING).c_str(), DECString(COMPACT_STRING | CURRENT_STRING).c_str());
12571255
_lcdMenu->setCursor(0, 1);
1258-
_lcdMenu->printMenu(disp);
1259-
disp = "D:" + String(_stepperDEC->currentPosition());
1260-
_lcdMenu->setCursor(8, 1);
1261-
_lcdMenu->printMenu(disp);
1256+
_lcdMenu->printMenu(scratchBuffer);
12621257
#endif
12631258
}
12641259
#endif

Software/Arduino code/OpenAstroTracker/Mount.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Mount {
6161

6262
// Set the HA time (HA is derived from LST, the setter calculates and sets LST)
6363
void setHA(const DayTime& haTime);
64-
const DayTime& HA() const;
64+
const DayTime HA() const;
6565

6666
// Set the LST time (HA is derived from LST)
6767
void setLST(const DayTime& haTime);

Software/Arduino code/OpenAstroTracker/OpenAstroTracker.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
#include "Globals.h"
1818

19-
String version = "V1.6.50";
19+
String version = "V1.6.51";
2020

2121
///////////////////////////////////////////////////////////////////////////
2222
// Please see the Globals.h file for configuration of the firmware.

Software/Arduino code/OpenAstroTracker/a_inits.ino

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//#include <SoftwareSerial.h>
33
#include <EEPROM.h>
44
#include <AccelStepper.h>
5+
//#include <avr8-stub.h>
56
#include <LiquidCrystal.h>
67

78
#include "Utility.h"
@@ -48,9 +49,9 @@
4849
#endif
4950

5051
// Menu IDs
51-
#define RA_Menu 0
52-
#define DEC_Menu 1
53-
#define HA_Menu 2
52+
#define RA_Menu 1
53+
#define DEC_Menu 2
54+
#define HA_Menu 3
5455
#define Heat_Menu 4
5556
#define Calibration_Menu 5
5657
#define Control_Menu 6

Software/Arduino code/OpenAstroTracker/b_setup.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ void setup() {
5252

5353
mount.setHA(haTime);
5454

55+
// For LCD screen, it's better to initialize the target to where we are (RA)
56+
mount.targetRA() = mount.currentRA();
57+
5558
// Start the tracker.
5659
mount.startSlewing(TRACKING);
5760

Software/Arduino code/OpenAstroTracker/c_buttons.ino

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void loop() {
4444

4545
#endif
4646

47+
4748
// Give the mount a time slice to do its thing...
4849
mount.loop();
4950

@@ -75,49 +76,50 @@ void loop() {
7576
}
7677
else
7778
#endif
79+
7880
{
7981
switch (lcdMenu.getActive()) {
8082
case RA_Menu:
81-
waitForButtonRelease = processRAKeys();
82-
break;
83+
waitForButtonRelease = processRAKeys();
84+
break;
8385
case DEC_Menu:
84-
waitForButtonRelease = processDECKeys();
85-
break;
86+
waitForButtonRelease = processDECKeys();
87+
break;
8688
#ifdef SUPPORT_POINTS_OF_INTEREST
8789
case POI_Menu:
88-
waitForButtonRelease = processPOIKeys();
89-
break;
90+
waitForButtonRelease = processPOIKeys();
91+
break;
9092
#else
9193
case Home_Menu:
92-
waitForButtonRelease = processHomeKeys();
93-
break;
94+
waitForButtonRelease = processHomeKeys();
95+
break;
9496
#endif
9597

9698
case HA_Menu:
97-
waitForButtonRelease = processHAKeys();
98-
break;
99+
waitForButtonRelease = processHAKeys();
100+
break;
99101
#ifdef SUPPORT_HEATING
100102
case Heat_Menu:
101-
waitForButtonRelease = processHeatKeys();
102-
break;
103+
waitForButtonRelease = processHeatKeys();
104+
break;
103105
#endif
104106

105107
#ifdef SUPPORT_CALIBRATION
106108
case Calibration_Menu:
107-
waitForButtonRelease = processCalibrationKeys();
108-
break;
109+
waitForButtonRelease = processCalibrationKeys();
110+
break;
109111
#endif
110112

111113
#ifdef SUPPORT_MANUAL_CONTROL
112114
case Control_Menu:
113-
waitForButtonRelease = processControlKeys();
114-
break;
115+
waitForButtonRelease = processControlKeys();
116+
break;
115117
#endif
116118

117119
#ifdef SUPPORT_INFO_DISPLAY
118120
case Status_Menu:
119-
waitForButtonRelease = processStatusKeys();
120-
break;
121+
waitForButtonRelease = processStatusKeys();
122+
break;
121123
#endif
122124
}
123125
}
@@ -146,33 +148,53 @@ void loop() {
146148
#endif
147149
{
148150
if (!inSerialControl) {
149-
switch (lcdMenu.getActive()) {
150-
case RA_Menu: printRASubmenu(); break;
151-
case DEC_Menu: printDECSubmenu(); break;
151+
// For some strange reason, a switch statement here causes a crash and reboot....
152+
int activeMenu = lcdMenu.getActive();
153+
if (activeMenu == RA_Menu) {
154+
printRASubmenu();
155+
}
156+
else if (activeMenu == DEC_Menu)
157+
{
158+
printDECSubmenu();
159+
}
152160
#ifdef SUPPORT_POINTS_OF_INTEREST
153-
case POI_Menu: printPOISubmenu(); break;
161+
else if (activeMenu == POI_Menu) {
162+
printPOISubmenu();
163+
}
154164
#else
155-
case Home_Menu: printHomeSubmenu(); break;
165+
else if (activeMenu == Home_Menu) {
166+
printHomeSubmenu();
167+
}
156168
#endif
157-
case HA_Menu: printHASubmenu(); break;
169+
else if (activeMenu == HA_Menu) {
170+
printHASubmenu();
171+
}
158172
#ifdef SUPPORT_HEATING
159-
case Heat_Menu: printHeatSubmenu(); break;
173+
else if (activeMenu == Heat_Menu) {
174+
printHeatSubmenu();
175+
}
160176
#endif
161177
#ifdef SUPPORT_MANUAL_CONTROL
162-
case Control_Menu: printControlSubmenu(); break;
178+
else if (activeMenu == Control_Menu) {
179+
printControlSubmenu();
180+
}
163181
#endif
164182
#ifdef SUPPORT_CALIBRATION
165-
case Calibration_Menu: printCalibrationSubmenu(); break;
183+
else if (activeMenu == Calibration_Menu) {
184+
printCalibrationSubmenu();
185+
}
166186
#endif
167187

168188
#ifdef SUPPORT_INFO_DISPLAY
169-
case Status_Menu: printStatusSubmenu(); break;
170-
#endif
189+
else if (activeMenu == Status_Menu) {
190+
printStatusSubmenu();
171191
}
192+
#endif
172193
}
173194
}
174195
}
175196

197+
176198
BTin();
177199
}
178200
#else

0 commit comments

Comments
 (0)