upm/examples/java/MPR121_Example.java
Noel Eck c54d6de054 JAVA: Unified Java Example names
Unified all Java examples to *match* <LIBRARY>[_otherstuf]_Example.java.
Note, a handful of the examples have a pseudo-random string for the
first component (see FlexSensor_Example.java, ideally this would be
Flex_Example.java).

This commit allows for quick development on a single sensor library
since a -DMODULE_LIST=mysensorlib now works with Java examples
(previously Java examples would fail generation when using
MODULE_LIST).

    * Renamed examples
    * Updated class names
    * Updated library descriptor .json files
    * Updated sample mapping file

TODO: Make this work like the C/C++ examples - grab the target library
name from the filename and grab all dependencies from that target
library.  Fix the handful of example names which don't conform.

Signed-off-by: Noel Eck <noel.eck@intel.com>
2018-02-27 15:28:48 -08:00

34 lines
725 B
Java

public class MPR121_Example {
private static void printButtons(upm_mpr121.MPR121 touch) {
boolean buttonPresed = false;
System.out.print("Buttons pressed: ");
for (int i = 0; i < 12; i++) {
if ((touch.getM_buttonStates() & (1 << i)) != 0) {
System.out.print(i + " ");
buttonPresed = true;
}
}
if (!buttonPresed)
System.out.print("None ");
System.out.println();
}
public static void main(String[] args) throws InterruptedException {
// Instantiate an MPR121 on I2C bus 0
upm_mpr121.MPR121 touch = new upm_mpr121.MPR121(0);
// init according to AN3944 defaults
touch.configAN3944();
while (true) {
touch.readButtons();
printButtons(touch);
Thread.sleep(1000);
}
}
}