I am trying to flip the values of all OUTPUT pins in my Raspberry Pi but my code doesn't seem to have any effect at all.
@Override
public void startApp()
{
Iterator<DeviceDescriptor<GPIOPin>> pinsIter = DeviceManager.list(GPIOPin.class);
while (pinsIter.hasNext())
{
DeviceDescriptor<GPIOPin> pin = pinsIter.next();
handlePin(pin, true);
}
}
private void handlePin(DeviceDescriptor<GPIOPin> device, boolean alternateValue)
{
System.out.println("Details for Pin: " + device.getName() + " (Id: " + device.getID() + ")");
try (GPIOPin pin = DeviceManager.open(device.getID(), GPIOPin.class))
{
System.out.println("Direction: " + directionName(pin.getDirection()));
System.out.println("Trigger: " + triggerName(pin.getTrigger()));
System.out.println("Value: " + pin.getValue());
if (pin.getDirection() == GPIOPin.OUTPUT && alternateValue)
{
System.out.println("Changing value for pin: " + device.getName());
pin.setValue(!pin.getValue());
}
} catch (IOException ex)
{
Logger.getLogger(DevicePins.class.getName()).log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
}
}
private String directionName(int d)
{
switch (d)
{
case GPIOPin.INPUT:
return "INPUT";
case GPIOPin.OUTPUT:
return "OUTPUT";
default:
throw new IllegalArgumentException(d + " is not a valid Direction constant!");
}
}
private String triggerName(int t)
{
switch (t)
{
case GPIOPinConfig.TRIGGER_BOTH_EDGES:
return "BOTH_EDGES";
case GPIOPinConfig.TRIGGER_BOTH_LEVELS:
return "BOTH_LEVELS";
case GPIOPinConfig.TRIGGER_FALLING_EDGE:
return "FALLING_EDGE";
case GPIOPinConfig.TRIGGER_HIGH_LEVEL:
return "HIGH_LEVEL";
case GPIOPinConfig.TRIGGER_LOW_LEVEL:
return "LOW_LEVEL";
case GPIOPinConfig.TRIGGER_NONE:
return "NONE";
case GPIOPinConfig.TRIGGER_RISING_EDGE:
return "RISING_EDGE";
default:
throw new IllegalArgumentException(t + " is not a valid Trigger constant!");
}
}
@Override
public void destroyApp(boolean unconditional)
{
}
I get a specific set of values in the "V" column. If I run the above command again after my code is ran and successfully deployed on my RasPi nothing really changes in the output i.e. all values in the "V" column remain the same. In the console output I can see that the value for all OUTPUT pins has been "changed" as per the log statements and no exceptions are thrown.
Any ideas what might be causing this behaviour? Any tips on troubleshooting this issue further?
I am using Java ME 8.2 and Raspberry Pi model B+.