Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

ButtonBase Executor Service should be closed on GpioController.shutdown() #355

Closed
ribasco opened this issue Aug 10, 2017 · 0 comments
Closed
Assignees
Labels
Milestone

Comments

@ribasco
Copy link

ribasco commented Aug 10, 2017

Screenshot of thread still alive after call to gpio.shutdown()

image

Test Code:

public class ButtonTest {
    private static final Logger log = LoggerFactory.getLogger(ButtonTest.class);
    private final GpioController gpio = GpioFactory.getInstance();
    private AtomicBoolean shutdown = new AtomicBoolean(false);

    public static void main(String[] args) throws Exception {
        new ButtonTest().run();
        log.info("Exiting Main");
    }

    private void run() throws Exception {
        createButton(RaspiPin.GPIO_06, "Shutdown", "shutdown", 3500, buttonHoldListener);
        while (!shutdown.get())
            Thread.sleep(1000);
        gpio.shutdown();
    }

    private ButtonReleasedListener buttonReleasedListener = buttonEvent -> log.info("Button {} released", buttonEvent.getButton().getName());

    private ButtonHoldListener buttonHoldListener = buttonEvent -> {
        log.info("Button {} held. Shutting down", buttonEvent.getButton().getName());
        shutdown.set(true);
    };

    private GpioButtonComponent createButton(Pin buttonPin, String name, String tag, int holdInterval, ButtonHoldListener holdListener) {
        GpioPinDigitalInput inputPin = gpio.provisionDigitalInputPin(buttonPin, name, PinPullResistance.PULL_UP);
        inputPin.setDebounce(64);
        GpioButtonComponent button = new GpioButtonComponent(inputPin, PinState.HIGH, PinState.LOW);
        button.setName(name);
        button.setTag(tag);
        button.addListener(buttonReleasedListener);
        if (holdListener != null)
            button.addListener(holdInterval, holdListener);
        return button;
    }
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants