-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathParallaxBot.c
More file actions
executable file
·118 lines (99 loc) · 2.95 KB
/
ParallaxBot.c
File metadata and controls
executable file
·118 lines (99 loc) · 2.95 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// ParallaxBot.c
//
#include "BotConfig.h"
#include "simpletools.h"
#include "fdserial.h"
#if (CONFIGURED_BOT == TRI_BOT)
#include "TriBot.h"
#else
#include "StandardBot.h"
#endif
#if (CONFIGURED_ACCESSORIES == PAN_TILT_ARMS)
#include "KitAccessoryServosConfig.h"
#elif (CONFIGURED_ACCESSORIES == TILT_GRIPPER)
#include "TiltGripperAccessoryServosConfig.h"
#else
#include "DefaultAccessoryServosConfig.h"
#endif
#if (CONFIGURED_EYES == EYES_WS2812)
#include "EyesWS2812.h"
#else
#include "EyesAPA102.h"
#endif
fdserial *term; //enables full-duplex serial communication of the terminal (In other words, 2 way signals between the computer and the robot)
void StartBotController(int type)
{
#if (CONFIGURED_BOT == TRI_BOT)
StartTriBotController();
#else
StartStandardBotController();
#endif
StartAccessoryServosController(&AccessoryServosConfig);
}
void HandleBotCommands(const char* inputString, fdserial *term)
{
#if (CONFIGURED_BOT == TRI_BOT)
HandleTriBotCommands(inputString, term);
#else
HandleStandardBotCommands(inputString, term);
#endif
HandleAccessoryServosCommands(inputString, term);
}
void StartEyesHandler(int type)
{
#if (CONFIGURED_EYES == EYES_WS2812)
StartEyesWS2812Handler( LED_DATA_PIN );
#else
StartEyesAPA102Handler( LED_CLOCK_PIN, LED_DATA_PIN );
#endif
}
void HandleEyeCommands(const char* inputString, fdserial *term)
{
#if (CONFIGURED_EYES == EYES_WS2812)
HandleEyeWS2812Commands(inputString, term);
#else
HandleEyeAPA102Commands(inputString, term);
#endif
}
int main()
{
// Shutdown the default simpleterm
simpleterm_close();
// and start up the full-duplex serial driver for the terminal
term = fdserial_open(31, 30, 0, SERIAL_BITRATE);
StartBotController(CONFIGURED_BOT);
StartEyesHandler(CONFIGURED_EYES);
char c;
int inputStringLength = 64;
char inputString[inputStringLength];
int sPos = 0;
while (1)
{
if (fdserial_rxReady(term)!=0)
{
c = fdserial_rxChar(term); //Get the character entered from the terminal
if (c != -1)
{
if ((int)c == 13 || (int)c == 10)
{
dprint(term, "\nreceived line:");
dprint(term, inputString);
dprint(term, "\n");
HandleBotCommands(inputString, term);
HandleEyeCommands(inputString, term);
dprint(term, "\n");
sPos = 0;
inputString[0] = 0; // clear string
}
else if (sPos < inputStringLength - 1)
{
// record next character
inputString[sPos] = c;
sPos += 1;
inputString[sPos] = 0; // make sure last element of string is 0
dprint(term, "%c", c);
}
}
}
}
}