3.3.2.8 GPIO Input Value Change Detection

As the Java GUI interface is primarily controlled by messages and periodical reading of GPIO inputs is complicated for programmers and speed-limiting due to high JNI operational costs and delay caused by Java-daemon communication intervals, an auxiliary nested static class IndoorTouch.GPIOWatcher is available for detection of GPIO value changes. When its instance is created, IndoorTouch.GPIOWatcher starts a thread, which periodically checks the GPIO input states and, having detected a change, calls public void OnGPIOChanged(int gpio, int value) via Android Looper, i.e. the content of this method is executed in the UI thread. Hence, to monitor the GPIO state, the user creates a son of this class and overrides this method. Then the user creates an instance of this class. Example:

class MyWatcher extends IndoorTouch.GPIOWatcher {
	public MyWatcher(int mask) {
		super(mask);
	}
	@Override
	public void OnGPIOChanged(int gpio, int value) {
		if (gpio == IndoorTouch.GPIO_PIN_IN1) {
		// do the magic
		}
	}
}
protected IndoorTouch.GPIOWatcher mWatch = new MyWatcher( IndoorTouch.GPIO_PIN_IN1 | IndoorTouch.GPIO_PIN_IN2);

GPIOWatcher has the following two constructors:

  • public GPIOWatcher(int watchMask)
  • public GPIOWatcher(int watchMask, int updateMs)

where watchMask is the GPIO pin bit array to be monitored and updateMs denotes the interval in miliseconds between the GPIO input checks. The default value is 200.