JavaFX输出到SPI总线而不是RPi上的HDMI

时间:2016-05-23 15:07:27

标签: java javafx raspberry-pi

我正在尝试使用覆盆子上的JavaFX应用程序。它在我的HDMI显示器上运行良好,渲染的大小似乎都没问题。

但是,我现在已经在SPI接口上添加了我的3.5英寸触摸屏,但我仍然在HDMI监视器上获得了JavaFX输出。它适用于图形界面。控制台出现在3.5英寸液晶显示屏上,所以我想我需要在某处为JavaFX设置设置以输出3.5 LCD,但我不记得怎么做了。

[编辑:] 这是我的(缩短的)应用程序代码:

public class Main extends Application {

    private static int width = 480;
    private static int height = 320;

    static final Text statusText = new Text(25, 300, "(no status update)");
    static final Label messagesArea = new Label("");

    @Override
    public void start(Stage stage) throws Exception {
        stage.setTitle("Registration UHF scanner");
        final Group rootGroup = new Group();
        final Scene scene = new Scene(rootGroup, width, height, Color.BLACK);

        final Text title = new Text(25, 45, "Youth 2000 UHF Registration");
        title.setFill(Color.WHITESMOKE);
        title.setFont(Font.font(java.awt.Font.SERIF, FontWeight.BOLD, 25));
        rootGroup.getChildren().add(title);

        messagesArea.setWrapText(true);
        messagesArea.setStyle("-fx-font-family: \"Comic Sans MS\"; -fx-font-size: 16; -fx-text-fill: white;");
        messagesArea.setTranslateX(25);
        messagesArea.setTranslateY(35);

        rootGroup.getChildren().add(messagesArea);

        statusText.setFill(Color.WHITESMOKE);
        statusText.setFont(Font.font(java.awt.Font.SERIF, 16));
        rootGroup.getChildren().add(statusText);

        scene.addEventFilter(KeyEvent.ANY, new EventHandler<KeyEvent>() {
                @Override
                public void handle(KeyEvent keyEvent) {
                    System.out.println("Key pressed: " + keyEvent.getCode());
                    if (keyEvent.getCode() == KeyCode.ENTER) {
                        System.out.println("Test!");
                    }
                }
            });

        Button shutDown = new Button("Shutdown");
        shutDown.setPrefWidth(110);
        shutDown.setPrefHeight(10);
        shutDown.setTranslateX(width - 115);
        shutDown.setTranslateY(height - 35);
        rootGroup.getChildren().add(shutDown);

        Button restart = new Button("Restart");
        restart.setPrefWidth(110);
        restart.setPrefHeight(10);
        restart.setTranslateX(width - 115);
        restart.setTranslateY(height - 75);
        rootGroup.getChildren().add(restart);

        shutDown.setOnAction(new EventHandler<ActionEvent>() {
            @Override public void handle(ActionEvent e) {
                // Shutdown the computer.
                try {
                    shutDown();
                } catch (Exception ex){
                    System.out.println("Problem shutting down: " + ex.getMessage());
                    setStatusText("Problem shutting down!!!!");
                }
            }
        });

        restart.setOnAction(new EventHandler<ActionEvent>() {
            @Override public void handle(ActionEvent e) {
                // Shutdown the computer.
                try {
                    restartServer();
                } catch (Exception ex){
                    System.out.println("Problem restarting: " + ex.getMessage());
                    setStatusText("Problem restarting!!!!");
                }
            }
        });

        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        System.out.println("Starting system...");

        if (System.getProperty("screenWidth") != null) {
            width = Integer.valueOf(System.getProperty("screenWidth"));
        }

        if (System.getProperty("screenHeight") != null) {
            height = Integer.valueOf(System.getProperty("screenHeight"));
        }

        Application.launch(args);

    }
}

1 个答案:

答案 0 :(得分:0)

需要将FrameBuffer镜像到SPI。 fbcp:https://github.com/tasanakorn/rpi-fbcp

主显示屏必须正确配置才能具有相同的分辨率。所以在/boot/config.txt中。就我而言:

disable_overscan=1

framebuffer_width=480
framebuffer_height=320
#set specific CVT mode
hdmi_cvt 480 320 60 1 0 0 0
#set CVT as default
hdmi_group=2
hdmi_mode=87
hdmi_force_hotplug=1

这只会让我在触摸屏上留下一点问题,因为交换了xy。这应该可以通过更改

来解决
swap_xy=X 
/ etc / modules中的

参数,但对我来说还没有工作到目前为止。我确实想要在风景中使用屏幕,因此旋转图像实际上不是一种选择。