Skip to content

Commit e191a6c

Browse files
committed
Fixed CCE(ClassCastException)
1 parent 0d2f467 commit e191a6c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/main/java/JoystickModule.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,17 @@ public void startCollectingChannelsData(){
8585
if(gpioController==null || mcp3008GpioProvider==null){
8686
throw new ModuleNotActiveException("Module not active or not initialized");
8787
}
88+
89+
GpioPinAnalogInput[] gpioPinAnalogInput= new GpioPinAnalogInput[inputChannels.size()];
90+
/*a way of making the var of the number a final value to be used anonymously & to change it at the same time*/
91+
final int[] position = {0};
92+
inputChannels.forEach(channel->{
93+
gpioPinAnalogInput[position[0]]= channel;
94+
position[0] +=1;
95+
});
96+
8897
gpioController.addListener((GpioPinListenerAnalog) event -> {
98+
8999
double valueY=mcp3008GpioProvider.getValue(MCP3008Pin.CH0);
90100
double valueX=mcp3008GpioProvider.getValue(MCP3008Pin.CH1);
91101

@@ -110,7 +120,7 @@ public void startCollectingChannelsData(){
110120
}
111121
System.out.println("Vx : "+valueX);
112122
System.out.println("Vy : "+valueY);
113-
}, (GpioPinInput[]) inputChannels.toArray());
123+
}, gpioPinAnalogInput);
114124

115125
gpioPinDigitalInput.addListener((GpioPinListenerDigital) event -> {
116126
System.out.println("Vz = "+event.getState());

0 commit comments

Comments
 (0)