root / trunk / code / projects / logic_tester / cTest.c @ 1947
History | View | Annotate | Download (2.84 KB)
1 |
/* cTest.c
|
---|---|
2 |
* C debug library file for Colony
|
3 |
* By Benjamin Wasserman
|
4 |
* Colony Project
|
5 |
*/
|
6 |
|
7 |
#include "cTest.h" |
8 |
|
9 |
short robotID, lastRangefinderVal[5] = {-1, -1, -1, -1, -1}, lastBomMax, |
10 |
lastBomVal[16] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}, |
11 |
lastWheel; |
12 |
|
13 |
// Dragonfly
|
14 |
void init_debug(int which){ |
15 |
short numRobots;
|
16 |
|
17 |
printf("Please use nice values for inputs. I haven't had time to make this debugger resistant to stupid. Thanks. -HAL9000\n\n\n");
|
18 |
printf("P.S. Keep in mind this is only to help you find logic errors. Other errors may show due to running on the robots.");
|
19 |
printf("Enter number of robots in test: ");
|
20 |
scanf("%hi", &numRobots);
|
21 |
if(numRobots < 1){ |
22 |
numRobots = 1;
|
23 |
} |
24 |
robotID = numRobots; |
25 |
for(; numRobots >1; numRobots--){ |
26 |
if(fork() == 0){ |
27 |
robotID = numRobots; |
28 |
break;
|
29 |
} |
30 |
} |
31 |
printf("\nDragonFly Initialized: %hi for robot %hi\n", which, robotID);
|
32 |
} |
33 |
|
34 |
int getRobotID(){
|
35 |
return robotID;
|
36 |
} |
37 |
|
38 |
// Motors
|
39 |
|
40 |
// Orbs
|
41 |
|
42 |
// Rangefinders
|
43 |
int getRangefinderVal(int which){ |
44 |
short numRead, val;
|
45 |
switch(which){
|
46 |
case IR1: which = 1; break; |
47 |
case IR2: which = 2; break; |
48 |
case IR3: which = 3; break; |
49 |
case IR4: which = 4; break; |
50 |
case IR5: which = 5; break; |
51 |
default:
|
52 |
printf("Error in input. Returning -1\n");
|
53 |
return -1; |
54 |
} |
55 |
printf("Enter value for rangefinder %hi. Note: No value will return last entry: ", which);
|
56 |
numRead = scanf("%hi", &val);
|
57 |
if(numRead == 0){ |
58 |
return lastRangefinderVal[which - 1]; |
59 |
} |
60 |
lastRangefinderVal[which - 1] = val;
|
61 |
printf("Rangefinder %hi reports value %hi\n", which, val);
|
62 |
return val;
|
63 |
} |
64 |
|
65 |
// BOM
|
66 |
int getBomVal(int which){ |
67 |
short val, numRead;
|
68 |
printf("Enter value for BOM LED %hi. Note: No value will return last entry: ", which);
|
69 |
numRead = scanf("%hi", &val);
|
70 |
if(numRead == 0){ |
71 |
return lastBomVal[which - 1]; |
72 |
} |
73 |
lastBomVal[which - 1] = val;
|
74 |
return val;
|
75 |
} |
76 |
|
77 |
int getBomMax(){
|
78 |
short val, numRead;
|
79 |
printf("Enter value for BOM max. Note: No value will return last entry: ");
|
80 |
numRead = scanf("%hi", &val);
|
81 |
if(numRead == 0){ |
82 |
return lastBomMax;
|
83 |
} |
84 |
lastBomMax = val; |
85 |
return val;
|
86 |
} |
87 |
|
88 |
// Encoders
|
89 |
|
90 |
// Buttons
|
91 |
int getButton1(){
|
92 |
short val, numRead;
|
93 |
printf("Enter value for Button 1 (0 or 1). Note: No value will return 0: ");
|
94 |
numRead = scanf("%hi", &val);
|
95 |
if(numRead == 0){ |
96 |
return 0; |
97 |
} |
98 |
return val;
|
99 |
} |
100 |
|
101 |
int getButton2(){
|
102 |
short val, numRead;
|
103 |
printf("Enter value for Button 2. Note: No value will return 0: ");
|
104 |
numRead = scanf("%hi", &val);
|
105 |
if(numRead == 0){ |
106 |
return 0; |
107 |
} |
108 |
return val;
|
109 |
} |
110 |
|
111 |
// Wheel
|
112 |
int getWheel(){
|
113 |
short val, numRead;
|
114 |
printf("Enter value for Wheel. Note: No value will return last entry: ");
|
115 |
numRead = scanf("%hi", &val);
|
116 |
if(numRead == 0){ |
117 |
return lastWheel;
|
118 |
} |
119 |
lastWheel = val; |
120 |
printf("Wheel has value %hi\n", val);
|
121 |
return val;
|
122 |
} |
123 |
|
124 |
|
125 |
|
126 |
// USB
|
127 |
|
128 |
// Wireless (old)
|
129 |
|
130 |
|
131 |
// Wireless (new)
|
132 |
|
133 |
// Time
|
134 |
|
135 |
// Math
|
136 |
|