PINE64
Java U8g2 - Printable Version

+- PINE64 (https://forum.pine64.org)
+-- Forum: PINE A64(+) (https://forum.pine64.org/forumdisplay.php?fid=4)
+--- Forum: Pine A64 Projects, Ideas and Tutorials (https://forum.pine64.org/forumdisplay.php?fid=19)
+--- Thread: Java U8g2 (/showthread.php?tid=15141)



Java U8g2 - sgjava - 10-20-2021

Java U8g2 is a high performance library based on U8g2: Library for monochrome displays, version 2. Rather than try to code the JNI by hand I used HawtJNI to generate the JNI wrappers. I also used some custom code to generate the HawtJNI methods and font constants. This makes life easier going forawrd as changes are simple to keep in sync.

Code:
final var u8g2 = U8g2.initU8g2();
// Change this to your actual display
U8g2.setupSsd1306I2c128x64NonameF(u8g2, U8G2_R0, u8x8_byte_arm_linux_hw_i2c, u8x8_arm_linux_gpio_and_delay);
U8g2.initDisplay(u8g2);
logger.debug(String.format("Size %d x %d, draw color %d", U8g2.getDisplayWidth(u8g2), U8g2.getDisplayHeight(u8g2), U8g2.
        getDrawColor(u8g2)));
U8g2.setPowerSave(u8g2, 0);
U8g2.clearBuffer(u8g2);
U8g2.setFont(u8g2, u8g2_font_t0_15b_mf);
U8g2.drawStr(u8g2, 1, 18, "Java U8g2");
U8g2.sendBuffer(u8g2);
try {
    TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException ie) {
    Thread.currentThread().interrupt();
}
U8g2.setPowerSave(u8g2, 1);
U8g2.done(u8g2);