@@ -23,16 +23,23 @@ public class RobotServiceImpl implements RobotService {
23
23
24
24
private ExecutorService executorService ;
25
25
26
+ private Boolean autoEnabled ;
27
+
26
28
final GpioController gpio = GpioFactory .getInstance ();
27
29
final GpioPinDigitalOutput input3 = gpio .provisionDigitalOutputPin (RaspiPin .GPIO_07 , PinState .LOW );
28
30
final GpioPinDigitalOutput input4 = gpio .provisionDigitalOutputPin (RaspiPin .GPIO_11 , PinState .LOW );
29
31
final GpioPinDigitalOutput input2 = gpio .provisionDigitalOutputPin (RaspiPin .GPIO_13 , PinState .LOW );
30
32
final GpioPinDigitalOutput input1 = gpio .provisionDigitalOutputPin (RaspiPin .GPIO_15 , PinState .LOW );
31
33
final GpioPinDigitalInput irInput1 = gpio .provisionDigitalInputPin (RaspiPin .GPIO_16 , PinPullResistance .PULL_UP );
32
34
final GpioPinDigitalInput irInput2 = gpio .provisionDigitalInputPin (RaspiPin .GPIO_04 , PinPullResistance .PULL_UP );
35
+ final GpioPinDigitalInput irInput3 = gpio .provisionDigitalInputPin (RaspiPin .GPIO_05 , PinPullResistance .PULL_UP );
36
+ final GpioPinDigitalInput irInput4 = gpio .provisionDigitalInputPin (RaspiPin .GPIO_06 , PinPullResistance .PULL_UP );
37
+ final GpioPinDigitalInput irInput5 = gpio .provisionDigitalInputPin (RaspiPin .GPIO_23 , PinPullResistance .PULL_UP );
38
+ final GpioPinDigitalInput irInput6 = gpio .provisionDigitalInputPin (RaspiPin .GPIO_25 , PinPullResistance .PULL_UP );
33
39
34
40
@ PostConstruct
35
41
public void init (){
42
+ autoEnabled = false ;
36
43
executorService = Executors .newFixedThreadPool (2 );
37
44
input3 .setShutdownOptions (true , PinState .LOW , PinPullResistance .OFF );
38
45
input4 .setShutdownOptions (true , PinState .LOW , PinPullResistance .OFF );
@@ -44,89 +51,131 @@ public void init(){
44
51
irInput1 .addListener (new GpioPinListenerDigital (){
45
52
@ Override
46
53
public void handleGpioPinDigitalStateChangeEvent (GpioPinDigitalStateChangeEvent gpioPinDigitalStateChangeEvent ) {
47
- reverse (Long .valueOf (250 ));
54
+ turnLeft ();
55
+ try {
56
+ Thread .sleep (250 );
57
+ }catch (Exception e ){
58
+ logger .error (e .getMessage ());
59
+ }
60
+ resetPins ();
48
61
}
49
62
});
50
63
irInput2 .addListener (new GpioPinListenerDigital (){
51
64
@ Override
52
65
public void handleGpioPinDigitalStateChangeEvent (GpioPinDigitalStateChangeEvent gpioPinDigitalStateChangeEvent ) {
53
- forward (Long .valueOf (250 ));
66
+ turnRight ();
67
+ try {
68
+ Thread .sleep (250 );
69
+ }catch (Exception e ){
70
+ logger .error (e .getMessage ());
71
+ }
54
72
}
55
73
});
74
+ executorService .submit (new PlaySound ("Protoss/Units/Dragoon/pdrwht01.wav" ));
56
75
}
57
76
58
77
@ Override
59
- public void move (String command , Long time ){
78
+ public void executeMove (String command , Long time ){
79
+ if (autoEnabled ){
80
+ return ;
81
+ }
60
82
logger .info ("Starting move for command: " + command );
61
83
if (time == null ){
62
84
logger .error ("Time is null!" );
85
+ executorService .submit (new PlaySound ("Protoss/Units/Dragoon/pdrwht02.wav" ));
63
86
return ;
64
87
}
88
+ String wavFilePath = null ;
65
89
if (StringUtils .equalsIgnoreCase (command ,"W" )){
66
90
logger .info ("Moving forward for: " + time );
67
- forward (time );
68
- executorService . submit ( new PlaySound ( "Marine_Attack00 .wav")) ;
91
+ forward ();
92
+ wavFilePath = "Protoss/Units/Dragoon/pdrwht05 .wav" ;
69
93
}else if (StringUtils .equalsIgnoreCase (command ,"S" )){
70
94
logger .info ("Moving reverse for: " + time );
71
- reverse (time );
95
+ reverse ();
96
+ wavFilePath = "Protoss/Units/Dragoon/pdrwht06.wav" ;
72
97
}else if (StringUtils .equalsIgnoreCase (command ,"A" )){
73
98
logger .info ("Turning left for: " + time );
74
- turnLeft (time );
99
+ turnLeft ();
100
+ wavFilePath = "Protoss/Units/Dragoon/pdrwht07.wav" ;
75
101
}else if (StringUtils .equalsIgnoreCase (command ,"D" )){
76
102
logger .info ("Turning right for: " + time );
77
- turnRight (time );
103
+ turnRight ();
104
+ wavFilePath = "Protoss/Units/Dragoon/pdryes01.wav" ;
78
105
}else if (StringUtils .equalsIgnoreCase (command ,"Q" )){
79
106
logger .info ("Pivot left for: " + time );
80
- pivotLeft (time );
107
+ pivotLeft ();
108
+ wavFilePath = "Protoss/Units/Dragoon/Marine_Attack00.wav" ;
81
109
}else if (StringUtils .equalsIgnoreCase (command ,"E" )){
82
110
logger .info ("Pivot right for: " + time );
83
- pivotRight (time );
111
+ pivotRight ();
112
+ wavFilePath = "Protoss/Units/Dragoon/Marine_Attack00.wav" ;
84
113
}else {
85
114
logger .error ("No Command recognized!: " + command );
86
115
return ;
87
116
}
117
+ try {
118
+ Thread .sleep (time );
119
+ resetPins ();
120
+ }catch (Exception e ){
121
+ logger .error (e .getMessage ());
122
+ }
123
+ executorService .submit (new PlaySound (wavFilePath ));
124
+ }
125
+
126
+ @ Override
127
+ public void enableAuto () {
128
+ this .autoEnabled = true ;
129
+ forward ();
88
130
}
89
131
90
- private void forward (Long time ){
132
+ private void forward (){
91
133
input4 .low ();
92
134
input2 .low ();
93
- input3 .pulse ( time , false );
94
- input1 .pulse ( time , false );
135
+ input3 .high ( );
136
+ input1 .high ( );
95
137
}
96
138
97
- private void reverse (Long time ){
139
+ private void reverse (){
98
140
input3 .low ();
99
141
input1 .low ();
100
- input4 .pulse ( time , false );
101
- input2 .pulse ( time , false );
142
+ input4 .high ( );
143
+ input2 .high ( );
102
144
}
103
145
104
- private void turnLeft (Long time ){
146
+ private void turnLeft (){
105
147
input1 .low ();
106
148
input2 .low ();
107
149
input4 .low ();
108
- input3 .pulse ( time , false );
150
+ input3 .high ( );
109
151
}
110
152
111
- private void turnRight (Long time ){
153
+ private void turnRight (){
112
154
input2 .low ();
113
155
input3 .low ();
114
156
input4 .low ();
115
- input1 .pulse ( time , false );
157
+ input1 .high ( );
116
158
}
117
159
118
- private void pivotLeft (Long time ){
160
+ private void pivotLeft (){
119
161
input4 .low ();
120
162
input1 .low ();
121
- input3 .pulse ( time , false );
122
- input2 .pulse ( time , false );
163
+ input3 .high ( );
164
+ input2 .high ( );
123
165
}
124
166
125
- private void pivotRight (Long time ){
167
+ private void pivotRight (){
126
168
input3 .low ();
127
169
input2 .low ();
128
- input4 .pulse (time ,false );
129
- input1 .pulse (time ,false );
170
+ input4 .high ();
171
+ input1 .high ();
172
+ }
173
+
174
+ private void resetPins (){
175
+ input1 .low ();
176
+ input2 .low ();
177
+ input3 .low ();
178
+ input4 .low ();
130
179
}
131
180
132
181
@ PreDestroy
0 commit comments