11#pragma once
2+ #include " Globals.hpp"
23
34#if HEADLESS_CLIENT == 0
45
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
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.
4548byte 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
4851float 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).
6063int BacklashSteps = 0 ;
6164
65+ // The brightness of the backlight of the LCD shield.
66+ // int Brightness = 255;
67+
6268bool 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
104113bool 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