-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathMeadeParserFocus.cpp
More file actions
80 lines (73 loc) · 1.77 KB
/
MeadeParserFocus.cpp
File metadata and controls
80 lines (73 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* @file MeadeParserFocus.cpp
* @brief Focus-family (`:F...`) dispatcher for the Meade LX200 parser.
*/
#include "MeadeParser.hpp"
#include "MeadeParserHelpers.hpp"
#include <stdlib.h>
namespace oat
{
namespace core
{
namespace meade
{
void handleMeadeFocus(MeadeResponse &r, const char *suffix, IMeadeFocusHandlers &h)
{
if (suffix == nullptr || suffix[0] == '\0')
{
return;
}
Cursor c(suffix);
// `:F1#` .. `:F4#` — speed-by-rate digits act as the whole input.
if (c.peek() >= '1' && c.peek() <= '4')
{
c.match(c.peek());
if (c.atEnd())
{
h.onFocusSetSpeedByRate(suffix[0] - '0');
return;
}
}
switch (c.peek())
{
case '+':
h.onFocusContinuousIn();
break;
case '-':
h.onFocusContinuousOut();
break;
case 'M':
c.match('M');
h.onFocusMoveBy(strtol(c.remaining(), nullptr, 10));
break;
case 'F':
h.onFocusSetSpeedByRate(4);
break;
case 'S':
h.onFocusSetSpeedByRate(1);
break;
case 'p':
fillLongResponse(r, h.onFocusGetPosition());
return;
case 'P':
if (h.onFocusIsAvailable())
{
c.match('P');
h.onFocusSetPosition(strtol(c.remaining(), nullptr, 10));
fillSetSuccessResponse(r, true);
return;
}
break;
case 'B':
fillSetSuccessResponse(r, h.onFocusGetState());
return;
case 'Q':
h.onFocusStop();
break;
default:
break;
}
}
} // namespace meade
} // namespace core
} // namespace oat