Skip to content

Commit cc99b08

Browse files
V1.7.14 - Updates
- Fixed a bug in Polar Alignment (this never actually worked correctly) - Fixed a bug in the Sync function of the mount - Added backlight adjustment, but it does not work (crashes the board), so it is commented out. Might revisit later.
1 parent 20277bf commit cc99b08

File tree

9 files changed

+180
-33
lines changed

9 files changed

+180
-33
lines changed

Software/Arduino code/OpenAstroTracker/LcdMenu.cpp

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <EEPROM.h>
12
#include "Utility.hpp"
23
#include "LcdMenu.hpp"
34

@@ -17,7 +18,12 @@ LcdMenu::LcdMenu(byte cols, byte rows, int maxItems) : _lcd(8, 9, 4, 5, 6, 7) {
1718
_activeCol = -1;
1819
_lastDisplay[0] = "";
1920
_lastDisplay[1] = "";
20-
_menuItems = new MenuItem * [maxItems];
21+
_menuItems = new MenuItem * [maxItems];
22+
23+
_brightness = EEPROM.read(11);
24+
LOGV2(DEBUG_INFO, "LCD: Brightness from EEPROM is %d", _brightness);
25+
// pinMode(10, OUTPUT);
26+
// analogWrite(10, _brightness);
2127

2228
// Create special characters for degrees and arrows
2329
_lcd.createChar(_degrees, DegreesBitmap);
@@ -71,6 +77,26 @@ void LcdMenu::clear() {
7177
_lcd.clear();
7278
}
7379

80+
// Set the brightness of the backlight
81+
void LcdMenu::setBacklightBrightness(int level, bool persist) {
82+
_brightness = level;
83+
84+
LOGV2(DEBUG_INFO, "LCD: Writing %d as brightness", _brightness );
85+
86+
// analogWrite(10, _brightness);
87+
88+
LOGV2(DEBUG_INFO, "LCD: Wrote %d as brightness", _brightness );
89+
if (persist) {
90+
LOGV2(DEBUG_INFO, "LCD: Saving %d as brightness", (_brightness & 0x00FF));
91+
EEPROMupdate(11, (byte)(_brightness & 0x00FF));
92+
}
93+
}
94+
95+
// Get the current brightness
96+
int LcdMenu::getBacklightBrightness() {
97+
return _brightness;
98+
}
99+
74100
// Go to the next menu item from currently active one
75101
void LcdMenu::setNextActive() {
76102

@@ -282,3 +308,50 @@ void LcdMenu::printMenu(String line) {}
282308
void LcdMenu::printChar(char ch) {}
283309

284310
#endif
311+
312+
/*
313+
class SubMenu {
314+
315+
display() { }
316+
onUp() { }
317+
onDown() { }
318+
319+
}
320+
}
321+
322+
class Menu {
323+
List<SubMenu> subMenu
324+
int activeSubIndex=0
325+
UseContinuousKeys(UP|DOWN|LEFT|RIGHT)
326+
327+
virtual OnUp() { previousSubmenu }
328+
virtual OnDown() { nextSubmenu }
329+
virtual OnRight() { nextmenu }
330+
virtual OnLeft() { nextItemInSubmenu }
331+
virtual OnSelect() { confirm }
332+
333+
displayMenu() { }
334+
335+
run(){
336+
if (any continuous keys)
337+
{
338+
if
339+
}
340+
}
341+
}
342+
343+
class MenuSystem {
344+
List<Menu> menus;
345+
346+
run() {
347+
if (!activeMenu->run())
348+
{
349+
activeMenu++
350+
}
351+
}
352+
}
353+
354+
Menu RA ;
355+
RA.fnDisplay = [] { _lcdMenu.goto(0,1); _lcdMenu.printMenu(_mount.targetRA()); }
356+
RA.fnUp() = [] { }
357+
*/

Software/Arduino code/OpenAstroTracker/LcdMenu.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class LcdMenu {
5050
// Pass thru utility function
5151
void setCursor(byte col, byte row);
5252

53+
// Set and get the brightness of the backlight
54+
void setBacklightBrightness(int level, bool persist = true);
55+
int getBacklightBrightness();
56+
5357
// Pass thru utility function
5458
void clear();
5559

@@ -79,6 +83,7 @@ class LcdMenu {
7983
byte _activeRow; // The row that the LCD cursor is on
8084
byte _activeCol; // The column that the LCD cursor is on
8185
String _lastDisplay[2]; // The last string that was displayed on each row
86+
int _brightness;
8287

8388
byte _degrees = 1;
8489
byte _minutes = 2;

Software/Arduino code/OpenAstroTracker/Mount.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,13 @@ const DegreeTime Mount::currentDEC() const {
569569
// to be at the calculated positions (that they would be if we were slewing there).
570570
void Mount::syncPosition(int raHour, int raMinute, int raSecond, int decDegree, int decMinute, int decSecond)
571571
{
572+
_targetRA.set(raHour,raMinute,raSecond);
573+
_targetDEC.set(decDegree,decMinute,decSecond);
574+
572575
float targetRA, targetDEC;
576+
LOGV7(DEBUG_MOUNT, "Mount: Sync Position to RA: %d:%d:%d and DEC: %d*%d:%d", raHour, raMinute, raSecond, decDegree, decMinute, decSecond);
573577
calculateRAandDECSteppers(targetRA, targetDEC);
578+
LOGV3(DEBUG_MOUNT, "Mount: Sync Stepper Position is RA: %d and DEC: %d", targetRA, targetDEC);
574579
_stepperRA->setCurrentPosition(targetRA);
575580
_stepperDEC->setCurrentPosition(targetDEC);
576581
}

Software/Arduino code/OpenAstroTracker/OpenAstroTracker.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include "Globals.hpp"
2020

21-
String version = "V1.7.13";
21+
String version = "V1.7.14";
2222

2323
///////////////////////////////////////////////////////////////////////////
2424
// Please see the Globals.h file for configuration of the firmware.

Software/Arduino code/OpenAstroTracker/Utility.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
#define LOGV4(level,a,b,c,d) logv((level),(a),(b),(c),(d))
2121
#define LOGV5(level,a,b,c,d,e) logv((level),(a),(b),(c),(d),(e))
2222
#define LOGV6(level,a,b,c,d,e,f) logv((level),(a),(b),(c),(d),(e),(f))
23-
#define LOGV7(level,a,b,c,d,e),f,g logv((level),(a),(b),(c),(d),(e),(f),(g))
23+
#define LOGV7(level,a,b,c,d,e,f,g) logv((level),(a),(b),(c),(d),(e),(f),(g))
24+
#define LOGV8(level,a,b,c,d,e,f,g,h) logv((level),(a),(b),(c),(d),(e),(f),(g),(h))
2425

2526
// Realtime timer class using microseconds to time stuff
2627
class RealTime {

Software/Arduino code/OpenAstroTracker/b_setup.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ void finishSetup()
164164
#endif
165165

166166
// The mount uses EEPROM storage locations 0-10 that it reads during construction
167-
167+
// The LCD uses EEPROM storage location 11
168+
168169
// Read other persisted values and set in mount
169170
DayTime haTime = DayTime(EEPROM.read(1), EEPROM.read(2), 0);
170171

Software/Arduino code/OpenAstroTracker/c722_menuPOI.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct PointOfInterest {
1515
PointOfInterest pointOfInterest[] = {
1616
// Name (15chars) RA (hms) DEC (dms)
1717
// 012345678901234
18-
{ ">Polaris" , PolarisRAHour, PolarisRAMinute, PolarisRASecond, 89, 21, 2 },
18+
{ ">Polaris" , PolarisRAHour, PolarisRAMinute, PolarisRASecond, 89, 21, 6 },
1919
{ ">Big Dipper" , 12, 16, 26, 56, 55, 7 },
2020
{ ">M31 Andromeda" , 0, 43, 52, 41, 22, 53 },
2121
{ ">M42 Orion Nbula", 5, 36, 18, -5, 22, 44 },

Software/Arduino code/OpenAstroTracker/c76_menuCAL.hpp

Lines changed: 82 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
2+
#include "Globals.hpp"
23

34
#if HEADLESS_CLIENT == 0
45

@@ -12,15 +13,14 @@
1213
#define HIGHLIGHT_RA_STEPS 4
1314
#define HIGHLIGHT_DEC_STEPS 5
1415
#define HIGHLIGHT_BACKLASH_STEPS 6
16+
// #define HIGHLIGHT_BACKLIGHT 7
1517
#define HIGHLIGHT_LAST 6
1618

1719
// Polar calibration goes through these three states:
18-
// 11- moving to RA of Polaris and then waiting on confirmation that Polaris is centered
19-
// 12- moving to DEC beyond Polaris and waiting on confirmation that Polaris is centered
20+
// 11- moving to RA and DEC beyond Polaris and waiting on confirmation that Polaris is centered
2021
// 13- moving back to home position
21-
#define POLAR_CALIBRATION_WAIT 11
22-
#define POLAR_CALIBRATION_GO 12
23-
#define POLAR_CALIBRATION_WAIT_HOME 13
22+
#define POLAR_CALIBRATION_WAIT_CENTER_POLARIS 11
23+
#define POLAR_CALIBRATION_WAIT_HOME 12
2424

2525
// Speed calibration only has one state, allowing you to adjust the speed with UP and DOWN
2626
#define SPEED_CALIBRATION 14
@@ -41,10 +41,13 @@
4141
// Backlash calibration only has one state, allowing you to adjust the number of steps with UP and DOWN
4242
#define BACKLASH_CALIBRATION 19
4343

44+
// Brightness setting only has one state, allowing you to adjust the brightness with UP and DOWN
45+
// #define BACKLIGHT_CALIBRATION 20
46+
4447
// Start off with Polar Alignment higlighted.
4548
byte calState = HIGHLIGHT_FIRST;
4649

47-
// SPeed adjustment variable. Added to 1.0 after dividing by 10000 to get final speed
50+
// Speed adjustment variable. Added to 1.0 after dividing by 10000 to get final speed
4851
float SpeedCalibration;
4952

5053
// The current delay in ms when changing calibration value. The longer a button is depressed, the smaller this gets.
@@ -59,6 +62,9 @@ byte driftDuration = 0;
5962
// The number of steps to use for backlash compensation (read from the mount).
6063
int BacklashSteps = 0;
6164

65+
// The brightness of the backlight of the LCD shield.
66+
// int Brightness = 255;
67+
6268
bool checkProgressiveUpDown(int* val) {
6369
bool ret = true;
6470

@@ -99,6 +105,9 @@ void gotoNextHighlightState(int dir) {
99105
else if (calState == HIGHLIGHT_SPEED) {
100106
SpeedCalibration = (mount.getSpeedCalibration() - 1.0) * 10000.0 + 0.5;
101107
}
108+
// else if (calState == HIGHLIGHT_BACKLIGHT) {
109+
// Brightness = lcdMenu.getBacklightBrightness();
110+
// }
102111
}
103112

104113
bool processCalibrationKeys() {
@@ -141,8 +150,22 @@ bool processCalibrationKeys() {
141150
else if (calState == BACKLASH_CALIBRATION) {
142151
checkForKeyChange = checkProgressiveUpDown(&BacklashSteps);
143152
}
153+
// else if (calState == BACKLIGHT_CALIBRATION) {
154+
// checkForKeyChange = checkProgressiveUpDown(&Brightness);
155+
// if (!checkForKeyChange) {
156+
// LOGV2(DEBUG_INFO,"CAL: Brightness changed to %d", Brightness);
157+
// Brightness = clamp(Brightness, 0, 255);
158+
// LOGV2(DEBUG_INFO,"CAL: Brightness clamped to %d", Brightness);
159+
// lcdMenu.setBacklightBrightness(Brightness, false);
160+
// LOGV2(DEBUG_INFO,"CAL: Brightness set %d", (int)lcdMenu.getBacklightBrightness());
161+
// }
162+
// }
163+
else if (calState == RA_STEP_CALIBRATION) {
164+
checkForKeyChange = checkProgressiveUpDown(&RAStepsPerDegree);
165+
}
144166
else if (calState == POLAR_CALIBRATION_WAIT_HOME) {
145167
if (!mount.isSlewingRAorDEC()) {
168+
146169
lcdMenu.updateDisplay();
147170
calState = HIGHLIGHT_POLAR;
148171
}
@@ -179,13 +202,9 @@ bool processCalibrationKeys() {
179202

180203
switch (calState) {
181204

182-
case POLAR_CALIBRATION_GO: {
205+
case POLAR_CALIBRATION_WAIT_HOME: {
183206
if (key == btnSELECT) {
184-
lcdMenu.printMenu("Aligned, homing");
185-
mount.delay(600);
186-
mount.setTargetToHome();
187-
mount.startSlewingToTarget();
188-
calState = POLAR_CALIBRATION_WAIT_HOME;
207+
calState = HIGHLIGHT_POLAR;
189208
}
190209
if (key == btnRIGHT) {
191210
lcdMenu.setNextActive();
@@ -259,18 +278,36 @@ bool processCalibrationKeys() {
259278
}
260279
break;
261280

281+
// case BACKLIGHT_CALIBRATION:
282+
// {
283+
// // UP and DOWN are handled above
284+
// if (key == btnSELECT) {
285+
// LOGV2(DEBUG_GENERAL, "CAL Menu: Set brightness to %d", Brightness);
286+
// lcdMenu.setBacklightBrightness(Brightness);
287+
// lcdMenu.printMenu("Level stored.");
288+
// mount.delay(500);
289+
// calState = HIGHLIGHT_BACKLIGHT;
290+
// }
291+
// else if (key == btnRIGHT) {
292+
// lcdMenu.setNextActive();
293+
// calState = HIGHLIGHT_BACKLIGHT;
294+
// }
295+
// }
296+
// break;
297+
262298
case HIGHLIGHT_POLAR: {
263299
if (key == btnDOWN) gotoNextHighlightState(1);
264300
else if (key == btnUP) gotoNextHighlightState(-1);
265301
else if (key == btnSELECT) {
266-
calState = POLAR_CALIBRATION_WAIT;
302+
calState = POLAR_CALIBRATION_WAIT_CENTER_POLARIS;
267303

268304
// Move the RA to that of Polaris. Moving to this RA aligns the DEC axis such that
269305
// it swings along the line between Polaris and the Celestial Pole.
270306
mount.targetRA() = DayTime(PolarisRAHour, PolarisRAMinute, PolarisRASecond);
271307

272-
// Now set DEC to move to Home position
273-
mount.targetDEC() = DegreeTime(90 - (NORTHERN_HEMISPHERE ? 90 : -90), 0, 0);
308+
// Set DEC to move the same distance past Polaris as
309+
// it is from the Celestial Pole. That equates to 88deg 42' 11.2".
310+
mount.targetDEC() = DegreeTime(88 - (NORTHERN_HEMISPHERE ? 90 : -90), 42, 11);
274311
mount.startSlewingToTarget();
275312
}
276313
else if (key == btnRIGHT) {
@@ -279,14 +316,21 @@ bool processCalibrationKeys() {
279316
}
280317
break;
281318

282-
case POLAR_CALIBRATION_WAIT: {
319+
case POLAR_CALIBRATION_WAIT_CENTER_POLARIS: {
283320
if (key == btnSELECT) {
284-
calState = POLAR_CALIBRATION_GO;
321+
calState = POLAR_CALIBRATION_WAIT_HOME;
322+
lcdMenu.printMenu("Aligned, homing");
323+
mount.delay(750);
285324

286-
// RA is already set. Now set DEC to move the same distance past Polaris as
287-
// it is from the Celestial Pole. That equates to 88deg 42' 6".
288-
mount.targetDEC() = DegreeTime(89 - (NORTHERN_HEMISPHERE ? 90 : -90), 21, 3);
325+
// Sync the mount to Polaris, since that's where it's pointing
326+
DayTime currentRa = mount.currentRA();
327+
mount.syncPosition(currentRa.getHours(), currentRa.getMinutes(), currentRa.getSeconds(), 89 - (NORTHERN_HEMISPHERE ? 90 : -90), 21, 6);
328+
329+
// Go home from here
330+
mount.setTargetToHome();
289331
mount.startSlewingToTarget();
332+
lcdMenu.setNextActive();
333+
calState = HIGHLIGHT_POLAR;
290334
}
291335
else if (key == btnRIGHT) {
292336
lcdMenu.setNextActive();
@@ -371,6 +415,16 @@ bool processCalibrationKeys() {
371415
}
372416
}
373417
break;
418+
// case HIGHLIGHT_BACKLIGHT : {
419+
// if (key == btnDOWN) gotoNextHighlightState(1);
420+
// if (key == btnUP) gotoNextHighlightState(-1);
421+
// else if (key == btnSELECT) calState = BACKLIGHT_CALIBRATION;
422+
// else if (key == btnRIGHT) {
423+
// lcdMenu.setNextActive();
424+
// calState = HIGHLIGHT_FIRST;
425+
// }
426+
// }
427+
// break;
374428
}
375429
}
376430

@@ -398,7 +452,10 @@ void printCalibrationSubmenu()
398452
else if (calState == HIGHLIGHT_BACKLASH_STEPS) {
399453
lcdMenu.printMenu(">Backlash Adjust");
400454
}
401-
else if ((calState == POLAR_CALIBRATION_WAIT_HOME) || (calState == POLAR_CALIBRATION_WAIT) || (calState == POLAR_CALIBRATION_GO)) {
455+
// else if (calState == HIGHLIGHT_BACKLIGHT) {
456+
// lcdMenu.printMenu(">LCD Brightness");
457+
// }
458+
else if (calState == POLAR_CALIBRATION_WAIT_CENTER_POLARIS) {
402459
if (!mount.isSlewingRAorDEC()) {
403460
lcdMenu.setCursor(0, 0);
404461
lcdMenu.printMenu("Centr on Polaris");
@@ -428,6 +485,10 @@ void printCalibrationSubmenu()
428485
sprintf(scratchBuffer, "Backlash: %d", BacklashSteps);
429486
lcdMenu.printMenu(scratchBuffer);
430487
}
488+
// else if (calState == BACKLIGHT_CALIBRATION) {
489+
// sprintf(scratchBuffer, "Brightness: %d", Brightness);
490+
// lcdMenu.printMenu(scratchBuffer);
491+
// }
431492
}
432493
#endif
433494

0 commit comments

Comments
 (0)