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

Commit

Permalink
Do not use emulator for virtual driver
Browse files Browse the repository at this point in the history
  • Loading branch information
ribasco committed Jan 8, 2019
1 parent c47e60d commit d124de0
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions src/main/java/com/ibasco/glcdemulator/utils/FontRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Organization: Rafael Luis Ibasco
* Project: GLCD Simulator
* Filename: FontRenderer.java
*
*
* ---------------------------------------------------------
* %%
* Copyright (C) 2018 Rafael Luis Ibasco
Expand All @@ -12,12 +12,12 @@
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
Expand All @@ -27,10 +27,11 @@

import com.ibasco.glcdemulator.DriverFactory;
import com.ibasco.glcdemulator.controls.GlcdScreen;
import com.ibasco.glcdemulator.emulator.GlcdEmulator;
import com.ibasco.glcdemulator.emulator.BufferLayout;
import com.ibasco.glcdemulator.emulator.BufferLayoutFactory;
import com.ibasco.ucgdisplay.drivers.glcd.Glcd;
import com.ibasco.ucgdisplay.drivers.glcd.GlcdDisplay;
import com.ibasco.ucgdisplay.drivers.glcd.GlcdDriver;
import com.ibasco.ucgdisplay.drivers.glcd.enums.GlcdBusInterface;
import com.ibasco.ucgdisplay.drivers.glcd.enums.GlcdFont;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -39,12 +40,14 @@ public class FontRenderer {

private static final Logger log = LoggerFactory.getLogger(FontRenderer.class);

private GlcdEmulator emulator;

private final Object mutext = new Object();

private GlcdDriver driver;

private BufferLayout bufferLayout;

private GlcdDisplay display = Glcd.SSD1306.D_128x64_NONAME;

public class FontInfo {
private int ascent;
private int descent;
Expand Down Expand Up @@ -80,9 +83,7 @@ private static class InstanceHolder {
}

private FontRenderer() {
driver = DriverFactory.createVirtual(Glcd.ST7920.D_128x64, GlcdBusInterface.SPI_HW_4WIRE_ST7920);
emulator = driver.getDriverEventHandler();
driver.setFont(GlcdFont.FONT_7X13B_TR); //default font
initialize();
}

private void initialize() {
Expand All @@ -105,17 +106,15 @@ public void setDisplay(GlcdDisplay display) {

public void renderFont(GlcdScreen screen, GlcdFont font, String text) {
synchronized (mutext) {
try {
emulator.setBuffer(screen.getBuffer());
driver.clearBuffer();
driver.setFont(font);
int y = (driver.getHeight() / 2) + (driver.getAscent() / 2);
driver.drawString(5, y, text);
driver.sendBuffer();
} finally {
emulator.setBuffer(null);
emulator.reset();
}
bufferLayout.setBuffer(screen.getBuffer());
bufferLayout.reset();
driver.clearBuffer();
driver.setFont(font);
int y = (driver.getHeight() / 2) + (driver.getAscent() / 2);
driver.drawString(5, y, text);
driver.sendBuffer();
bufferLayout.processBuffer(driver.getBuffer());
screen.refresh();
}
}

Expand Down

0 comments on commit d124de0

Please sign in to comment.