Skip to content

Commit 93939b2

Browse files
Fixed some key processing bugs
- Keys were being waited on when they shouldn't - Placed all the vararg stuff in the DEBUG mode (seems flaky). - DEC movement did not display progress.
1 parent 730ce46 commit 93939b2

15 files changed

+80
-68
lines changed

Software/Arduino code/OpenAstroTracker/OpenAstroTracker.ino

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
/*
22
=======================================================================================================================================
33
4-
Version 1.4.1
4+
Version 1.4.2
55
66
1. Connect your Arduino, under tools choose "Arduino Uno", set the right Port and set "Arduino ISP" as the Programmer.
7-
2. Hit upload
7+
2. Hit upload (Ctrl-U)
88
99
You might need to download the "AccelStepper" library by Mike McCauley
1010
11+
Authors: /u/intercipere
12+
/u/clutchplate
13+
/u/EorEquis
14+
1115
=======================================================================================================================================
1216
*/
13-
String version = "V1.4.1";
17+
String version = "V1.4.2";
1418

1519
boolean north = true; // change this to 'false' if youre in the southern hemisphere
1620

Software/Arduino code/OpenAstroTracker/b0_functions.ino

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ int read_LCD_buttons() {
1414
int adjustWrap(int current, int adjustBy, int minVal, int maxVal)
1515
{
1616
current += adjustBy;
17-
if (current > maxVal) current -= (maxVal + 1);
18-
if (current < minVal) current += (maxVal + 1);
17+
if (current > maxVal) current -= (maxVal + 1 - minVal);
18+
if (current < minVal) current += (maxVal + 1 - minVal
19+
);
1920
return current;
2021
}
2122

@@ -81,7 +82,6 @@ void logv(const char* input, ...) {
8182
va_end(argp);
8283

8384
}
84-
#endif
8585

8686
String format(const char* input, ...) {
8787
va_list argp;
@@ -92,7 +92,7 @@ String format(const char* input, ...) {
9292
}
9393

9494
String formatArg(const char* input, va_list args) {
95-
char achBuffer[128];
95+
char achBuffer[255];
9696
char*p = achBuffer;
9797

9898
for (const char* i = input; *i != 0; i++) {
@@ -152,3 +152,4 @@ String formatArg(const char* input, va_list args) {
152152
*p = '\0';
153153
return String(achBuffer);
154154
}
155+
#endif

Software/Arduino code/OpenAstroTracker/b1_menu.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ class LcdMenu {
9595
}
9696

9797
// Pass throu utility function
98-
void setCursor(int col, int row){
99-
_lcd->setCursor(col,row);
98+
void setCursor(int col, int row) {
99+
_lcd->setCursor(col, row);
100100
}
101-
101+
102102
// Go to the next menu item from currently active one
103103
void setNextActive() {
104104
// If the last item is active, go to the first.

Software/Arduino code/OpenAstroTracker/b2_daytime.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// A class to handle hours, minutes, seconds in a unified manner, allowing
1+
// A class to handle hours, minutes, seconds in a unified manner, allowing
22
// addition of hours, minutes, seconds, other times and conversion to string.
33
class DayTime {
44
private:

Software/Arduino code/OpenAstroTracker/b_setup.ino

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void setup() {
5858
if (north) {
5959
lcdMenu.addItem("POL", Polaris_Menu);
6060
}
61-
#ifdef SUPPORT_HEATING
61+
#ifdef SUPPORT_HEATING
6262
lcdMenu.addItem("HEAT", Heat_Menu);
6363
#endif
6464
lcdMenu.addItem("CTRL", Control_Menu);
@@ -70,6 +70,4 @@ void setup() {
7070
lcd.setCursor(0, 1);
7171
lcd.print(" " + version);
7272
delay(1750);
73-
74-
7573
}

Software/Arduino code/OpenAstroTracker/c65_startup.ino

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
#define StartupPoleConfirmed 10
77
#define StartupCompleted 20
88

9+
#define YES 1
10+
#define NO 2
11+
#define CANCEL 3
12+
913
int startupState = StartupIsPointedAtPole;
10-
int isAtPole = 1;
14+
int isAtPole = NO;
1115

1216

1317
void startupIsCompleted() {
@@ -26,13 +30,13 @@ void processStartupKeys(int key) {
2630
case StartupIsPointedAtPole:
2731
{
2832
if (key == btnLEFT) {
29-
isAtPole = adjustWrap(isAtPole, 1, 0, 2);
33+
isAtPole = adjustWrap(isAtPole, 1, YES, CANCEL);
3034
}
3135
else if (key == btnSELECT) {
32-
if (isAtPole == 1) { // Yes
36+
if (isAtPole == YES) {
3337
startupState = StartupSetHATime;
3438
}
35-
else if (isAtPole == 0) { // No
39+
else if (isAtPole == NO) {
3640
startupState = StartupWaitForPoleCompletion;
3741
inStartup = false;
3842
lcdMenu.setCursor(0, 0);
@@ -42,7 +46,7 @@ void processStartupKeys(int key) {
4246
// Skip the 'Manual control' prompt
4347
inControlMode = true;
4448
}
45-
else if (isAtPole == 2) { // Cancel
49+
else if (isAtPole == CANCEL) {
4650
startupIsCompleted();
4751
}
4852
}
@@ -68,7 +72,7 @@ void processStartupKeys(int key) {
6872
break;
6973

7074
case StartupPoleConfirmed: {
71-
isAtPole = true;
75+
isAtPole = YES;
7276

7377
// Ask again to confirm
7478
startupState = StartupIsPointedAtPole;
@@ -85,15 +89,15 @@ void prinStartupMenu() {
8589
{
8690
// 0123456789012345
8791
String choices(" Yes No Cancl ");
88-
if (isAtPole == 1) {
92+
if (isAtPole == YES) {
8993
choices.setCharAt(0, '>');
9094
choices.setCharAt(4, '<');
9195
}
92-
if (isAtPole == 0) {
96+
if (isAtPole == NO) {
9397
choices.setCharAt(5, '>');
9498
choices.setCharAt(8, '<');
9599
}
96-
if (isAtPole == 2) {
100+
if (isAtPole == CANCEL) {
97101
choices.setCharAt(9, '>');
98102
choices.setCharAt(15, '<');
99103
}

Software/Arduino code/OpenAstroTracker/c6_moveTo.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ void moveSteppersToTarget() {
6868
String disp = "";
6969
if (decTotal > 0) {
7070
float decDist = 100.0 - 100.0 * abs(stepperDEC.distanceToGo()) / decTotal;
71-
disp = disp + format("DEC:%d%% ", (int)floor(decDist));
71+
disp = disp + "DEC:" + String( (int)floor(decDist)) + "% ";
7272
}
7373
if (raTotal > 0) {
7474
float raDist = 100.0 - 100.0 * abs(stepperRA.distanceToGo()) / raTotal;
75-
disp = disp + format("RA:%d%% ", (int)floor(raDist));
75+
disp = disp + "RA:" + String((int)floor(raDist)) + "%";
7676
}
7777
lcdMenu.printMenu(disp);
7878
display = displaySkip;
@@ -99,17 +99,17 @@ void moveSteppersToTargetAsync() {
9999
lcdMenu.setCursor(0, 1);
100100
String disp ;
101101
if ((totalDECMove == 0) || (totalRAMove == 0)) {
102-
disp = String(format("D:%l R:%l", stepperDEC.currentPosition(), stepperRA.currentPosition()));
102+
disp = "D:" + String(stepperDEC.currentPosition()) + " R:" + String( stepperRA.currentPosition());
103103
}
104104
else {
105105
disp = "";
106106
if (totalDECMove > 0) {
107107
float decDist = 100.0 - 100.0 * abs(stepperDEC.distanceToGo()) / totalDECMove;
108-
disp = disp + format("DEC:%d%% ", (int)floor(decDist));
108+
disp = disp + "DEC:" + String((int)floor(decDist)) + "% ";
109109
}
110110
if (totalRAMove > 0) {
111111
float raDist = 100.0 - 100.0 * abs(stepperRA.distanceToGo()) / totalRAMove;
112-
disp = disp + format("RA:%d%% ", (int)floor(raDist));
112+
disp = disp + "RA:" + String((int)floor(raDist)) + "% ";
113113
}
114114
}
115115

Software/Arduino code/OpenAstroTracker/c70_menuRA.ino

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ void processRAKeys(int key) {
44
if (RAselect == 0) RATime.addHours(1);
55
if (RAselect == 1) RATime.addMinutes(1);
66
if (RAselect == 2) RATime.addSeconds(1);
7-
7+
88
// slow down key repetitions
99
delay(150);
1010
waitForButtonRelease = false;
@@ -39,23 +39,23 @@ void processRAKeys(int key) {
3939
}
4040
}
4141

42-
void printRASubmenu(){
43-
44-
//Serial.println("HA:" + HATime.ToString() + " HA(corr):" + HACorrection.ToString() + " RA:" + RATime.ToString() + " RA(corr):" + RADisplayTime.ToString());
45-
if (RAselect == 0) {
46-
lcdMenu.printMenuArg(">%dh %dm %ds", RADisplayTime.getHours(), RADisplayTime.getMinutes(), RADisplayTime.getSeconds());
47-
48-
//lcd.print(int(diamCorrection)); //for debugging
49-
//lcd.print("");
50-
//lcd.print(trackingspeed);
51-
//lcd.print(" ");
52-
}
53-
54-
if (RAselect == 1) {
55-
lcdMenu.printMenuArg(" %dh>%dm %ds", RADisplayTime.getHours(), RADisplayTime.getMinutes(), RADisplayTime.getSeconds());
56-
}
57-
58-
if (RAselect == 2) {
59-
lcdMenu.printMenuArg(" %dh %dm>%ds", RADisplayTime.getHours(), RADisplayTime.getMinutes(), RADisplayTime.getSeconds());
60-
}
42+
void printRASubmenu() {
43+
44+
//Serial.println("HA:" + HATime.ToString() + " HA(corr):" + HACorrection.ToString() + " RA:" + RATime.ToString() + " RA(corr):" + RADisplayTime.ToString());
45+
if (RAselect == 0) {
46+
lcdMenu.printMenuArg(">%dh %dm %ds", RADisplayTime.getHours(), RADisplayTime.getMinutes(), RADisplayTime.getSeconds());
47+
48+
//lcd.print(int(diamCorrection)); //for debugging
49+
//lcd.print("");
50+
//lcd.print(trackingspeed);
51+
//lcd.print(" ");
52+
}
53+
54+
if (RAselect == 1) {
55+
lcdMenu.printMenuArg(" %dh>%dm %ds", RADisplayTime.getHours(), RADisplayTime.getMinutes(), RADisplayTime.getSeconds());
56+
}
57+
58+
if (RAselect == 2) {
59+
lcdMenu.printMenuArg(" %dh %dm>%ds", RADisplayTime.getHours(), RADisplayTime.getMinutes(), RADisplayTime.getSeconds());
6160
}
61+
}

Software/Arduino code/OpenAstroTracker/c71_menuDEC.ino

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
bool movingToTarget = false;
22

33
void processDECKeys(int key) {
4+
45
switch (key) {
56
case btnUP: {
67
if (DECselect == 0) degreeDEC = north ? adjustClamp(degreeDEC, 1, -180, 0) : adjustClamp(degreeDEC, 1, 0, 180);
@@ -46,18 +47,22 @@ void processDECKeys(int key) {
4647

4748
if (movingToTarget) {
4849
moveSteppersToTargetAsync();
50+
if (!stepperRA.isRunning() && !stepperDEC.isRunning()) {
51+
movingToTarget = false;
52+
}
4953
}
5054
}
5155

5256
void printDECSubmenu() {
53-
54-
if (DECselect == 0) {
55-
lcdMenu.printMenuArg(">%d%c %d%c %d%s", printdegDEC, 0, minDEC, 1, secDEC, "\"");
56-
}
57-
if (DECselect == 1) {
58-
lcdMenu.printMenuArg(" %d%c>%d%c %d%s", printdegDEC, 0, minDEC, 1, secDEC, "\"");
59-
}
60-
if (DECselect == 2) {
61-
lcdMenu.printMenuArg(" %d%c %d%c>%d%s", printdegDEC, 0, minDEC, 1, secDEC, "\"");
57+
if (!movingToTarget) {
58+
if (DECselect == 0) {
59+
lcdMenu.printMenuArg(">%d%c %d%c %d%s", printdegDEC, 0, minDEC, 1, secDEC, "\"");
60+
}
61+
if (DECselect == 1) {
62+
lcdMenu.printMenuArg(" %d%c>%d%c %d%s", printdegDEC, 0, minDEC, 1, secDEC, "\"");
63+
}
64+
if (DECselect == 2) {
65+
lcdMenu.printMenuArg(" %d%c %d%c>%d%s", printdegDEC, 0, minDEC, 1, secDEC, "\"");
66+
}
6267
}
6368
}

Software/Arduino code/OpenAstroTracker/c725_menuHOME.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
void processHomeKeys(int key) {
22
switch (key) {
33
case btnSELECT: {
4-
if ((stepperRA.currentPosition() == 0) && (stepperDEC.currentPosition()==0)) {
4+
if ((stepperRA.currentPosition() == 0) && (stepperDEC.currentPosition() == 0)) {
55
lcdMenu.setCursor(0, 1);
66
lcdMenu.printMenu("Already Home...");
77
long now = millis();
88
while (millis() - now < 750) {
99
runTracker();
1010
}
1111
}
12-
12+
1313
stepperRA.moveTo(0);
1414
stepperDEC.moveTo(0);
1515
moveSteppersToTarget();

0 commit comments

Comments
 (0)