Skip to content

Commit edd7828

Browse files
committed
Update Arduino Code to ClutchPlateDude's 1.6
1 parent b8d0b68 commit edd7828

25 files changed

+2227
-647
lines changed
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
#include "Utility.h"
2+
#include "DayTime.hpp"
3+
// A class to handle hours, minutes, seconds in a unified manner, allowing
4+
// addition of hours, minutes, seconds, other times and conversion to string.
5+
6+
DayTime::DayTime() {
7+
hours = 0;
8+
mins = 0;
9+
secs = 0;
10+
}
11+
12+
DayTime::DayTime(const DayTime& other) {
13+
hours = other.hours;
14+
mins = other.mins;
15+
secs = other.secs;
16+
}
17+
18+
DayTime::DayTime(int h, int m, int s) {
19+
hours = h;
20+
mins = m;
21+
secs = s;
22+
}
23+
24+
// From milliseconds. Does not handle days!
25+
DayTime::DayTime(long ms) {
26+
ms /= 1000; // seconds
27+
secs = (int)(ms % 60);
28+
ms = (ms - secs) / 60;
29+
mins = (int)(ms % 60);
30+
ms = (ms - mins) / 60;
31+
hours = (int)ms ;
32+
}
33+
34+
DayTime::DayTime(float timeInHours) {
35+
hours = floor(timeInHours);
36+
timeInHours = (timeInHours - hours) * 60;
37+
mins = floor(timeInHours);
38+
timeInHours = (timeInHours - mins) * 60;
39+
secs = floor(timeInHours);
40+
}
41+
42+
int DayTime::getHours() {
43+
return hours;
44+
}
45+
46+
int DayTime::getMinutes() {
47+
return mins;
48+
}
49+
50+
int DayTime::getSeconds() {
51+
return secs;
52+
}
53+
54+
float DayTime::getTotalHours() {
55+
return 1.0f * getHours() + ((float)getMinutes() / 60.0f) + ((float)getSeconds() / 3600.0f);
56+
}
57+
58+
float DayTime::getTotalMinutes() {
59+
return 60.0f * getHours() + (float)getMinutes() + ((float)getSeconds() / 60.0f);
60+
}
61+
62+
float DayTime::getTotalSeconds() {
63+
return 3600.0f * getHours() + (float)getMinutes() * 60.0f + (float)getSeconds();
64+
}
65+
66+
int DayTime::getTime(int& h, int& m, int& s) {
67+
h = hours;
68+
m = mins;
69+
s = secs;
70+
}
71+
72+
void DayTime::set(int h, int m, int s) {
73+
hours = h;
74+
mins = m;
75+
secs = s;
76+
checkHours();
77+
}
78+
79+
void DayTime::set(const DayTime& other) {
80+
hours = other.hours;
81+
mins = other.mins;
82+
secs = other.secs;
83+
checkHours();
84+
}
85+
86+
// Add hours, wrapping days (which are not tracked)
87+
void DayTime::addHours(int deltaHours) {
88+
hours += deltaHours;
89+
checkHours();
90+
}
91+
92+
void DayTime::checkHours() {
93+
Serial.println("DtIn: "+String(hours));
94+
while (hours >= hourWrap) {
95+
hours -= hourWrap;
96+
}
97+
while (hours < 0) {
98+
hours += hourWrap;
99+
}
100+
Serial.println("DtOut: "+String(hours));
101+
}
102+
103+
// Add minutes, wrapping hours if needed
104+
void DayTime::addMinutes(int deltaMins) {
105+
mins += deltaMins;
106+
while (mins > 59) {
107+
mins -= 60;
108+
addHours(1);
109+
}
110+
while (mins < 0) {
111+
mins += 60;
112+
addHours(-1);
113+
}
114+
}
115+
116+
// Add seconds, wrapping minutes and hours if needed
117+
void DayTime::addSeconds(long deltaSecs) {
118+
secs += deltaSecs;
119+
while (secs > 59) {
120+
secs -= 60;
121+
addMinutes(1);
122+
}
123+
while (secs < 0) {
124+
secs += 60;
125+
addMinutes(-1);
126+
}
127+
}
128+
129+
// Add time components, wrapping seconds, minutes and hours if needed
130+
void DayTime::addTime(int deltaHours, int deltaMinutes, int deltaSeconds)
131+
{
132+
addSeconds(deltaSeconds);
133+
addMinutes(deltaMinutes);
134+
addHours(deltaHours);
135+
}
136+
137+
// Add another time, wrapping seconds, minutes and hours if needed
138+
void DayTime::addTime(const DayTime& other)
139+
{
140+
addSeconds(other.getSeconds());
141+
addMinutes(other.getMinutes());
142+
addHours(other.getHours());
143+
}
144+
145+
// Subtract another time, wrapping seconds, minutes and hours if needed
146+
void DayTime::subtractTime(const DayTime& other)
147+
{
148+
addSeconds(-other.getSeconds());
149+
addMinutes(-other.getMinutes());
150+
addHours(-other.getHours());
151+
}
152+
153+
// Convert to a standard string (like 14:45:06)
154+
String DayTime::ToString()
155+
{
156+
char achBuf[12];
157+
char*p = achBuf;
158+
159+
if (hours < 10) {
160+
*p++ = '0';
161+
} else {
162+
*p++ = '0' + (hours / 10);
163+
}
164+
*p++ = '0' + (hours % 10);
165+
166+
*p++ = ':';
167+
if (mins < 10) {
168+
*p++ = '0';
169+
} else {
170+
*p++ = '0' + (mins / 10);
171+
}
172+
*p++ = '0' + (mins % 10);
173+
*p++ = ':';
174+
if (secs < 10) {
175+
*p++ = '0';
176+
} else {
177+
*p++ = '0' + (secs / 10);
178+
}
179+
*p++ = '0' + (secs % 10);
180+
*p++ = '\0';
181+
return String(achBuf);
182+
}
183+
184+
185+
DegreeTime::DegreeTime(): DayTime() {
186+
hourWrap = 180;
187+
}
188+
189+
DegreeTime::DegreeTime(const DegreeTime& other): DayTime(other) { }
190+
DegreeTime::DegreeTime(int h, int m, int s) : DayTime(h, m, s) { }
191+
DegreeTime::DegreeTime(float inDegrees) : DayTime(inDegrees) { }
192+
193+
void DegreeTime::addDegrees(int deltaDegrees) {
194+
addHours(deltaDegrees);
195+
}
196+
197+
int DegreeTime::getDegrees() {
198+
return hours;
199+
}
200+
201+
int DegreeTime::getPrintDegrees() {
202+
return NORTHERN_HEMISPHERE ? hours + 90 : hours - 90;
203+
}
204+
205+
float DegreeTime::getTotalDegrees() {
206+
return getTotalHours();
207+
}
208+
209+
void DegreeTime::checkHours() {
210+
if (NORTHERN_HEMISPHERE) {
211+
Serial.println("DgIn: "+String(hours));
212+
if (hours > 0) hours = 0;
213+
if (hours < -180) hours = -180;
214+
Serial.println("DgOut: "+String(hours));
215+
} else {
216+
if (hours > 180) hours = 180;
217+
if (hours < 0) hours = 0;
218+
}
219+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#ifndef _DAYTIME_HPP_
2+
#define _DAYTIME_HPP_
3+
4+
#include <Arduino.h>
5+
#include "Globals.h"
6+
7+
// A class to handle hours, minutes, seconds in a unified manner, allowing
8+
// addition of hours, minutes, seconds, other times and conversion to string.
9+
10+
class DayTime {
11+
protected:
12+
int hours;
13+
int mins;
14+
int secs;
15+
int hourWrap = 24;
16+
17+
public:
18+
DayTime();
19+
20+
DayTime(const DayTime& other);
21+
DayTime(int h, int m, int s);
22+
23+
// From milliseconds. Does not handle days!
24+
DayTime(long ms);
25+
26+
// From hours
27+
DayTime(float timeInHours);
28+
29+
int getHours();
30+
int getMinutes();
31+
int getSeconds();
32+
float getTotalHours();
33+
float getTotalMinutes();
34+
float getTotalSeconds();
35+
36+
int getTime(int& h, int& m, int& s);
37+
void set(int h, int m, int s);
38+
void set(const DayTime& other);
39+
40+
// Add hours, wrapping days (which are not tracked). Negative or positive.
41+
virtual void addHours(int deltaHours);
42+
43+
// Add minutes, wrapping hours if needed
44+
void addMinutes(int deltaMins);
45+
46+
// Add seconds, wrapping minutes and hours if needed
47+
void addSeconds(long deltaSecs);
48+
49+
// Add time components, wrapping seconds, minutes and hours if needed
50+
void addTime(int deltaHours, int deltaMinutes, int deltaSeconds);
51+
52+
// Add another time, wrapping seconds, minutes and hours if needed
53+
void addTime(const DayTime& other);
54+
// Subtract another time, wrapping seconds, minutes and hours if needed
55+
56+
void subtractTime(const DayTime& other);
57+
58+
// Convert to a standard string (like 14:45:06)
59+
String ToString();
60+
//protected:
61+
virtual void checkHours();
62+
};
63+
64+
class DegreeTime : public DayTime {
65+
public:
66+
DegreeTime();
67+
DegreeTime(const DegreeTime& other);
68+
DegreeTime(int h, int m, int s);
69+
DegreeTime(float inDegrees);
70+
71+
// Add degrees, clamp at 90
72+
void addDegrees(int deltaDegrees);
73+
74+
// Get degrees component
75+
int getDegrees();
76+
77+
// Get degrees for printing component
78+
int getPrintDegrees();
79+
80+
// Get total degrees
81+
float getTotalDegrees();
82+
//protected:
83+
virtual void checkHours() override;
84+
85+
private:
86+
void clampDegrees();
87+
};
88+
89+
#endif
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "Globals.h"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef _GLOBALS_H_
2+
#define _GLOBALS_H_
3+
// Set to 1 if you are in the northern hemisphere.
4+
#define NORTHERN_HEMISPHERE 1
5+
6+
#define DEBUG_MODE
7+
8+
// Time in ms between LCD screen updates during slewing operations
9+
#define DISPLAY_UPDATE_TIME 200
10+
11+
#endif

0 commit comments

Comments
 (0)